tests: give each test-api.sh section its own handles.
commit d29c0383dc030dbe3983670ece3533f78f1aaa6f · parent c24db4dd24
· browse this tree
Ximianth, 2026-10-23 14:48:55 UTC
The sourcing and error sections read handle 'a' as the re-parse section left it, so editing one section could break another. Dropped the row checking that a parse after re-sourcing doesn't collide with open docs: it guarded a handle counter that sourcing used to reset, which no longer exists.
diff --git a/tests/test-api.sh b/tests/test-api.sh index 91be24a..d91b3c7 100755 --- a/tests/test-api.sh +++ b/tests/test-api.sh @@ -82,25 +82,25 @@ testmark_parse g b.md expect_eq "a re-parse leaves nothing of the old doc" "$(globals)" "$before" # --- sourcing: twice keeps state; inside a function still makes globals --- +testmark_parse s a.md # shellcheck source=lib/testmark.bash source "$ROOT/lib/testmark.bash" -expect_eq "sourcing again keeps open docs" "$(testmark_body a x)" "two" -testmark_parse c none.md -expect_fail "and later parses don't collide with them" 'testmark: c: no hunk named "x"' testmark_body c x +expect_eq "sourcing again keeps open docs" "$(testmark_body s x)" "one" expect_eq "sourcing inside a function" "$( "$BASH" -c 'f() { source "$1"; }; f "$1"; testmark_parse d1 a.md; testmark_parse d2 b.md; testmark_body d1 x' _ "$ROOT/lib/testmark.bash" )" "one" # --- errors --- +testmark_parse r a.md expect_fail "unknown handle" 'testmark: unknown handle "nope"' testmark_body nope x -expect_fail "unknown hunk" 'testmark: a: no hunk named "nope"' testmark_info a nope +expect_fail "unknown hunk" 'testmark: r: no hunk named "nope"' testmark_info r nope expect_fail "invalid handle" 'testmark: invalid handle "a-b": must match [A-Za-z0-9_]+' testmark_parse a-b a.md expect_fail "empty handle" 'testmark: invalid handle "": must match [A-Za-z0-9_]+' testmark_parse '' a.md -expect_fail "directory" 'testmark: .: not a readable file' testmark_parse a . -expect_fail "parse arity" 'testmark: usage: testmark_parse HANDLE FILE' testmark_parse a +expect_fail "directory" 'testmark: .: not a readable file' testmark_parse r . +expect_fail "parse arity" 'testmark: usage: testmark_parse HANDLE FILE' testmark_parse r expect_fail "names arity" 'testmark: usage: testmark_names HANDLE' testmark_names -expect_fail "body arity" 'testmark: usage: testmark_body HANDLE NAME' testmark_body a x y -expect_fail "info arity" 'testmark: usage: testmark_info HANDLE NAME' testmark_info a +expect_fail "body arity" 'testmark: usage: testmark_body HANDLE NAME' testmark_body r x y +expect_fail "info arity" 'testmark: usage: testmark_info HANDLE NAME' testmark_info r # --- names with shell syntax: plain data, never evaluated --- names=('$(>pwned1)' '`>pwned2`' 'a]b' 'x[0]' '@' '*' '$HOME' "'q'" '"q"' 'a\b')