Increase test coverage to ~99.5% - #19
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
formatterpackage had almost no tests (7.5% coverage, onlycomments_test.gofrom Fix comment parsing to respect word boundaries around '#' #18). Addedformatter/errors_test.go,formatter/formatter_test.go,formatter/processor_test.go, and extendedcomments_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.testHelpFlaghelper inmain_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 theos.Exit/log.Fatalfcode paths that would otherwise kill the test binary (and its coverage profile) if exercised in-process.make coverage(prints per-function %) andmake coverage-htmltargets.coverage.htmlto.gitignore.Coverage
formattermain(root)Two spots remain below 100%, both intentionally so:
formatter/processor.go's annotation branchlen(parts) < 2is unreachable dead code —parseSectiononly routes to that branch when the line already starts with@, so the split can never return fewer than 2 parts.main()'slog.Fatalferror branch callsos.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% totalgofmt -l ./go vet ./...clean