Emit test_ref facts for Go so test-only symbols aren't reported dead - #89
Merged
Conversation
A production function whose only caller is its own _test.go was reported as high-confidence dead code. Two gates caused it, and fixing either alone is a no-op: the walker collects an ignored file for reference-only extraction only when it matches a test glob, and runTestRefExtractors skips extractors that don't implement plugin.TestRefExtractor. - config.Default().TestGlobs gains "**/*_test.go". Go's bare suffix is safe: the toolchain defines any *_test.go as a test file, so no production file can collide with it the way _test.rb did (v97). - goextractor implements ExtractTestRefs, resolving targets with the production resolvers (flattenSelector/collectLocalTypes/resolveChain). A reference from a test is therefore spelled exactly as one from production, and inherits goBuiltins filtering — a package-level min shadowing the builtin is still not credited, from either side. Copying Ruby's identifier-level walker would have rescued unrelated symbols by bare name, trading false positives for false negatives. - Deliberately no OwnsFile: plugin.FileOwner is what opts an extractor into the incremental cache, and adding it would move .go files out of the shared partition that keys every other extractor. ExtractTestRefs filters internally. cacheVersion v100 + cachecov entry. go_sample gains a_test.go (in-package) and a_ext_test.go (package a_test) to pin both Go test idioms; the latter calls a dedicated Gamma rather than Alpha, whose dependent count TestE2E_ImpactAnalysis asserts — a test_ref counts as a graph dependent, which is a separate pre-existing defect in god-class/hotspots.
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.
A production function whose only caller is its own _test.go was reported as high-confidence dead code. Two gates caused it, and fixing either alone is a no-op: the walker collects an ignored file for reference-only extraction only when it matches a test glob, and runTestRefExtractors skips extractors that don't implement plugin.TestRefExtractor.
cacheVersion v100 + cachecov entry. go_sample gains a_test.go (in-package) and a_ext_test.go (package a_test) to pin both Go test idioms; the latter calls a dedicated Gamma rather than Alpha, whose dependent count TestE2E_ImpactAnalysis asserts — a test_ref counts as a graph dependent, which is a separate pre-existing defect in god-class/hotspots.