Skip to content

fix(coverage): count only the braces that are code when spanning a function - #1087

Merged
Chemaclass merged 1 commit into
mainfrom
fix/1086-brace-aware-function-spans
Aug 13, 2026
Merged

Chemaclass merged 1 commit into
mainfrom
fix/1086-brace-aware-function-spans

Conversation

@Chemaclass

Copy link
Copy Markdown
Member

🤔 Background

Related #1086

A function ended where its braces balanced, counted with no regard for quoting.
One stray brace in a comment, a string or a heredoc kept it open, and it
swallowed every later declaration in the file — src/coverage/lines.sh
reported 1 function instead of 11.

💡 Changes

  • Quote and heredoc state is carried across lines, since both span them, and a declaration is recognised only on a line starting outside either
  • Bash is the oracle: under extdebug, declare -F gives the real start line of all 697 functions in src/, and extraction now matches every one — it was 19 missing and 2 spurious (END { of an embedded awk program read as a function)
  • FN, FNDA, FNF and FNH change (680 → 697 records here); LF and BRF are byte-identical
  • Same output on macOS awk, BusyBox awk and mawk; the scan costs 535 ms for 128 files against the 2238 ms Bash loop removed in perf(coverage): scan function declarations in one awk pass #1085

…nction

A function ended where its braces balanced, counted with no regard for
quoting. One stray brace in a comment, a string or a heredoc kept it open and
it swallowed every later declaration: src/coverage/lines.sh reported 1
function instead of 11, and the END block of an embedded awk program was
reported as a function called END.

The scanner now carries quote and heredoc state across lines, because both
span them, and a declaration is only recognised on a line that starts outside
either. Bash itself is the oracle: under extdebug, declare -F gives the real
start line of all 697 functions in src/, and extraction now matches every one
of them, with nothing spurious. It was 19 missing and 2 spurious.

FN, FNDA, FNF and FNH change; LF and BRF are byte-identical.

Closes #1086
@Chemaclass Chemaclass added the bug Something isn't working label Aug 13, 2026
@Chemaclass Chemaclass self-assigned this Aug 13, 2026
@Chemaclass
Chemaclass merged commit 393d4e8 into main Aug 13, 2026
37 checks passed
@Chemaclass
Chemaclass deleted the fix/1086-brace-aware-function-spans branch August 13, 2026 05:20
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