Skip to content

Commit

Permalink
Work around unstable kill(2) behavior on macOS
Browse files Browse the repository at this point in the history
We already have this workaround in exit-p.tst and trap-p.tst, but it
was missing in trap-y.tst. This commit adds the workaround to trap-y.tst
as well.

Syncs with:
https://github.com/magicant/yash-rs/blob/1e4fae1766b63b3a77b0afd11bf22d2bc63796f3/yash-cli/tests/scripted_test/trap-y.sh
  • Loading branch information
magicant committed Feb 11, 2025
1 parent e379edb commit 2a76f74
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tests/trap-y.tst
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# trap-y.tst: yash-specific test of the trap built-in

if [ "$(uname)" = Darwin ]; then
# On macOS, kill(2) does not appear to run any signal handlers
# synchronously, making it impossible for the shell to respond to self-sent
# signals at a predictable time. To work around this issue, the kill
# built-in is called in a subshell on macOS, using the SIGCHLD signal as a
# synchronization trigger.
setup <<'__EOF__'
killx() (((command kill "$@"); :); :)
alias kill=killx
__EOF__
fi

test_o 'trap for EXIT is executed just once'
"$TESTEE" -c 'trap "echo EXIT 1" EXIT; ./_no_such_command_ '
"$TESTEE" -c 'trap "echo EXIT 2" EXIT; (./_no_such_command_)'
Expand Down

0 comments on commit 2a76f74

Please sign in to comment.