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>

Jeff King committed Mar 20, 2015 at 06:13 UTC e4e6e8b4e3aeb3f7237b83f2125c9deee221ff77
1 file changed +31 -60
t/t6030-bisect-porcelain.sh
+31 -60
@@ -52,15 +52,8 @@ test_expect_success 'bisect starts with only one bad' '
52 test_expect_success 'bisect does not start with only one good' '
53 git bisect reset &&
54 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
57 '
58
59 test_expect_success 'bisect start with one bad and good' '
@@ -191,34 +184,27 @@ test_expect_success 'bisect start: no ".git/BISECT_START" if checkout error' '
184 # but $HASH2 is bad,
185 # so we should find $HASH2 as the first bad commit
186 test_expect_success 'bisect skip: successful result' '
187 + test_when_finished git bisect reset &&
188 git bisect reset &&
189 git bisect start $HASH4 $HASH1 &&
190 git bisect skip &&
191 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
193 '
194
195 # $HASH1 is good, $HASH4 is bad, we skip $HASH3 and $HASH2
196 # so we should not be able to tell the first bad commit
197 # among $HASH2, $HASH3 and $HASH4
198 test_expect_success 'bisect skip: cannot tell between 3 commits' '
199 + test_when_finished git bisect reset &&
200 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
208 '
209
210 # $HASH1 is good, $HASH4 is bad, we skip $HASH3
@@ -226,22 +212,15 @@ test_expect_success 'bisect skip: cannot tell between 3 commits' '
212 # so we should not be able to tell the first bad commit
213 # among $HASH3 and $HASH4
214 test_expect_success 'bisect skip: cannot tell between 2 commits' '
215 + test_when_finished git bisect reset &&
216 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
224 '
225
226 # $HASH1 is good, $HASH4 is both skipped and bad, we skip $HASH3
@@ -249,24 +228,18 @@ test_expect_success 'bisect skip: cannot tell between 2 commits' '
228 # so we should not be able to tell the first bad commit
229 # among $HASH3 and $HASH4
230 test_expect_success 'bisect skip: with commit both bad and skipped' '
231 + test_when_finished git bisect reset &&
232 git bisect start &&
233 git bisect skip &&
234 git bisect bad &&
235 git bisect good $HASH1 &&
236 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
243 '
244
245 # We want to automatically find the commit that
@@ -601,8 +574,7 @@ test_expect_success 'test bisection on bare repo - --no-checkout specified' '
574 git bisect bad $HASH4 &&
575 git bisect run eval \
576 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
604 - >../nocheckout.log &&
605 - git bisect reset
577 + >../nocheckout.log
578 ) &&
579 grep "$HASH3 is the first bad commit" nocheckout.log
580 '
@@ -617,8 +589,7 @@ test_expect_success 'test bisection on bare repo - --no-checkout defaulted' '
589 git bisect bad $HASH4 &&
590 git bisect run eval \
591 "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \
620 - >../defaulted.log &&
621 - git bisect reset
592 + >../defaulted.log
593 ) &&
594 grep "$HASH3 is the first bad commit" defaulted.log
595 '
@@ -642,14 +613,14 @@ test_expect_success 'broken branch creation' '
613 mkdir missing &&
614 :> missing/MISSING &&
615 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" &&
617 git tag BROKEN_HASH6 &&
618 add_line_into_file "7(broken): second line on a broken branch" hello2 &&
619 git tag BROKEN_HASH7 &&
620 add_line_into_file "8(broken): third line on a broken branch" hello2 &&
621 git tag BROKEN_HASH8 &&
622 git rm missing/MISSING &&
652 - git commit -m "9(broken): Remove missing file"
623 + git commit -m "9(broken): Remove missing file" &&
624 git tag BROKEN_HASH9 &&
625 rm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d
626 '