summaryrefslogtreecommitdiffstats
path: root/tests/run.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/run.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/run.sh')
-rw-r--r--tests/run.sh26
1 files changed, 7 insertions, 19 deletions
diff --git a/tests/run.sh b/tests/run.sh
index 4a159f9..85d961f 100644
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -28,7 +28,7 @@ debug_err() {
callers | while read -r line func file; do
if [ "$func" = source ]; then
local cmd="$(awk "NR == $line" "$file" 2>/dev/null)" || :
- debug "$file" $line "${RED}error $ret${RST}" "$cmd" >&4
+ debug "$file" $line "${RED}error $ret${RST}" "$cmd" >&$DUPERR
break
fi
done
@@ -73,21 +73,9 @@ bg_test() {
return $ret
}
-# Wait for any background job to complete
-if ((BASH_VERSINFO[0] > 4 || (BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 3))); then
- wait_any() {
- wait -n
- }
-else
- wait_any() {
- read -ra jobs < <(jobs -p)
- wait ${jobs[0]}
- }
-fi
-
# Wait for a background test to finish
wait_test() {
- wait_any
+ wait -n
ret=$?
((BG--))
@@ -197,7 +185,7 @@ skip() {
caller | {
read -r line file
printf "${BOL}"
- debug "$file" $line "" "$(awk "NR == $line" "$file")" >&3
+ debug "$file" $line "" "$(awk "NR == $line" "$file")" >&$DUPOUT
}
fi
@@ -252,8 +240,8 @@ bfs_verbose() {
(
# Close some fds to make room for the pipe,
# even with extremely low ulimit -n
- exec >&- 4>&-
- exec >&3 3>&-
+ exec >&- {DUPERR}>&-
+ exec >&$DUPOUT {DUPOUT}>&-
color bfs_verbose_impl "$@"
)
fi
@@ -306,7 +294,7 @@ invoke_bfs() {
local ret=0
# Close the logging fds
- "${BFS[@]}" "$@" 3>&- 4>&- || ret=$?
+ "${BFS[@]}" "$@" {DUPOUT}>&- {DUPERR}>&- || ret=$?
# Allow bfs to fail, but not crash
if ((ret > 125)); then
@@ -391,7 +379,7 @@ diff_output() {
if ((UPDATE)); then
cp "$OUT" "$GOLD"
else
- $DIFF -u "$GOLD" "$OUT" >&4
+ $DIFF -u "$GOLD" "$OUT" >&$DUPERR
fi
}