git/t/t0005-signals.sh
Jeff King 9b67c9942e tests: factor portable signal check out of t0005
In POSIX shells, a program which exits due to a signal
generally has an exit code of 128 plus the signal number.
However, ksh uses 256 plus the signal number.  We've
accounted for that in t0005, but not in other tests.  Let's
pull out the logic so we can use it elsewhere.

It would be nice for debugging if this additionally printed
errors to stderr, like our other test_* helpers. But we're
going to need to use it in other places besides the innards
of a test_expect block. So let's leave it as generic as
possible.

Note that we also leave the magic "3" for Windows out of the
generic helper. This is an artifact of the way we use
raise() to kill ourselves in test-sigchain.c, and will not
necessarily apply to all programs. So it's better to keep it
out of the helper, to reduce the chance of confusing it with
a real call to exit(3).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-07-06 07:43:29 -07:00

54 lines
1.2 KiB
Bash
Executable file

#!/bin/sh
test_description='signals work as we expect'
. ./test-lib.sh
cat >expect <<EOF
three
two
one
EOF
test_expect_success 'sigchain works' '
{ test-sigchain >actual; ret=$?; } &&
{
# Signal death by raise() on Windows acts like exit(3),
# regardless of the signal number. So we must allow that
# as well as the normal signal check.
test_match_signal 15 "$ret" ||
test "$ret" = 3
} &&
test_cmp expect actual
'
test_expect_success !MINGW 'signals are propagated using shell convention' '
# we use exec here to avoid any sub-shell interpretation
# of the exit code
git config alias.sigterm "!exec test-sigchain" &&
test_expect_code 143 git sigterm
'
large_git () {
for i in $(test_seq 1 100)
do
git diff --cached --binary || return
done
}
test_expect_success 'create blob' '
test-genrandom foo 16384 >file &&
git add file
'
test_expect_success !MINGW 'a constipated git dies with SIGPIPE' '
OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) &&
test "$OUT" -eq 141
'
test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' '
OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) &&
test "$OUT" -eq 141
'
test_done