Skip to content

Commit 0968f12

Browse files
johnkeepinggitster
authored andcommitted
test-lib-functions: detect test_when_finished in subshell
test_when_finished does nothing in a subshell because the change to test_cleanup does not affect the parent. There is no POSIX way to detect that we are in a subshell ($$ and $PPID are specified to remain unchanged), but we can detect it on Bash and fall back to ignoring the bug on other shells. Signed-off-by: John Keeping <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent da568b6 commit 0968f12

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

t/test-lib-functions.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,11 @@ test_seq () {
736736
# what went wrong.
737737

738738
test_when_finished () {
739+
# We cannot detect when we are in a subshell in general, but by
740+
# doing so on Bash is better than nothing (the test will
741+
# silently pass on other shells).
742+
test "${BASH_SUBSHELL-0}" = 0 ||
743+
error "bug in test script: test_when_finished does nothing in a subshell"
739744
test_cleanup="{ $*
740745
} && (exit \"\$eval_ret\"); eval_ret=\$?; $test_cleanup"
741746
}

0 commit comments

Comments
 (0)