commit 57702d75602029d08a87ffa1dd1fe5334e905e41
parent 2a857c40bd4dabad0c15b3685b82c1f168e365ef
Author: Ryan Sepassi <rsepassi@gmail.com>
Date: Mon, 1 Jun 2026 17:14:26 -0700
test: set cf_workdir's EXIT trap in the caller's shell
CF_WORK=$(cf_workdir X) ran the function inside a command-substitution
subshell, so the EXIT trap fired and deleted the workdir the moment the
subshell closed -- before the harness ever used it. Set the global CF_WORK and
install the trap directly in the caller; migrate all six callers to the bare
'cf_workdir TOOL' form.
Diffstat:
7 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/test/ar/run.sh b/test/ar/run.sh
@@ -20,7 +20,7 @@ CFREE="${CFREE:-$repo_root/build/cfree}"
export CFREE
cf_require_cfree ar-driver
-CF_WORK=$(cf_workdir ar)
+cf_workdir ar
cf_report_init
for sh in "$cases_dir"/*.sh; do
[ -e "$sh" ] || continue
diff --git a/test/dbg/run.sh b/test/dbg/run.sh
@@ -44,7 +44,7 @@ case "$host_os:$host_arch" in
;;
esac
-CF_WORK=$(cf_workdir dbg)
+cf_workdir dbg
# DBG_STRICT_XFAIL drives the report layer's strict-xfail gate: an xfail case
# that unexpectedly passes becomes a real failure (stale marker) under strict.
diff --git a/test/lib/cfree_sh_report.sh b/test/lib/cfree_sh_report.sh
@@ -165,11 +165,14 @@ cf_require_cfree() {
fi
}
-# cf_workdir TOOL : mktemp -d under TMPDIR with the canonical name and install
-# an EXIT trap removing it. Echoes the path. NOTE: the EXIT trap is a singleton;
-# call once per harness.
+# cf_workdir TOOL : mktemp -d under TMPDIR with the canonical name, store it in
+# the global CF_WORK, and install an EXIT trap removing it. Call as
+# `cf_workdir TOOL` (NOT `CF_WORK=$(cf_workdir TOOL)`): the trap must be set in
+# the caller's shell, so the function may not run inside a command-substitution
+# subshell — there the EXIT trap fires (and deletes CF_WORK) the moment the
+# subshell closes, before the harness ever uses it. NOTE: the EXIT trap is a
+# singleton; call once per harness.
cf_workdir() {
- cf_wd_dir=$(mktemp -d "${TMPDIR:-/tmp}/cfree-$1-test.XXXXXX")
- trap 'rm -rf "$cf_wd_dir"' EXIT
- printf '%s' "$cf_wd_dir"
+ CF_WORK=$(mktemp -d "${TMPDIR:-/tmp}/cfree-$1-test.XXXXXX")
+ trap 'rm -rf "$CF_WORK"' EXIT
}
diff --git a/test/objcopy/run.sh b/test/objcopy/run.sh
@@ -15,7 +15,7 @@ CFREE="${CFREE:-$repo_root/build/cfree}"
export CFREE
cf_require_cfree objcopy-driver
-CF_WORK=$(cf_workdir objcopy)
+cf_workdir objcopy
cf_report_init
for sh in "$cases_dir"/*.sh; do
[ -e "$sh" ] || continue
diff --git a/test/objdump/run.sh b/test/objdump/run.sh
@@ -19,7 +19,7 @@ CFREE="${CFREE:-$repo_root/build/cfree}"
export CFREE
cf_require_cfree objdump-driver
-CF_WORK=$(cf_workdir objdump)
+cf_workdir objdump
CF_SCENARIO_SKIP=1 # honor leading "SKIP" lines from cases
cf_report_init
for arch_dir in "$script_dir"/*/; do
diff --git a/test/strings/run.sh b/test/strings/run.sh
@@ -15,7 +15,7 @@ CFREE="${CFREE:-$repo_root/build/cfree}"
export CFREE
cf_require_cfree strings-driver
-CF_WORK=$(cf_workdir strings)
+cf_workdir strings
cf_report_init
for sh in "$cases_dir"/*.sh; do
[ -e "$sh" ] || continue
diff --git a/test/strip/run.sh b/test/strip/run.sh
@@ -15,7 +15,7 @@ CFREE="${CFREE:-$repo_root/build/cfree}"
export CFREE
cf_require_cfree strip-driver
-CF_WORK=$(cf_workdir strip)
+cf_workdir strip
cf_report_init
for sh in "$cases_dir"/*.sh; do
[ -e "$sh" ] || continue