test(engine): cover remaining directives.go branches and remove dead code#1
Merged
matuszeg merged 1 commit intofeat/nomutant-directivefrom Apr 29, 2026
Merged
Conversation
…code Codecov flagged four uncovered lines in internal/engine/directives.go. Two of them were genuinely missing tests — the nil-receiver guard in isSuppressed and the empty-name "continue" inside parseDirective's comma-split loop — and are now exercised by new unit tests. The other two were a *ast.Comment guard inside both collectTokenLines and largestNodeStartingAtLine that turn out to be unreachable, because the preceding *ast.CommentGroup guard already returns false from the ast.Inspect callback and ast.Inspect therefore never descends into the CommentGroup's *ast.Comment children. Removed both as dead code and noted in a comment why no Comment guard is needed.
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
Internal review branch addressing the four lines Codecov flagged on
internal/engine/directives.go(lines 68, 168, 214, 268 of the version onfeat/nomutant-directive@1ca72c6).isSuppressed. Now exercised byTestDirectiveIndex_NilReceiverIsSafe, which calls(*directiveIndex)(nil).isSuppressed(...)and confirms it returnsfalsewithout panicking.continueinside the comma-split loop inparseDirective, hit when an empty entry appears (e.g.//nomutant:arithmetic-base,,invert-bitwise). Now exercised byTestBuildDirectiveIndex_TypedFilterWithEmptyEntries.*ast.Commentguards insidecollectTokenLinesandlargestNodeStartingAtLine. Removed as unreachable: the preceding*ast.CommentGroupguard already returnsfalsefrom theast.Inspectcallback, so the walker never descends into the CommentGroup's*ast.Commentchildren. Added a comment explaining why no Comment guard is needed.Test plan
go test -race ./internal/engine/...— all greenmake lint— 0 issuesgo tool cover -funcondirectives.go— every function reports 100.0%If this looks good, merging it into
feat/nomutant-directivewill update the real PR (go-gremlins#279) with the coverage and dead-code fixes.