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>
This commit is contained in:
Clemens Buchacher 2009-06-01 14:14:41 +02:00 committed by Junio C Hamano
parent 1f729dca93
commit 6e7b5aaf40

View File

@ -147,7 +147,7 @@ fi
error () { error () {
say_color error "error: $*" say_color error "error: $*"
trap - EXIT GIT_EXIT_OK=t
exit 1 exit 1
} }
@ -179,10 +179,17 @@ test_broken=0
test_success=0 test_success=0
die () { die () {
echo >&5 "FATAL: Unexpected exit with code $?" code=$?
if test -n "$GIT_EXIT_OK"
then
exit $code
else
echo >&5 "FATAL: Unexpected exit with code $code"
exit 1 exit 1
fi
} }
GIT_EXIT_OK=
trap 'die' EXIT trap 'die' EXIT
# The semantics of the editor variables are that of invoking # The semantics of the editor variables are that of invoking
@ -285,7 +292,7 @@ test_failure_ () {
say_color error "FAIL $test_count: $1" say_color error "FAIL $test_count: $1"
shift shift
echo "$@" | sed -e 's/^/ /' echo "$@" | sed -e 's/^/ /'
test "$immediate" = "" || { trap - EXIT; exit 1; } test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; }
} }
test_known_broken_ok_ () { test_known_broken_ok_ () {
@ -498,7 +505,7 @@ test_create_repo () {
} }
test_done () { test_done () {
trap - EXIT GIT_EXIT_OK=t
test_results_dir="$TEST_DIRECTORY/test-results" test_results_dir="$TEST_DIRECTORY/test-results"
mkdir -p "$test_results_dir" mkdir -p "$test_results_dir"
test_results_path="$test_results_dir/${0%.sh}-$$" test_results_path="$test_results_dir/${0%.sh}-$$"
@ -640,7 +647,7 @@ fi
test="trash directory.$(basename "$0" .sh)" test="trash directory.$(basename "$0" .sh)"
test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test" test ! -z "$debug" || remove_trash="$TEST_DIRECTORY/$test"
rm -fr "$test" || { rm -fr "$test" || {
trap - EXIT GIT_EXIT_OK=t
echo >&5 "FATAL: Cannot prepare test area" echo >&5 "FATAL: Cannot prepare test area"
exit 1 exit 1
} }