fix(source-gen): correct source location for cross-project inherited tests#6133
Merged
thomhurst merged 1 commit intoMay 31, 2026
Merged
Conversation
…tests When a test is inherited (via [InheritsTests]) from an abstract base class in a *referenced assembly*, the base method symbol has no source location in the current compilation (method.Locations is not in source). The fallback then took the *derived class's* syntax line span but paired it with the base file path (from the [Test] attribute's CallerFilePath), producing an inconsistent location: the base file shown at the derived class's line range. The Source view of the HTML report (and any IDE/tooling consuming the test node location) jumped to unrelated lines in the base file. The [Test] attribute's CallerFilePath/CallerLineNumber are baked at the base method declaration and remain the correct pointer, so fall back to those instead of the derived class's syntax span. Same-compilation inheritance is unaffected (the base method is in source and its own span is used). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
Owner
|
Thanks! 😄 |
1 task
This was referenced Jun 1, 2026
This was referenced Jun 3, 2026
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.
Problem
For a test inherited via
[InheritsTests]from an abstract base class in a referenced assembly (a separate project), the generated source location pairs the base file path with the derived class's line range.Concretely, a derived
SqsChangeMessageVisibilityAsyncVerificationTests : SqsChangeMessageVisibilityAsyncTestsreports every test method atSqsChangeMessageVisibilityAsyncTests.cs(base, correct) but lines 3–19 — which is the derived class's declaration span, not the method. Tooling consuming the test node location (e.g. the HTML report's Source tab) then opens the base file at unrelated lines.Cause
In
TestMetadataGenerator.GetTestMethodSourceLocation(inherited overload), when the base method symbol has no source location in the current compilation (method.Locationsis in metadata, because the base class is in a referenced assembly), the fallback usedclassInfo.ClassSyntax.GetLineSpan()(the derived class span) while keepingattrFilePath(the[Test]attribute'sCallerFilePath→ the base file). The two don't correspond.Fix
The
[Test]attribute'sCallerFilePath/CallerLineNumberare baked at the base method declaration and remain the correct pointer, so fall back to those instead of the derived class's syntax span. Same-compilation inheritance is unaffected — the base method is in source and its own span is still used (verified: existingInheritsTests*snapshot tests pass unchanged).Test coverage gap
The existing SG test harness compiles base + derived in a single compilation (
AdditionalFiles), so the base method is always in-source and can't reproduce the metadata-symbol path. A genuine regression test needs the harness extended to add a pre-compiled assembly reference. Flagging as a follow-up.Regression range
This is a regression introduced between 1.45.8 and 1.47.0. Verified against the real project that reported it (
LocalSqsSnsMessaging, cross-project[InheritsTests]):LineNumber(the base method's[Test]line).LineNumber = 5, EndLineNumber = 17for a method actually at line 90).LineNumber = 90, and other inherited methods resolve to their real base-file lines.🤖 Generated with Claude Code