Skip to content

Commit c21fc9d

Browse files
peffgitster
authored andcommitted
t: use test_expect_code instead of hand-rolled comparison
This makes our output in the event of a failure slightly nicer, and it means that we do not break the &&-chain. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35da1bf commit c21fc9d

File tree

3 files changed

+38
-44
lines changed

3 files changed

+38
-44
lines changed

t/t0040-parse-options.sh

+4-8
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,9 @@ test_expect_success 'long options' '
172172
'
173173

174174
test_expect_success 'missing required value' '
175-
test-parse-options -s;
176-
test $? = 129 &&
177-
test-parse-options --string;
178-
test $? = 129 &&
179-
test-parse-options --file;
180-
test $? = 129
175+
test_expect_code 129 test-parse-options -s &&
176+
test_expect_code 129 test-parse-options --string &&
177+
test_expect_code 129 test-parse-options --file
181178
'
182179

183180
cat > expect << EOF
@@ -227,8 +224,7 @@ test_expect_success 'unambiguously abbreviated option with "="' '
227224
'
228225

229226
test_expect_success 'ambiguously abbreviated option' '
230-
test-parse-options --strin 123;
231-
test $? = 129
227+
test_expect_code 129 test-parse-options --strin 123
232228
'
233229

234230
cat > expect << EOF

t/t4035-diff-quiet.sh

+32-34
Original file line numberDiff line numberDiff line change
@@ -29,67 +29,65 @@ test_expect_success 'setup' '
2929
'
3030

3131
test_expect_success 'git diff-tree HEAD^ HEAD' '
32-
git diff-tree --quiet HEAD^ HEAD >cnt
33-
test $? = 1 && test_line_count = 0 cnt
32+
test_expect_code 1 git diff-tree --quiet HEAD^ HEAD >cnt &&
33+
test_line_count = 0 cnt
3434
'
3535
test_expect_success 'git diff-tree HEAD^ HEAD -- a' '
36-
git diff-tree --quiet HEAD^ HEAD -- a >cnt
37-
test $? = 0 && test_line_count = 0 cnt
36+
test_expect_code 0 git diff-tree --quiet HEAD^ HEAD -- a >cnt &&
37+
test_line_count = 0 cnt
3838
'
3939
test_expect_success 'git diff-tree HEAD^ HEAD -- b' '
40-
git diff-tree --quiet HEAD^ HEAD -- b >cnt
41-
test $? = 1 && test_line_count = 0 cnt
40+
test_expect_code 1 git diff-tree --quiet HEAD^ HEAD -- b >cnt &&
41+
test_line_count = 0 cnt
4242
'
4343
# this diff outputs one line: sha1 of the given head
4444
test_expect_success 'echo HEAD | git diff-tree --stdin' '
45-
echo $(git rev-parse HEAD) | git diff-tree --quiet --stdin >cnt
46-
test $? = 1 && test_line_count = 1 cnt
45+
echo $(git rev-parse HEAD) |
46+
test_expect_code 1 git diff-tree --quiet --stdin >cnt &&
47+
test_line_count = 1 cnt
4748
'
4849
test_expect_success 'git diff-tree HEAD HEAD' '
49-
git diff-tree --quiet HEAD HEAD >cnt
50-
test $? = 0 && test_line_count = 0 cnt
50+
test_expect_code 0 git diff-tree --quiet HEAD HEAD >cnt &&
51+
test_line_count = 0 cnt
5152
'
5253
test_expect_success 'git diff-files' '
53-
git diff-files --quiet >cnt
54-
test $? = 0 && test_line_count = 0 cnt
54+
test_expect_code 0 git diff-files --quiet >cnt &&
55+
test_line_count = 0 cnt
5556
'
5657
test_expect_success 'git diff-index --cached HEAD' '
57-
git diff-index --quiet --cached HEAD >cnt
58-
test $? = 0 && test_line_count = 0 cnt
58+
test_expect_code 0 git diff-index --quiet --cached HEAD >cnt &&
59+
test_line_count = 0 cnt
5960
'
6061
test_expect_success 'git diff-index --cached HEAD^' '
61-
git diff-index --quiet --cached HEAD^ >cnt
62-
test $? = 1 && test_line_count = 0 cnt
62+
test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
63+
test_line_count = 0 cnt
6364
'
6465
test_expect_success 'git diff-index --cached HEAD^' '
6566
echo text >>b &&
6667
echo 3 >c &&
67-
git add . && {
68-
git diff-index --quiet --cached HEAD^ >cnt
69-
test $? = 1 && test_line_count = 0 cnt
70-
}
68+
git add . &&
69+
test_expect_code 1 git diff-index --quiet --cached HEAD^ >cnt &&
70+
test_line_count = 0 cnt
7171
'
7272
test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' '
73-
git commit -m "text in b" && {
74-
git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt
75-
test $? = 1 && test_line_count = 0 cnt
76-
}
73+
git commit -m "text in b" &&
74+
test_expect_code 1 git diff-tree --quiet -Stext HEAD^ HEAD -- b >cnt &&
75+
test_line_count = 0 cnt
7776
'
7877
test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' '
79-
git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt
80-
test $? = 0 && test_line_count = 0 cnt
78+
test_expect_code 0 git diff-tree --quiet -Snot-found HEAD^ HEAD -- b >cnt &&
79+
test_line_count = 0 cnt
8180
'
8281
test_expect_success 'git diff-files' '
83-
echo 3 >>c && {
84-
git diff-files --quiet >cnt
85-
test $? = 1 && test_line_count = 0 cnt
86-
}
82+
echo 3 >>c &&
83+
test_expect_code 1 git diff-files --quiet >cnt &&
84+
test_line_count = 0 cnt
8785
'
86+
8887
test_expect_success 'git diff-index --cached HEAD' '
89-
git update-index c && {
90-
git diff-index --quiet --cached HEAD >cnt
91-
test $? = 1 && test_line_count = 0 cnt
92-
}
88+
git update-index c &&
89+
test_expect_code 1 git diff-index --quiet --cached HEAD >cnt &&
90+
test_line_count = 0 cnt
9391
'
9492

9593
test_expect_success 'git diff, one file outside repo' '

t/t4053-diff-no-index.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ test_expect_success 'setup' '
1717
'
1818

1919
test_expect_success 'git diff --no-index directories' '
20-
git diff --no-index a b >cnt
21-
test $? = 1 && test_line_count = 14 cnt
20+
test_expect_code 1 git diff --no-index a b >cnt &&
21+
test_line_count = 14 cnt
2222
'
2323

2424
test_expect_success 'git diff --no-index relative path outside repo' '

0 commit comments

Comments
 (0)