Fix InheritsTests source location to show actual test method location#3061
Fix InheritsTests source location to show actual test method location#3061
Conversation
Resolves issue #3055 where tests using [InheritsTests] attribute reported source location at the attribute location instead of the actual test method location. Changes: - Added GetMethodLocation helper to extract actual method source location - Modified GenerateInheritedTestSources to use method location when available - Falls back to class location if method location unavailable - Updated snapshot tests to reflect correct line numbers 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Improved the source location fix by leveraging the existing CallerFilePath and CallerLineNumber parameters in TestAttribute constructor arguments, which are automatically captured when the [Test] attribute is applied. This approach is: - Simpler and more reliable than parsing syntax trees - Uses the built-in compiler-provided location information - Removes the need for the GetMethodLocation helper method - More consistent with how regular test methods get their source location The TestAttribute already captures the exact file and line number via [CallerFilePath] and [CallerLineNumber] attributes, making this the preferred approach for getting accurate source locations. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Claude finished @thomhurst's task —— View job Code Review Complete ✅
Review SummaryThis PR successfully fixes the source location issue for ✅ StrengthsClean Implementation
Good Code Quality
Comprehensive Testing
🔍 Technical AnalysisThe Fix (TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs:136-141) var filePath = testAttribute.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString() ??
classInfo.ClassSyntax.GetLocation().SourceTree?.FilePath ??
classInfo.ClassSyntax.SyntaxTree.FilePath;
var lineNumber = (int?)testAttribute.ConstructorArguments.ElementAtOrDefault(1).Value ??
classInfo.ClassSyntax.GetLocation().GetLineSpan().StartLinePosition.Line + 1;This correctly extracts the caller information that Performance: ✅ Excellent
Security: ✅ No concerns
Potential Issues:
🎯 Test Coverage AssessmentThe snapshot changes demonstrate the fix works across various inheritance scenarios:
💡 Minor Suggestions
✅ Overall AssessmentThis is a high-quality fix that:
The approach of using the Recommendation: Approve and merge ✅ |
|
Claude finished @thomhurst's task —— View job Code Review Complete ✅
Review SummaryThis PR successfully fixes the source location issue for ✅ StrengthsClean Implementation
Good Code Quality
Comprehensive Testing
🔍 Technical AnalysisThe Fix (TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs:136-141) var filePath = testAttribute.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString() ??
classInfo.ClassSyntax.GetLocation().SourceTree?.FilePath ??
classInfo.ClassSyntax.SyntaxTree.FilePath;
var lineNumber = (int?)testAttribute.ConstructorArguments.ElementAtOrDefault(1).Value ??
classInfo.ClassSyntax.GetLocation().GetLineSpan().StartLinePosition.Line + 1;This correctly extracts the caller information that Performance: ✅ Excellent
Security: ✅ No concerns
Potential Issues:
🎯 Test Coverage AssessmentThe snapshot changes demonstrate the fix works across various inheritance scenarios:
💡 Minor Suggestions
✅ Overall AssessmentThis is a high-quality fix that:
The approach of using the Recommendation: Approve and merge ✅ |
Fixes #3055