t1400: use test_when_finished for cleanup

Move cleanup lines that occur after test blocks into test_when_finished calls within the test bodies. Don't move cleanup lines that seem to be related to mutiple tests rather than a single test. Signed-off-by: Kyle Meyer <kyle@kyleam.com> Reviewed-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kyle Meyer committed Mar 20, 2017 at 20:56 UTC 2405ed07ca1d2b2f8c3d1825f1fee8ccdbf22a40
1 file changed +41 -40
t/t1400-update-ref.sh
+41 -40
@@ -48,24 +48,24 @@ test_expect_success "fail to delete $m with stale ref" '
48 test $B = "$(cat .git/$m)"
49 '
50 test_expect_success "delete $m" '
51 + test_when_finished "rm -f .git/$m" &&
52 git update-ref -d $m $B &&
53 test_path_is_missing .git/$m
54 '
54 -rm -f .git/$m
55
56 -test_expect_success "delete $m without oldvalue verification" "
56 +test_expect_success "delete $m without oldvalue verification" '
57 + test_when_finished "rm -f .git/$m" &&
58 git update-ref $m $A &&
58 - test $A = \$(cat .git/$m) &&
59 + test $A = $(cat .git/$m) &&
60 git update-ref -d $m &&
61 test_path_is_missing .git/$m
61 -"
62 -rm -f .git/$m
62 +'
63
64 -test_expect_success \
65 - "fail to create $n" \
66 - "touch .git/$n_dir &&
67 - test_must_fail git update-ref $n $A"
68 -rm -f .git/$n_dir
64 +test_expect_success "fail to create $n" '
65 + test_when_finished "rm -f .git/$n_dir" &&
66 + touch .git/$n_dir &&
67 + test_must_fail git update-ref $n $A
68 +'
69
70 test_expect_success \
71 "create $m (by HEAD)" \
@@ -80,28 +80,28 @@ test_expect_success "fail to delete $m (by HEAD) with stale ref" '
80 test $B = $(cat .git/$m)
81 '
82 test_expect_success "delete $m (by HEAD)" '
83 + test_when_finished "rm -f .git/$m" &&
84 git update-ref -d HEAD $B &&
85 test_path_is_missing .git/$m
86 '
86 -rm -f .git/$m
87
88 test_expect_success "deleting current branch adds message to HEAD's log" '
89 + test_when_finished "rm -f .git/$m" &&
90 git update-ref $m $A &&
91 git symbolic-ref HEAD $m &&
92 git update-ref -m delete-$m -d $m &&
93 test_path_is_missing .git/$m &&
94 grep "delete-$m$" .git/logs/HEAD
95 '
95 -rm -f .git/$m
96
97 test_expect_success "deleting by HEAD adds message to HEAD's log" '
98 + test_when_finished "rm -f .git/$m" &&
99 git update-ref $m $A &&
100 git symbolic-ref HEAD $m &&
101 git update-ref -m delete-by-head -d HEAD &&
102 test_path_is_missing .git/$m &&
103 grep "delete-by-head$" .git/logs/HEAD
104 '
104 -rm -f .git/$m
105
106 test_expect_success 'update-ref does not create reflogs by default' '
107 test_when_finished "git update-ref -d $outside" &&
@@ -188,20 +188,21 @@ test_expect_success \
188 "git update-ref HEAD $B $A &&
189 test $B"' = $(cat .git/'"$m"')'
190 test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" '
191 + test_when_finished "rm -f .git/$m" &&
192 git update-ref -d HEAD $B &&
193 ! grep "$m" .git/packed-refs &&
194 test_path_is_missing .git/$m
195 '
195 -rm -f .git/$m
196
197 cp -f .git/HEAD .git/HEAD.orig
198 test_expect_success "delete symref without dereference" '
199 + test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
200 git update-ref --no-deref -d HEAD &&
201 test_path_is_missing .git/HEAD
202 '
202 -cp -f .git/HEAD.orig .git/HEAD
203
204 test_expect_success "delete symref without dereference when the referred ref is packed" '
205 + test_when_finished "cp -f .git/HEAD.orig .git/HEAD" &&
206 echo foo >foo.c &&
207 git add foo.c &&
208 git commit -m foo &&
@@ -209,7 +210,7 @@ test_expect_success "delete symref without dereference when the referred ref is
210 git update-ref --no-deref -d HEAD &&
211 test_path_is_missing .git/HEAD
212 '
212 -cp -f .git/HEAD.orig .git/HEAD
213 +
214 git update-ref -d $m
215
216 test_expect_success 'update-ref -d is not confused by self-reference' '
@@ -241,10 +242,10 @@ test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' '
242 test_expect_success '(not) create HEAD with old sha1' "
243 test_must_fail git update-ref HEAD $A $B
244 "
244 -test_expect_success "(not) prior created .git/$m" "
245 +test_expect_success "(not) prior created .git/$m" '
246 + test_when_finished "rm -f .git/$m" &&
247 test_path_is_missing .git/$m
246 -"
247 -rm -f .git/$m
248 +'
249
250 test_expect_success \
251 "create HEAD" \
@@ -252,10 +253,10 @@ test_expect_success \
253 test_expect_success '(not) change HEAD with wrong SHA1' "
254 test_must_fail git update-ref HEAD $B $Z
255 "
255 -test_expect_success "(not) changed .git/$m" "
256 - ! test $B"' = $(cat .git/'"$m"')
256 +test_expect_success "(not) changed .git/$m" '
257 + test_when_finished "rm -f .git/$m" &&
258 + ! test $B = $(cat .git/$m)
259 '
258 -rm -f .git/$m
260
261 rm -f .git/logs/refs/heads/master
262 test_expect_success \
@@ -309,10 +310,10 @@ $Z $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 Initial Creati
310 $A $B $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150260 +0000 Switch
311 $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150860 +0000
312 EOF
312 -test_expect_success \
313 - "verifying $m's log (logged by touch)" \
314 - "test_cmp expect .git/logs/$m"
315 -rm -rf .git/$m .git/logs expect
313 +test_expect_success "verifying $m's log (logged by touch)" '
314 + test_when_finished "rm -rf .git/$m .git/logs expect" &&
315 + test_cmp expect .git/logs/$m
316 +'
317
318 test_expect_success \
319 "create $m (logged by config)" \
@@ -340,8 +341,8 @@ $B $A $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150980 +0000
341 EOF
342 test_expect_success \
343 "verifying $m's log (logged by config)" \
343 - 'test_cmp expect .git/logs/$m'
344 -rm -f .git/$m .git/logs/$m expect
344 + 'test_when_finished "rm -f .git/$m .git/logs/$m expect" &&
345 + test_cmp expect .git/logs/$m'
346
347 git update-ref $m $D
348 cat >.git/logs/$m <<EOF
@@ -357,55 +358,55 @@ gd="Thu, 26 May 2005 18:33:00 -0500"
358 ld="Thu, 26 May 2005 18:43:00 -0500"
359 test_expect_success \
360 'Query "master@{May 25 2005}" (before history)' \
360 - 'rm -f o e &&
361 + 'test_when_finished "rm -f o e" &&
362 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
363 test '"$C"' = $(cat o) &&
364 test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
365 test_expect_success \
366 "Query master@{2005-05-25} (before history)" \
366 - 'rm -f o e &&
367 + 'test_when_finished "rm -f o e" &&
368 git rev-parse --verify master@{2005-05-25} >o 2>e &&
369 test '"$C"' = $(cat o) &&
370 echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"'
371 test_expect_success \
372 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \
372 - 'rm -f o e &&
373 + 'test_when_finished "rm -f o e" &&
374 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
375 test '"$C"' = $(cat o) &&
376 test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"'
377 test_expect_success \
378 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \
378 - 'rm -f o e &&
379 + 'test_when_finished "rm -f o e" &&
380 git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e &&
381 test '"$C"' = $(cat o) &&
382 test "" = "$(cat e)"'
383 test_expect_success \
384 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \
384 - 'rm -f o e &&
385 + 'test_when_finished "rm -f o e" &&
386 git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e &&
387 test '"$A"' = $(cat o) &&
388 test "" = "$(cat e)"'
389 test_expect_success \
390 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \
390 - 'rm -f o e &&
391 + 'test_when_finished "rm -f o e" &&
392 git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e &&
393 test '"$B"' = $(cat o) &&
394 test "warning: Log for ref '"$m has gap after $gd"'." = "$(cat e)"'
395 test_expect_success \
396 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \
396 - 'rm -f o e &&
397 + 'test_when_finished "rm -f o e" &&
398 git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e &&
399 test '"$Z"' = $(cat o) &&
400 test "" = "$(cat e)"'
401 test_expect_success \
402 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \
402 - 'rm -f o e &&
403 + 'test_when_finished "rm -f o e" &&
404 git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e &&
405 test '"$E"' = $(cat o) &&
406 test "" = "$(cat e)"'
407 test_expect_success \
408 'Query "master@{2005-05-28}" (past end of history)' \
408 - 'rm -f o e &&
409 + 'test_when_finished "rm -f o e" &&
410 git rev-parse --verify "master@{2005-05-28}" >o 2>e &&
411 test '"$D"' = $(cat o) &&
412 test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"'
@@ -415,7 +416,8 @@ rm -f .git/$m .git/logs/$m expect
416
417 test_expect_success \
418 'creating initial files' \
418 - 'echo TEST >F &&
419 + 'test_when_finished rm -f M &&
420 + echo TEST >F &&
421 git add F &&
422 GIT_AUTHOR_DATE="2005-05-26 23:30" \
423 GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a &&
@@ -433,8 +435,7 @@ test_expect_success \
435 echo $h_TEST >.git/MERGE_HEAD &&
436 GIT_AUTHOR_DATE="2005-05-26 23:45" \
437 GIT_COMMITTER_DATE="2005-05-26 23:45" git commit -F M &&
436 - h_MERGED=$(git rev-parse --verify HEAD) &&
437 - rm -f M'
438 + h_MERGED=$(git rev-parse --verify HEAD)'
439
440 cat >expect <<EOF
441 $Z $h_TEST $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 commit (initial): add