Skip to content

Commit e4e6e8b

Browse files
peffgitster
authored andcommitted
t6030: use modern test_* helpers
We can get rid of a lot of hand-rolled error messages by using test_must_fail and test_expect_code. The existing code was careful to use "|| return 1" when breaking the &&-chain, but it did fool --chain-lint; the new code is more idiomatic. We also add some uses of test_when_finished, which is less cryptic and more robust than putting code at the end of a test. In two cases we run "git bisect reset" from a subshell, which is a problem for test_when_finished (it would not run). However, in both of these cases, we are performing the tests in one-off sub-repos, so we do not need to clean up at all (and in fact it is nicer not to if the user wants to inspect the trash directory after a failure). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent d8cd327 commit e4e6e8b

1 file changed

Lines changed: 31 additions & 60 deletions

File tree

t/t6030-bisect-porcelain.sh

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,8 @@ test_expect_success 'bisect starts with only one bad' '
5252
test_expect_success 'bisect does not start with only one good' '
5353
git bisect reset &&
5454
git bisect start &&
55-
git bisect good $HASH1 || return 1
56-
57-
if git bisect next
58-
then
59-
echo Oops, should have failed.
60-
false
61-
else
62-
:
63-
fi
55+
git bisect good $HASH1 &&
56+
test_must_fail git bisect next
6457
'
6558

6659
test_expect_success 'bisect start with one bad and good' '
@@ -191,82 +184,62 @@ test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
191184
# but $HASH2 is bad,
192185
# so we should find $HASH2 as the first bad commit
193186
test_expect_success 'bisect skip: successful result' '
187+
test_when_finished git bisect reset &&
194188
git bisect reset &&
195189
git bisect start $HASH4 $HASH1 &&
196190
git bisect skip &&
197191
git bisect bad > my_bisect_log.txt &&
198-
grep "$HASH2 is the first bad commit" my_bisect_log.txt &&
199-
git bisect reset
192+
grep "$HASH2 is the first bad commit" my_bisect_log.txt
200193
'
201194

202195
# $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
203196
# so we should not be able to tell the first bad commit
204197
# among $HASH2, $HASH3 and $HASH4
205198
test_expect_success 'bisect skip: cannot tell between 3 commits' '
199+
test_when_finished git bisect reset &&
206200
git bisect start $HASH4 $HASH1 &&
207-
git bisect skip || return 1
208-
209-
if git bisect skip > my_bisect_log.txt
210-
then
211-
echo Oops, should have failed.
212-
false
213-
else
214-
test $? -eq 2 &&
215-
grep "first bad commit could be any of" my_bisect_log.txt &&
216-
! grep $HASH1 my_bisect_log.txt &&
217-
grep $HASH2 my_bisect_log.txt &&
218-
grep $HASH3 my_bisect_log.txt &&
219-
grep $HASH4 my_bisect_log.txt &&
220-
git bisect reset
221-
fi
201+
git bisect skip &&
202+
test_expect_code 2 git bisect skip >my_bisect_log.txt &&
203+
grep "first bad commit could be any of" my_bisect_log.txt &&
204+
! grep $HASH1 my_bisect_log.txt &&
205+
grep $HASH2 my_bisect_log.txt &&
206+
grep $HASH3 my_bisect_log.txt &&
207+
grep $HASH4 my_bisect_log.txt
222208
'
223209

224210
# $HASH1 is good, $HASH4 is bad, we skip $HASH3
225211
# but $HASH2 is good,
226212
# so we should not be able to tell the first bad commit
227213
# among $HASH3 and $HASH4
228214
test_expect_success 'bisect skip: cannot tell between 2 commits' '
215+
test_when_finished git bisect reset &&
229216
git bisect start $HASH4 $HASH1 &&
230-
git bisect skip || return 1
231-
232-
if git bisect good > my_bisect_log.txt
233-
then
234-
echo Oops, should have failed.
235-
false
236-
else
237-
test $? -eq 2 &&
238-
grep "first bad commit could be any of" my_bisect_log.txt &&
239-
! grep $HASH1 my_bisect_log.txt &&
240-
! grep $HASH2 my_bisect_log.txt &&
241-
grep $HASH3 my_bisect_log.txt &&
242-
grep $HASH4 my_bisect_log.txt &&
243-
git bisect reset
244-
fi
217+
git bisect skip &&
218+
test_expect_code 2 git bisect good >my_bisect_log.txt &&
219+
grep "first bad commit could be any of" my_bisect_log.txt &&
220+
! grep $HASH1 my_bisect_log.txt &&
221+
! grep $HASH2 my_bisect_log.txt &&
222+
grep $HASH3 my_bisect_log.txt &&
223+
grep $HASH4 my_bisect_log.txt
245224
'
246225

247226
# $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
248227
# and $HASH2 is good,
249228
# so we should not be able to tell the first bad commit
250229
# among $HASH3 and $HASH4
251230
test_expect_success 'bisect skip: with commit both bad and skipped' '
231+
test_when_finished git bisect reset &&
252232
git bisect start &&
253233
git bisect skip &&
254234
git bisect bad &&
255235
git bisect good $HASH1 &&
256236
git bisect skip &&
257-
if git bisect good > my_bisect_log.txt
258-
then
259-
echo Oops, should have failed.
260-
false
261-
else
262-
test $? -eq 2 &&
263-
grep "first bad commit could be any of" my_bisect_log.txt &&
264-
! grep $HASH1 my_bisect_log.txt &&
265-
! grep $HASH2 my_bisect_log.txt &&
266-
grep $HASH3 my_bisect_log.txt &&
267-
grep $HASH4 my_bisect_log.txt &&
268-
git bisect reset
269-
fi
237+
test_expect_code 2 git bisect good >my_bisect_log.txt &&
238+
grep "first bad commit could be any of" my_bisect_log.txt &&
239+
! grep $HASH1 my_bisect_log.txt &&
240+
! grep $HASH2 my_bisect_log.txt &&
241+
grep $HASH3 my_bisect_log.txt &&
242+
grep $HASH4 my_bisect_log.txt
270243
'
271244

272245
# We want to automatically find the commit that
@@ -601,8 +574,7 @@ test_expect_success 'test bisection on bare repo - --no-checkout specified' '
601574
git bisect bad $HASH4 &&
602575
git bisect run eval \
603576
"test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
604-
>../nocheckout.log &&
605-
git bisect reset
577+
>../nocheckout.log
606578
) &&
607579
grep "$HASH3 is the first bad commit" nocheckout.log
608580
'
@@ -617,8 +589,7 @@ test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
617589
git bisect bad $HASH4 &&
618590
git bisect run eval \
619591
"test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
620-
>../defaulted.log &&
621-
git bisect reset
592+
>../defaulted.log
622593
) &&
623594
grep "$HASH3 is the first bad commit" defaulted.log
624595
'
@@ -642,14 +613,14 @@ test_expect_success 'broken branch creation' '
642613
mkdir missing &&
643614
:> missing/MISSING &&
644615
git add missing/MISSING &&
645-
git commit -m "6(broken): Added file that will be deleted"
616+
git commit -m "6(broken): Added file that will be deleted" &&
646617
git tag BROKEN_HASH6 &&
647618
add_line_into_file "7(broken): second line on a broken branch" hello2 &&
648619
git tag BROKEN_HASH7 &&
649620
add_line_into_file "8(broken): third line on a broken branch" hello2 &&
650621
git tag BROKEN_HASH8 &&
651622
git rm missing/MISSING &&
652-
git commit -m "9(broken): Remove missing file"
623+
git commit -m "9(broken): Remove missing file" &&
653624
git tag BROKEN_HASH9 &&
654625
rm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d
655626
'

0 commit comments

Comments
 (0)