Problem
Branch coverage records whether an arm was taken, never how often. compute_branch_hits (src/coverage/branches.sh:223) emits taken_count as 0 or 1, documented as an MVP limit, and report_lcov writes that straight into BRDA (src/coverage/report_lcov.sh:64).
LCOV consumers read the BRDA fourth field as an execution count. Reporting 1 for an arm taken 5,000 times and 1 for an arm taken once loses the distinction that makes branch data useful: which paths are exercised in earnest and which are grazed by a single test.
The per-line data needed already exists. _BASHUNIT_COVERAGE_HITS_BY_LINE holds real execution counts, which is what LCOV DA records emit today.
Proposal
Report the arm's execution count instead of a taken flag.
_arm_taken (src/coverage/branches.sh:204) returns on the first hit line. Instead, take the count of the arm's first executable line, which is the closest analogue to how other tools count an arm entry.- Decide the rule explicitly and document it: first executable line's count, or the maximum across the arm's lines. First-line count is the honest one for an arm, since later lines can be skipped by an early return.
BRDA then carries a real count, and BRH still counts arms with a non-zero count, so existing summaries stay valid.
Low priority next to the correctness issues in this audit. It improves data quality, it does not correct a wrong number.
Where to change
src/coverage/branches.sh:196-251_arm_taken, compute_branch_hitssrc/coverage/report_lcov.sh:60-69BRDA emissionsrc/coverage/html_file.sh if the HTML report shows branch data
Acceptance criteria
Repo checklist (agent)
- TDD: RED then GREEN then REFACTOR. Write the failing test first.
- Bash 3.0+ only: no
printf -v, no += append, no declare -A, no [[ ]], no ${var,,}, no &>>, no ${arr[-1]}. - The
_branch_* helpers mutate their caller's locals through dynamic scoping on purpose and must stay in one file, see ADR-010 and the comment at src/coverage/branches.sh:196-202. - Gates:
make sa, make lint, ./bashunit tests/, ./bashunit --parallel tests/. Never run shfmt -w. - CHANGELOG.md: one line under
## Unreleased. - One issue = one PR.
Problem
Branch coverage records whether an arm was taken, never how often.
compute_branch_hits(src/coverage/branches.sh:223) emitstaken_countas 0 or 1, documented as an MVP limit, andreport_lcovwrites that straight intoBRDA(src/coverage/report_lcov.sh:64).LCOV consumers read the
BRDAfourth field as an execution count. Reporting 1 for an arm taken 5,000 times and 1 for an arm taken once loses the distinction that makes branch data useful: which paths are exercised in earnest and which are grazed by a single test.The per-line data needed already exists.
_BASHUNIT_COVERAGE_HITS_BY_LINEholds real execution counts, which is what LCOVDArecords emit today.Proposal
Report the arm's execution count instead of a taken flag.
_arm_taken(src/coverage/branches.sh:204) returns on the first hit line. Instead, take the count of the arm's first executable line, which is the closest analogue to how other tools count an arm entry.BRDAthen carries a real count, andBRHstill counts arms with a non-zero count, so existing summaries stay valid.Low priority next to the correctness issues in this audit. It improves data quality, it does not correct a wrong number.
Where to change
src/coverage/branches.sh:196-251_arm_taken,compute_branch_hitssrc/coverage/report_lcov.sh:60-69BRDAemissionsrc/coverage/html_file.shif the HTML report shows branch dataAcceptance criteria
BRDAreports the arm's execution count, not 0 or 1BRFandBRHtotals are unchanged for the same rungenhtmlaccepts the output, tested on a real LCOV filetrapandxtrace)Repo checklist (agent)
printf -v, no+=append, nodeclare -A, no[[ ]], no${var,,}, no&>>, no${arr[-1]}._branch_*helpers mutate their caller's locals through dynamic scoping on purpose and must stay in one file, see ADR-010 and the comment atsrc/coverage/branches.sh:196-202.make sa,make lint,./bashunit tests/,./bashunit --parallel tests/. Never runshfmt -w.## Unreleased.