Skip to content

Increase test coverage to ~99.5% - #19

Merged
david-littlefarmer merged 1 commit into
masterfrom
test/increase-coverage
Aug 7, 2026
Merged

Increase test coverage to ~99.5%#19
david-littlefarmer merged 1 commit into
masterfrom
test/increase-coverage

Conversation

@david-littlefarmer

Copy link
Copy Markdown
Member

Summary

  • The formatter package had almost no tests (7.5% coverage, only comments_test.go from Fix comment parsing to respect word boundaries around '#' #18). Added formatter/errors_test.go, formatter/formatter_test.go, formatter/processor_test.go, and extended comments_test.go, covering the section-parsing state machine (formatLine/parseSection/processLines), comment/error printing, method-argument formatting, and the comment/hash word-boundary logic from Inconsistent pathological comment parsing #17.
  • Fixed the dead/unused testHelpFlag helper in main_test.go (lowercase name meant it never ran, and its logic was broken anyway) and replaced it with real tests, including subprocess-based tests for the os.Exit/log.Fatalf code paths that would otherwise kill the test binary (and its coverage profile) if exercised in-process.
  • Added make coverage (prints per-function %) and make coverage-html targets.
  • Added coverage.html to .gitignore.

Coverage

Package Before After
formatter 7.5% 99.7%
main (root) 54.7% 98.4%
total 15.2% 99.5%

Two spots remain below 100%, both intentionally so:

  • formatter/processor.go's annotation branch len(parts) < 2 is unreachable dead code — parseSection only routes to that branch when the line already starts with @, so the split can never return fewer than 2 parts.
  • main()'s log.Fatalf error branch calls os.Exit, which can't be safely triggered in-process (it would abort the test binary before it writes its own coverage profile). It's verified behaviorally via subprocess tests instead (TestSubprocess_*), which don't count toward this package's in-process coverage percentage.

Test plan

  • go build ./...
  • go test ./... (all pass)
  • make coverage — 99.5% total
  • gofmt -l . / go vet ./... clean

The formatter package had almost no tests (7.5% coverage). Added
tests for comments.go, errors.go, formatter.go, and processor.go
covering the section-parsing state machine, error/comment printing,
method argument formatting, and comment/hash boundary handling.

Also fixed the dead, unused testHelpFlag helper in main_test.go and
replaced it with working tests, including subprocess-based tests for
the os.Exit/log.Fatalf code paths that can't be safely exercised
in-process.

Added `make coverage` / `make coverage-html` targets.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@david-littlefarmer
david-littlefarmer merged commit 4f42271 into master Aug 7, 2026
1 check passed
@david-littlefarmer
david-littlefarmer deleted the test/increase-coverage branch August 7, 2026 10:47
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.

1 participant