test-lib: Let tests specify commands to be run at end of test
commit3bf7886705b4ea7189f046fa5258fdf6edcdbe23
authorJonathan Nieder <jrnieder@gmail.com>
Sun, 2 May 2010 08:53:41 +0000 (2 03:53 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 4 May 2010 22:27:52 +0000 (4 15:27 -0700)
tree334c237a7ac7a8ed0ec8d70ab076c4a5422785bc
parent6b6f5d4664c9088636418653a61f600b5e3a9ea4
test-lib: Let tests specify commands to be run at end of test

Certain actions can imply that if the test fails early, recovery from
within other tests is too much to expect:

 - creating unwritable directories, like the EACCESS test in t0001-init
 - setting unusual configuration, like user.signingkey in t7004-tag
 - crashing and leaving the index lock held, like t3600-rm once did

Some test scripts work around this by running cleanup actions outside
the supervision of the test harness, with the unfortunate consequence
that those commands are not appropriately echoed and their output not
suppressed.  Others explicitly save exit status, clean up, and then
reset the exit status within the tests, which has excellent behavior
but makes the tests hard to read.  Still others ignore the problem.

Allow tests a fourth option: by calling this function, tests can
stack up commands they would like to be run to clean up.

Commands passed to test_when_finished during a test are
unconditionally run in the test environment immediately before the
test is completed, in last-in-first-out order.  If some cleanup
command fails, then the other cleanup commands are still run before
the failure is reported and the test script allowed to continue.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/test-lib.sh