@matheusbsbs / matheus-bagliano / commits / 6e7b5aaf40
Fork 0

test-lib: allow exit trap to be used for cleanup by tests

Exit trap should not be removed in case tests require cleanup code. This is especially important if tests are executed with the --immediate option. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Jun 1, 2009 at 14:14 UTC 6e7b5aaf40dac54edcbd7e0a859d26f526ef643e
1 file changed +14 -7
t/test-lib.sh
+14 -7
@@ -147,7 +147,7 @@ fi
147
148 error () {
149 say_color error "error: $*"
150 - trap - EXIT
150 + GIT_EXIT_OK=t
151 exit 1
152 }
153
@@ -179,10 +179,17 @@ test_broken=0
179 test_success=0
180
181 die () {
182 - echo >&5 "FATAL: Unexpected exit with code $?"
183 - exit 1
182 + code=$?
183 + if test -n "$GIT_EXIT_OK"
184 + then
185 + exit $code
186 + else
187 + echo >&5 "FATAL: Unexpected exit with code $code"
188 + exit 1
189 + fi
190 }
191
192 +GIT_EXIT_OK=
193 trap 'die' EXIT
194
195 # The semantics of the editor variables are that of invoking
@@ -285,7 +292,7 @@ test_failure_ () {
292 say_color error "FAIL $test_count: $1"
293 shift
294 echo "$@" | sed -e 's/^/ /'
288 - test "$immediate" = "" || { trap - EXIT; exit 1; }
295 + test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
296 }
297
298 test_known_broken_ok_ () {
@@ -347,7 +354,7 @@ test_expect_failure () {
354 then
355 test_known_broken_ok_ "$1"
356 else
350 - test_known_broken_failure_ "$1"
357 + test_known_broken_failure_ "$1"
358 fi
359 fi
360 echo >&3 ""
@@ -498,7 +505,7 @@ test_create_repo () {
505 }
506
507 test_done () {
501 - trap - EXIT
508 + GIT_EXIT_OK=t
509 test_results_dir="$TEST_DIRECTORY/test-results"
510 mkdir -p "$test_results_dir"
511 test_results_path="$test_results_dir/${0%.sh}-$$"
@@ -640,7 +647,7 @@ fi
647 test="trash directory.$(basename "$0" .sh)"
648 test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test"
649 rm -fr "$test" || {
643 - trap - EXIT
650 + GIT_EXIT_OK=t
651 echo >&5 "FATAL: Cannot prepare test area"
652 exit 1
653 }