Skip to content

fix(coverage): quote coverage paths baked into the DEBUG trap - #1246

Merged
Chemaclass merged 1 commit into
mainfrom
fix/coverage-path-with-space
Aug 14, 2026
Merged

fix(coverage): quote coverage paths baked into the DEBUG trap#1246
Chemaclass merged 1 commit into
mainfrom
fix/coverage-path-with-space

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1245

--coverage-paths "my src/" produced a DEBUG trap that does not parse:

debug trap: line 265: syntax error near unexpected token `src/*'
… 75 more
Tests:      0 passed, 1 failed, 1 total
Assertions: 1 passed, 0 failed, 1 total
my src/math lib.sh                         0/  1 lines (  0%)

The worst part is the third line: the test is reported failed while its own assertion passed, so a correct suite goes red for a reason unrelated to the code under test. Coverage also silently reads 0%.

💡 Changes

  • Single-quote the literal path segments, leaving * and | as syntax — the alternation still has to reach the trap as syntax, which is why the paths are baked in at all
  • Escape an embedded apostrophe as '\'', built from variables because the replacement in ${var//pat/repl} processes backslashes and mangles the inline spelling; verified by round-tripping through a real case
  • Rewrite three tests that asserted the glob's spelling to assert what it admits, using the glob_matches helper the same file already had — a spelling assertion cannot tell a pattern that parses from one that parses and matches nothing

Quoting is also the more correct reading: a coverage path is a literal, so a [ or ? in a directory name should not act as a pattern.

A coverage path containing a space produced a trap that does not parse:
"syntax error near unexpected token" on every executed line, 75 of them for a
one-test run, coverage reported 0% because record_line never ran, and the test
itself was marked failed although its assertion passed.

build_trap_glob bakes the paths into a `case` as syntax on purpose -- `|`
arriving through a variable would not split -- but the literal segments were
interpolated unquoted. Quote those and leave `*` and `|` as syntax. That also
reads more correctly: a coverage path is a literal, so `[` or `?` in a
directory name must not act as a pattern.

An apostrophe has to be escaped as '\'', and that cannot be written inline:
the replacement in ${var//pat/repl} processes backslashes and hands it back
mangled, so it is built from variables and verified by round-tripping through
a real `case`.

Three tests asserted the glob's spelling and broke on the quoting although the
behaviour was unchanged. The file already had a glob_matches helper that evals
the pattern; they now assert what the glob admits, which is also the only way
to tell a pattern that parses from one that parses and matches nothing.

Closes #1245
@Chemaclass Chemaclass added the bug Something isn't working label Aug 14, 2026
@Chemaclass Chemaclass self-assigned this Aug 14, 2026
@Chemaclass
Chemaclass merged commit a72c35e into main Aug 14, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the fix/coverage-path-with-space branch August 14, 2026 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant