Skip to content

Commit 4118427

Browse files
Pavel RoskinJunio C Hamano
authored andcommitted
[PATCH] Trapping exit in tests, using return for errors: further fixes.
"return" from a test would leave the exit trap set, which could cause a spurious error message if it's the last test in the script or --immediate is used. The easiest solution would be to have a global trap that is set when test-lib.sh is sourced and unset either by test_done(), error() or by test_failure_() with --immediate. Signed-off-by: Pavel Roskin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4d9d62f commit 4118427

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

t/test-lib.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ unset SHA1_FILE_DIRECTORY
3636

3737
error () {
3838
echo "* error: $*"
39+
trap - exit
3940
exit 1
4041
}
4142

@@ -74,6 +75,8 @@ fi
7475
test_failure=0
7576
test_count=0
7677

78+
trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
79+
7780

7881
# You are not expected to call test_ok_ and test_failure_ directly, use
7982
# the text_expect_* functions instead.
@@ -89,7 +92,7 @@ test_failure_ () {
8992
say "FAIL $test_count: $1"
9093
shift
9194
echo "$@" | sed -e 's/^/ /'
92-
test "$immediate" = "" || exit 1
95+
test "$immediate" = "" || { trap - exit; exit 1; }
9396
}
9497

9598

@@ -98,10 +101,8 @@ test_debug () {
98101
}
99102

100103
test_run_ () {
101-
trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit
102104
eval >&3 2>&4 "$1"
103105
eval_ret="$?"
104-
trap - exit
105106
return 0
106107
}
107108

@@ -132,6 +133,7 @@ test_expect_success () {
132133
}
133134

134135
test_done () {
136+
trap - exit
135137
case "$test_failure" in
136138
0)
137139
# We could:

0 commit comments

Comments
 (0)