summaryrefslogtreecommitdiffstats
path: root/tests/util.sh
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@tavianator.com>2024-02-01 16:03:05 -0500
committerTavian Barnes <tavianator@tavianator.com>2024-02-01 16:31:53 -0500
commitf8b22f20147d872aef9fa1037139c39e4dd0e687 (patch)
treecd8bc5f5c25ff58cd36d4e68bf67679b1c7d6b09 /tests/util.sh
parent31bede02d5dbbc8e9e60d3af9fc4a749ad89fa11 (diff)
downloadbfs-f8b22f20147d872aef9fa1037139c39e4dd0e687.tar.xz
tests: Use variable redirections to dup std{out,err}
Previously, we hardcoded file descriptors 3 and 4 for duplicating stdandard output/error respectively. In preparation for keeping inherited FDs open, switch to using bash's variable redirection feature to dynamically assign FDs. This feature is only available from bash 4.1 onwards, so this marks the end of our support for bash 3. macOS users will need to install a modern bash version to run our tests.
Diffstat (limited to 'tests/util.sh')
-rw-r--r--tests/util.sh17
1 files changed, 8 insertions, 9 deletions
diff --git a/tests/util.sh b/tests/util.sh
index 5bd3328..686cc77 100644
--- a/tests/util.sh
+++ b/tests/util.sh
@@ -68,7 +68,7 @@ stdenv() {
# Close stdin so bfs doesn't think we're interactive
# dup() the standard fds for logging even when redirected
- exec </dev/null 3>&1 4>&2
+ exec </dev/null {DUPOUT}>&1 {DUPERR}>&2
}
# Drop root priviliges or bail
@@ -159,19 +159,18 @@ defer() {
# Pop a single command from the defer stack and run it
pop_defer() {
- local i=$((${#DEFER_CMDS[@]} - 1))
- local cmd="${DEFER_CMDS[$i]}"
- local file="${DEFER_FILES[$i]}"
- local line="${DEFER_LINES[$i]}"
- unset "DEFER_CMDS[$i]"
- unset "DEFER_FILES[$i]"
- unset "DEFER_LINES[$i]"
+ local cmd="${DEFER_CMDS[-1]}"
+ local file="${DEFER_FILES[-1]}"
+ local line="${DEFER_LINES[-1]}"
+ unset "DEFER_CMDS[-1]"
+ unset "DEFER_FILES[-1]"
+ unset "DEFER_LINES[-1]"
local ret=0
eval "$cmd" || ret=$?
if ((ret != 0)); then
- debug "$file" $line "${RED}error $ret${RST}" "defer $cmd" >&4
+ debug "$file" $line "${RED}error $ret${RST}" "defer $cmd" >&$DUPERR
fi
return $ret