Skip to content

fix(coverage): ignore case comments and done redirections (#634)#635

Merged
Chemaclass merged 2 commits intomainfrom
fix/634-coverage-non-executable-lines
Apr 21, 2026
Merged

fix(coverage): ignore case comments and done redirections (#634)#635
Chemaclass merged 2 commits intomainfrom
fix/634-coverage-non-executable-lines

Conversation

@Chemaclass
Copy link
Copy Markdown
Member

Summary

  • Case patterns with trailing comments (e.g. *thing) # note) were counted as executable lines.
  • Loop terminators with redirections or pipes (done < file, done <<<"$var", done | sort, done < <(cmd)) were counted as executable lines.
  • Both inflated the executable-lines denominator and distorted coverage percentages.

Fix

  • src/coverage.sh::bashunit::coverage::is_executable_line:
    • Allow an optional trailing (#.*)? on the case-pattern regex so *pat) # comment is recognized as non-executable.
    • Add a new check that treats done followed by any of <, >, |, & as a non-executable loop terminator.

Test plan

  • ./bashunit tests/unit/coverage_executable_test.sh tests/unit/coverage_core_test.sh
  • ./bashunit tests/
  • ./bashunit --parallel tests/
  • make sa
  • make lint
  • New regression unit tests for each reported pattern
  • Integration test via get_executable_lines on a fixture with all patterns

Closes #634

Coverage counted `*pat) # comment` and loop terminators with
redirections or pipes (`done < file`, `done <<<"$var"`, `done | sort`)
as executable lines. Update is_executable_line regex to skip trailing
comments on case patterns and treat `done` followed by `<`, `>`, `|`
or `&` as a non-executable loop terminator.

Closes #634
Widen the loop-terminator skip to match `done 2>&1`, `done &`, `done >>`
and other non-space trailing forms. Regex now requires any non-space,
non-comment char after `done ` so any valid trailing redirection, fd
redirect, pipe or background marker keeps `done` non-executable.
@Chemaclass Chemaclass merged commit 15aa158 into main Apr 21, 2026
30 checks passed
@Chemaclass Chemaclass deleted the fix/634-coverage-non-executable-lines branch April 21, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Non-executable lines of code marked as executable in coverage report

1 participant