testmark-bash

tests: move run_case into lib.sh, for a second runner test script to share.

commit 499e4121d70fb6b85966ca1224662f5647c3e0b9 · parent 90280a0b42 · browse this tree
Ximianth, 2026-10-25 12:00:21 UTC

diff --git a/tests/lib.sh b/tests/lib.sh
index 57b9371..543b744 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -144,3 +144,21 @@ parse_case() {
 	dump_parse in.md >got # not in $(...), so a library bug that kills the shell kills this script too
 	expect_eq "$1" "$(<got)" "$(printf '%s\n' "${@:3}")"
 }
+
+## Writes t/doc.md and t/test.sh, runs the script in a fresh bash from $work, and checks what it printed and its status.
+## The script gets a line sourcing the library first.  $work in the output shows as WORK.
+##
+## - @param $1 description
+## - @param $2 t/doc.md's content
+## - @param $3 the rest of t/test.sh
+## - @param $4 the expected stdout, then a line `--- stderr`, then the expected stderr, then `--- status N`
+run_case() {
+	mkdir -p t
+	printf '%s' "$2" >t/doc.md
+	printf 'source %q\n%s\n' "$ROOT/lib/testmark.bash" "$3" >t/test.sh
+	local rc=0 got
+	"$BASH" t/test.sh >"$work/out" 2>"$work/err" </dev/null || rc=$?
+	got="$(<"$work/out")"$'\n'"--- stderr"$'\n'"$(<"$work/err")"$'\n'"--- status $rc"
+	got=${got//$work/WORK}
+	expect_eq "$1" "$got" "$4"
+}
diff --git a/tests/test-run.sh b/tests/test-run.sh
index 3559860..c4728e7 100755
--- a/tests/test-run.sh
+++ b/tests/test-run.sh
@@ -8,24 +8,6 @@ cd "$(dirname "$0")"
 source ./lib.sh
 
 unset TESTMARK_REGEN TESTMARK_RAW_ERRORS
-mkdir t
-
-## Writes t/doc.md and t/test.sh, runs the script from $work, and checks what it printed and its status.
-## The script gets a line sourcing the library first.  $work in the output shows as WORK.
-##
-## - @param $1 description
-## - @param $2 t/doc.md's content
-## - @param $3 the rest of t/test.sh
-## - @param $4 the expected stdout, then a line `--- stderr`, then the expected stderr, then `--- status N`
-run_case() {
-	printf '%s' "$2" >t/doc.md
-	printf 'source %q\n%s\n' "$ROOT/lib/testmark.bash" "$3" >t/test.sh
-	local rc=0 got
-	"$BASH" t/test.sh >"$work/out" 2>"$work/err" </dev/null || rc=$?
-	got="$(<"$work/out")"$'\n'"--- stderr"$'\n'"$(<"$work/err")"$'\n'"--- status $rc"
-	got=${got//$work/WORK}
-	expect_eq "$1" "$got" "$4"
-}
 
 ## Checks t/doc.md's bytes, as `bytes` quotes them.
 ##