testmark-bash

tests: share one parse_case, in lib.sh, instead of a copy per script.

commit 3c9f75eb9f9714e200a1747d6a3d006623db44b6 · parent 736f5b0b6e · browse this tree
Ximianth, 2026-10-23 14:49:43 UTC

diff --git a/tests/lib.sh b/tests/lib.sh
index 7940209..d87f243 100644
--- a/tests/lib.sh
+++ b/tests/lib.sh
@@ -100,3 +100,14 @@ dump_parse() {
 		printf 'error: %s\n' "$(<"$work/err")"
 	fi
 }
+
+## Parses a document given as a printf format, and checks its dump against the expected lines.
+##
+## - @param $1 case name
+## - @param $2 document, as a printf format
+## - @param $3... expected dump lines
+parse_case() {
+	printf -- "$2" >in.md
+	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}")"
+}
diff --git a/tests/test-caller-env.sh b/tests/test-caller-env.sh
index 6e8b7df..1d6e317 100755
--- a/tests/test-caller-env.sh
+++ b/tests/test-caller-env.sh
@@ -13,13 +13,6 @@ shopt -s nocasematch failglob extglob
 IFS='(#) '
 export LC_ALL=C.UTF-8
 
-## Like test-parse.sh's parse_case.
-parse_case() {
-	printf -- "$2" >in.md
-	dump_parse in.md >got
-	expect_eq "$1" "$(<got)" "$(printf '%s\n' "${@:3}")"
-}
-
 parse_case "nocasematch: annotations are case-sensitive" '[TESTMARK]:# (x)\n```\nhello\n```\n'
 parse_case "UTF-8 locale: an em space isn't whitespace" \
 	'[testmark]:# (a\xe2\x80\x83b)\n```\xe2\x80\x83json\xe2\x80\x83\nhello\n```\n' \
diff --git a/tests/test-parse.sh b/tests/test-parse.sh
index 5790d80..d4c43b8 100755
--- a/tests/test-parse.sh
+++ b/tests/test-parse.sh
@@ -10,15 +10,6 @@ source ./lib.sh
 MAL='malformed annotation; want "[testmark]:# (name)"'
 DANGLING='annotation not followed by a code block'
 
-## - @param $1 case name
-## - @param $2 document, as a printf format
-## - @param $3... expected dump lines
-parse_case() {
-	printf -- "$2" >in.md
-	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}")"
-}
-
 # --- annotation line shape ---
 parse_case ann-basic 'prose\n\n[testmark]:# (x)\n```text\nhello\n```\n' 'hunk "x"' 'info "text"' 'body "hello\n"'
 parse_case ann-trailing-text '[testmark]:# (x reserved words)\n```\nhello\n```\n' 'hunk "x"' 'info ""' 'body "hello\n"'