Skip to content

Commit ea05fd5

Browse files
committed
Merge branch 'ab/keep-git-exit-codes-in-tests'
Updates tests around the use of "test $(git cmd) = constant". * ab/keep-git-exit-codes-in-tests: rev-list simplify tests: don't ignore "git" exit code checkout tests: don't ignore "git <cmd>" exit code apply tests: don't ignore "git ls-files" exit code, drop sub-shell gettext tests: don't ignore "test-tool regex" exit code rev-list tests: don't hide abort() in "test_expect_failure" diff tests: don't ignore "git rev-list" exit code notes tests: don't ignore "git" exit code rev-parse tests: don't ignore "git reflog" exit code merge tests: use "test_must_fail" instead of ad-hoc pattern apply tests: use "test_must_fail" instead of ad-hoc pattern diff tests: don't ignore "git diff" exit code in "read" loop diff tests: don't ignore "git diff" exit code read-tree tests: check "diff-files" exit code on failure tests: use "test_stdout_line_count", not "test $(git [...] | wc -l)" tests: change some 'test $(git) = "x"' to test_cmp
2 parents 0b01c0a + a6ecc25 commit ea05fd5

19 files changed

+245
-218
lines changed

t/t0002-gitfile.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ test_expect_success 'check commit-tree' '
6565
test_path_is_file "$REAL/objects/$(objpath $SHA)"
6666
'
6767

68-
test_expect_success 'check rev-list' '
68+
test_expect_success !SANITIZE_LEAK 'check rev-list' '
6969
git update-ref "HEAD" "$SHA" &&
70-
test "$SHA" = "$(git rev-list HEAD)"
70+
git rev-list HEAD >actual &&
71+
echo $SHA >expected &&
72+
test_cmp expected actual
7173
'
7274

7375
test_expect_success 'setup_git_dir twice in subdir' '

t/t1001-read-tree-m-2way.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ In the test, these paths are used:
2121
yomin - not in H or M
2222
'
2323

24-
TEST_PASSES_SANITIZE_LEAK=true
2524
. ./test-lib.sh
2625
. "$TEST_DIRECTORY"/lib-read-tree.sh
2726

@@ -38,11 +37,12 @@ compare_change () {
3837
}
3938

4039
check_cache_at () {
41-
clean_if_empty=$(git diff-files -- "$1")
40+
git diff-files -- "$1" >out &&
41+
clean_if_empty=$(cat out) &&
4242
case "$clean_if_empty" in
4343
'') echo "$1: clean" ;;
4444
?*) echo "$1: dirty" ;;
45-
esac
45+
esac &&
4646
case "$2,$clean_if_empty" in
4747
clean,) : ;;
4848
clean,?*) false ;;

t/t1002-read-tree-m-u-2way.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ This is identical to t1001, but uses -u to update the work tree as well.
99
1010
'
1111

12-
TEST_PASSES_SANITIZE_LEAK=true
1312
. ./test-lib.sh
1413
. "$TEST_DIRECTORY"/lib-read-tree.sh
1514

@@ -23,11 +22,12 @@ compare_change () {
2322
}
2423

2524
check_cache_at () {
26-
clean_if_empty=$(git diff-files -- "$1")
25+
git diff-files -- "$1" >out &&
26+
clean_if_empty=$(cat out) &&
2727
case "$clean_if_empty" in
2828
'') echo "$1: clean" ;;
2929
?*) echo "$1: dirty" ;;
30-
esac
30+
esac &&
3131
case "$2,$clean_if_empty" in
3232
clean,) : ;;
3333
clean,?*) false ;;

t/t1503-rev-parse-verify.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,9 @@ test_expect_success 'use --default' '
132132
test_must_fail git rev-parse --verify --default bar
133133
'
134134

135-
test_expect_success 'main@{n} for various n' '
136-
N=$(git reflog | wc -l) &&
135+
test_expect_success !SANITIZE_LEAK 'main@{n} for various n' '
136+
git reflog >out &&
137+
N=$(wc -l <out) &&
137138
Nm1=$(($N-1)) &&
138139
Np1=$(($N+1)) &&
139140
git rev-parse --verify main@{0} &&

t/t2012-checkout-last.sh

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,20 @@ test_expect_success 'first branch switch' '
2121
git checkout other
2222
'
2323

24+
test_cmp_symbolic_HEAD_ref () {
25+
echo refs/heads/"$1" >expect &&
26+
git symbolic-ref HEAD >actual &&
27+
test_cmp expect actual
28+
}
29+
2430
test_expect_success '"checkout -" switches back' '
2531
git checkout - &&
26-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
32+
test_cmp_symbolic_HEAD_ref main
2733
'
2834

2935
test_expect_success '"checkout -" switches forth' '
3036
git checkout - &&
31-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
37+
test_cmp_symbolic_HEAD_ref other
3238
'
3339

3440
test_expect_success 'detach HEAD' '
@@ -37,12 +43,16 @@ test_expect_success 'detach HEAD' '
3743

3844
test_expect_success '"checkout -" attaches again' '
3945
git checkout - &&
40-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other"
46+
test_cmp_symbolic_HEAD_ref other
4147
'
4248

4349
test_expect_success '"checkout -" detaches again' '
4450
git checkout - &&
45-
test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" &&
51+
52+
git rev-parse other >expect &&
53+
git rev-parse HEAD >actual &&
54+
test_cmp expect actual &&
55+
4656
test_must_fail git symbolic-ref HEAD
4757
'
4858

@@ -63,31 +73,31 @@ more_switches () {
6373
test_expect_success 'switch to the last' '
6474
more_switches &&
6575
git checkout @{-1} &&
66-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch2"
76+
test_cmp_symbolic_HEAD_ref branch2
6777
'
6878

6979
test_expect_success 'switch to second from the last' '
7080
more_switches &&
7181
git checkout @{-2} &&
72-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch3"
82+
test_cmp_symbolic_HEAD_ref branch3
7383
'
7484

7585
test_expect_success 'switch to third from the last' '
7686
more_switches &&
7787
git checkout @{-3} &&
78-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch4"
88+
test_cmp_symbolic_HEAD_ref branch4
7989
'
8090

8191
test_expect_success 'switch to fourth from the last' '
8292
more_switches &&
8393
git checkout @{-4} &&
84-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch5"
94+
test_cmp_symbolic_HEAD_ref branch5
8595
'
8696

8797
test_expect_success 'switch to twelfth from the last' '
8898
more_switches &&
8999
git checkout @{-12} &&
90-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/branch13"
100+
test_cmp_symbolic_HEAD_ref branch13
91101
'
92102

93103
test_expect_success 'merge base test setup' '
@@ -98,27 +108,36 @@ test_expect_success 'merge base test setup' '
98108
test_expect_success 'another...main' '
99109
git checkout another &&
100110
git checkout another...main &&
101-
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
111+
112+
git rev-parse --verify main^ >expect &&
113+
git rev-parse --verify HEAD >actual &&
114+
test_cmp expect actual
102115
'
103116

104117
test_expect_success '...main' '
105118
git checkout another &&
106119
git checkout ...main &&
107-
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
120+
121+
git rev-parse --verify main^ >expect &&
122+
git rev-parse --verify HEAD >actual &&
123+
test_cmp expect actual
108124
'
109125

110126
test_expect_success 'main...' '
111127
git checkout another &&
112128
git checkout main... &&
113-
test "z$(git rev-parse --verify HEAD)" = "z$(git rev-parse --verify main^)"
129+
130+
git rev-parse --verify main^ >expect &&
131+
git rev-parse --verify HEAD >actual &&
132+
test_cmp expect actual
114133
'
115134

116135
test_expect_success '"checkout -" works after a rebase A' '
117136
git checkout main &&
118137
git checkout other &&
119138
git rebase main &&
120139
git checkout - &&
121-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
140+
test_cmp_symbolic_HEAD_ref main
122141
'
123142

124143
test_expect_success '"checkout -" works after a rebase A B' '
@@ -127,15 +146,15 @@ test_expect_success '"checkout -" works after a rebase A B' '
127146
git checkout other &&
128147
git rebase main moodle &&
129148
git checkout - &&
130-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
149+
test_cmp_symbolic_HEAD_ref main
131150
'
132151

133152
test_expect_success '"checkout -" works after a rebase -i A' '
134153
git checkout main &&
135154
git checkout other &&
136155
git rebase -i main &&
137156
git checkout - &&
138-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
157+
test_cmp_symbolic_HEAD_ref main
139158
'
140159

141160
test_expect_success '"checkout -" works after a rebase -i A B' '
@@ -144,7 +163,7 @@ test_expect_success '"checkout -" works after a rebase -i A B' '
144163
git checkout other &&
145164
git rebase main foodle &&
146165
git checkout - &&
147-
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/main"
166+
test_cmp_symbolic_HEAD_ref main
148167
'
149168

150169
test_done

t/t2200-add-update.sh

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ only the updates to dir/sub.
1414
Also tested are "git add -u" without limiting, and "git add -u"
1515
without contents changes, and other conditions'
1616

17-
TEST_PASSES_SANITIZE_LEAK=true
1817
. ./test-lib.sh
1918

2019
test_expect_success setup '
@@ -41,20 +40,28 @@ test_expect_success update '
4140
'
4241

4342
test_expect_success 'update noticed a removal' '
44-
test "$(git ls-files dir1/sub1)" = ""
43+
git ls-files dir1/sub1 >out &&
44+
test_must_be_empty out
4545
'
4646

4747
test_expect_success 'update touched correct path' '
48-
test "$(git diff-files --name-status dir2/sub3)" = ""
48+
git diff-files --name-status dir2/sub3 >out &&
49+
test_must_be_empty out
4950
'
5051

5152
test_expect_success 'update did not touch other tracked files' '
52-
test "$(git diff-files --name-status check)" = "M check" &&
53-
test "$(git diff-files --name-status top)" = "M top"
53+
echo "M check" >expect &&
54+
git diff-files --name-status check >actual &&
55+
test_cmp expect actual &&
56+
57+
echo "M top" >expect &&
58+
git diff-files --name-status top >actual &&
59+
test_cmp expect actual
5460
'
5561

5662
test_expect_success 'update did not touch untracked files' '
57-
test "$(git ls-files dir2/other)" = ""
63+
git ls-files dir2/other >out &&
64+
test_must_be_empty out
5865
'
5966

6067
test_expect_success 'cache tree has not been corrupted' '
@@ -76,9 +83,8 @@ test_expect_success 'update from a subdirectory' '
7683
'
7784

7885
test_expect_success 'change gets noticed' '
79-
80-
test "$(git diff-files --name-status dir1)" = ""
81-
86+
git diff-files --name-status dir1 >out &&
87+
test_must_be_empty out
8288
'
8389

8490
test_expect_success 'non-qualified update in subdir updates from the root' '
@@ -103,23 +109,26 @@ test_expect_success 'replace a file with a symlink' '
103109
test_expect_success 'add everything changed' '
104110
105111
git add -u &&
106-
test -z "$(git diff-files)"
112+
git diff-files >out &&
113+
test_must_be_empty out
107114
108115
'
109116

110117
test_expect_success 'touch and then add -u' '
111118
112119
touch check &&
113120
git add -u &&
114-
test -z "$(git diff-files)"
121+
git diff-files >out &&
122+
test_must_be_empty out
115123
116124
'
117125

118126
test_expect_success 'touch and then add explicitly' '
119127
120128
touch check &&
121129
git add check &&
122-
test -z "$(git diff-files)"
130+
git diff-files >out &&
131+
test_must_be_empty out
123132
124133
'
125134

t/t3302-notes-index-expensive.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ test_description='Test commit notes index (expensive!)'
88
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
99
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
1010

11-
TEST_PASSES_SANITIZE_LEAK=true
1211
. ./test-lib.sh
1312

1413
create_repo () {
@@ -65,7 +64,8 @@ create_repo () {
6564
test_notes () {
6665
count=$1 &&
6766
git config core.notesRef refs/notes/commits &&
68-
git log | grep "^ " >output &&
67+
git log >tmp &&
68+
grep "^ " tmp >output &&
6969
i=$count &&
7070
while test $i -gt 0
7171
do
@@ -90,7 +90,7 @@ write_script time_notes <<\EOF
9090
unset GIT_NOTES_REF
9191
;;
9292
esac
93-
git log
93+
git log || exit $?
9494
i=$(($i+1))
9595
done >/dev/null
9696
EOF

t/t3303-notes-subtrees.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ test_description='Test commit notes organized in subtrees'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8-
TEST_PASSES_SANITIZE_LEAK=true
98
. ./test-lib.sh
109

1110
number_of_commits=100
@@ -79,7 +78,7 @@ test_sha1_based () {
7978
(
8079
start_note_commit &&
8180
nr=$number_of_commits &&
82-
git rev-list refs/heads/main |
81+
git rev-list refs/heads/main >out &&
8382
while read sha1; do
8483
note_path=$(echo "$sha1" | sed "$1")
8584
cat <<INPUT_END &&
@@ -91,9 +90,9 @@ EOF
9190
INPUT_END
9291

9392
nr=$(($nr-1))
94-
done
95-
) |
96-
git fast-import --quiet
93+
done <out
94+
) >gfi &&
95+
git fast-import --quiet <gfi
9796
}
9897

9998
test_expect_success 'test notes in 2/38-fanout' 'test_sha1_based "s|^..|&/|"'

0 commit comments

Comments
 (0)