tests: patch, check, and write under the caller settings test's errexit, ERR trap, nocasematch, and noclobber.
commit 2063a16c560aeb961d431d4e180ed9e149019ab0 · parent 4a4248cccf
· browse this tree
Ximianth, 2026-10-24 00:25:16 UTC
diff --git a/tests/test-caller-env.sh b/tests/test-caller-env.sh index d69f237..10446c3 100755 --- a/tests/test-caller-env.sh +++ b/tests/test-caller-env.sh @@ -26,6 +26,20 @@ expect_eq "errexit: a doc without a final newline" "$(testmark_body doc x)" "hel rc=0 testmark_body doc nope 2>/dev/null || rc=$? expect_eq "errexit: an error returns, to a caller that checks" "$rc" 1 + +# Patch, check, and write, called directly the same way; and write under noclobber, since it writes the file in place. +printf '[testmark]:# (x)\n```\nhello\n```\n[testmark]:# (y)\n```\nhello\n```\n[testmark]:# (z)\n```\nhello\n```\n' >in.md +testmark_parse doc in.md +testmark_check doc x <<<'hello' +rc=0 +testmark_check doc z <<<'HELLO' 2>/dev/null || rc=$? +expect_eq "nocasematch: a check that differs only in case fails" "$rc" 1 +testmark_patch doc x <<<'patched' +TESTMARK_REGEN=1 testmark_check doc y <<<'regen' +set -C +testmark_write doc +set +C +expect_eq "errexit, noclobber: patch, check, and write" "$(testmark_body doc x)$(testmark_body doc y)" "patchedregen" expect_eq "the ERR trap never fired" "$err_trap_fired" 0 # The library turns on set -u for its own code only.