Skip to content

Commit e5a730a

Browse files
committed
Merge branch 'jk/test-match-signal' into maint
The test framework learned a new helper test_match_signal to check an exit code from getting killed by an expected signal. * jk/test-match-signal: t/lib-git-daemon: use test_match_signal test_must_fail: use test_match_signal t0005: use test_match_signal as appropriate tests: factor portable signal check out of t0005
2 parents 174f9e6 + 03c39b3 commit e5a730a

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

t/lib-git-daemon.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,7 @@ stop_git_daemon() {
8282
kill "$GIT_DAEMON_PID"
8383
wait "$GIT_DAEMON_PID" >&3 2>&4
8484
ret=$?
85-
# expect exit with status 143 = 128+15 for signal TERM=15
86-
if test $ret -ne 143
85+
if test_match_signal 15 $?
8786
then
8887
error "git daemon exited with status: $ret"
8988
fi

t/t0005-signals.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ EOF
1111

1212
test_expect_success 'sigchain works' '
1313
{ test-sigchain >actual; ret=$?; } &&
14-
case "$ret" in
15-
143) true ;; # POSIX w/ SIGTERM=15
16-
271) true ;; # ksh w/ SIGTERM=15
17-
3) true ;; # Windows
18-
*) false ;;
19-
esac &&
14+
{
15+
# Signal death by raise() on Windows acts like exit(3),
16+
# regardless of the signal number. So we must allow that
17+
# as well as the normal signal check.
18+
test_match_signal 15 "$ret" ||
19+
test "$ret" = 3
20+
} &&
2021
test_cmp expect actual
2122
'
2223

@@ -41,12 +42,12 @@ test_expect_success 'create blob' '
4142

4243
test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
4344
OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
44-
test "$OUT" -eq 141
45+
test_match_signal 13 "$OUT"
4546
'
4647

4748
test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
4849
OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
49-
test "$OUT" -eq 141
50+
test_match_signal 13 "$OUT"
5051
'
5152

5253
test_done

t/test-lib-functions.sh

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ test_must_fail () {
612612
then
613613
echo >&2 "test_must_fail: command succeeded: $*"
614614
return 1
615-
elif test $exit_code -eq 141 && list_contains "$_test_ok" sigpipe
615+
elif test_match_signal 13 $exit_code && list_contains "$_test_ok" sigpipe
616616
then
617617
return 0
618618
elif test $exit_code -gt 129 && test $exit_code -le 192
@@ -961,3 +961,18 @@ test_env () {
961961
done
962962
)
963963
}
964+
965+
# Returns true if the numeric exit code in "$2" represents the expected signal
966+
# in "$1". Signals should be given numerically.
967+
test_match_signal () {
968+
if test "$2" = "$((128 + $1))"
969+
then
970+
# POSIX
971+
return 0
972+
elif test "$2" = "$((256 + $1))"
973+
then
974+
# ksh
975+
return 0
976+
fi
977+
return 1
978+
}

0 commit comments

Comments
 (0)