diff options
author | Tavian Barnes <tavianator@tavianator.com> | 2023-10-23 11:42:33 -0400 |
---|---|---|
committer | Tavian Barnes <tavianator@tavianator.com> | 2023-10-23 13:00:21 -0400 |
commit | de8e0fbb8c1e59b3f1af72a07477b63a8f0bbc75 (patch) | |
tree | 4ab177ebe2342103eeca4d721d6a810b58ef99fc /tests/util.sh | |
parent | 4c7a49a83e082a7bfff85a9305882f0912655123 (diff) | |
download | bfs-de8e0fbb8c1e59b3f1af72a07477b63a8f0bbc75.tar.xz |
tests: Fix Bash 3 compatibility
Diffstat (limited to 'tests/util.sh')
-rw-r--r-- | tests/util.sh | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/tests/util.sh b/tests/util.sh index 31a7b6c..bfa5d16 100644 --- a/tests/util.sh +++ b/tests/util.sh @@ -120,7 +120,7 @@ callers() { # Print a message including path, line number, and command debug() { - local file="${1/#*\/tests\//tests\/}" + local file="${1/#*\/tests\//tests/}" set -- "$file" "${@:2}" color printf "${BLD}%s:%d:${RST} %s\n %s\n" "$@" } @@ -136,14 +136,13 @@ quote() { fi } +DEFER_LEVEL=-1 + # Run a command when this (sub)shell exits defer() { - # Refresh trap state before trap -p - # See https://unix.stackexchange.com/a/556888/56202 - trap -- KILL - # Check if the EXIT trap is already set - if ! trap -p EXIT | grep -q pop_defers; then + if ((DEFER_LEVEL != BASH_SUBSHELL)); then + DEFER_LEVEL=$BASH_SUBSHELL DEFER_CMDS=() DEFER_LINES=() DEFER_FILES=() |