Keep the list of storage kinds in one place, and unset a handle's globals by looping over it.
commit 8618f82f0e74f9293b6004775f14be95578c7310 · parent 0ad96a7762
· browse this tree
Ximianth, 2026-10-23 14:47:37 UTC
Adding a kind now means adding it to that list, and declaring it at the commit if it's assoc.
diff --git a/lib/testmark/document.bash b/lib/testmark/document.bash index ade7b8e..52547d4 100644 --- a/lib/testmark/document.bash +++ b/lib/testmark/document.bash @@ -14,6 +14,7 @@ # Globals are reached through namerefs; assoc ones are declared first, since a nameref to an undeclared name makes an indexed array. # Hunk names come from documents, so they are hostile as keys: on some bash versions, arithmetic, `[[ -v ]]`, `unset`, and `printf -v` on an element run `$(...)` from inside its key. # So touch name-keyed elements only as `a[$k]=v`, `"${a[$k]}"`, `"${a[$k]-}"`, `${a[$k]+set}`, and `"${!a[@]}"`. +_testmark_kinds=(lines start end info names pid) _testmark_err() { >&2 printf 'testmark: %s\n' "$1" @@ -32,9 +33,9 @@ _testmark_parse() { _testmark_err "usage: testmark_parse HANDLE FILE" return 1 } - local h=$1 file=$2 + local h=$1 file=$2 kind _testmark_handle "$h" || return 1 - unset -v "_testmark_lines_$h" "_testmark_start_$h" "_testmark_end_$h" "_testmark_info_$h" "_testmark_names_$h" "_testmark_pid_$h" + for kind in "${_testmark_kinds[@]}"; do unset -v "_testmark_${kind}_$h"; done # A directory would read as zero lines, so it's rejected here. [[ -f $file && -r $file ]] || { _testmark_err "$file: not a readable file"