Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal sealed class ConcreteClass1_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal sealed class ConcreteClass2_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 2,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down Expand Up @@ -231,7 +231,7 @@ internal sealed class ConcreteClass2_SecondTest_TestSource_GUID : global::TUnit.
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 3,
LineNumber = 11,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2),
Expand Down Expand Up @@ -329,7 +329,7 @@ internal sealed class ConcreteClass1_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal sealed class ConcreteClass2_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 2,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down Expand Up @@ -231,7 +231,7 @@ internal sealed class ConcreteClass2_SecondTest_TestSource_GUID : global::TUnit.
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 3,
LineNumber = 11,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2),
Expand Down Expand Up @@ -329,7 +329,7 @@ internal sealed class ConcreteClass1_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ internal sealed class InheritedPropertySetterTests_Test_TestSource_GUID : global
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 3,
LineNumber = 69,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.PropertySetterTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ internal sealed class InheritedTestsFromDifferentProjectTests_BaseTest_TestSourc
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 5,
LineNumber = 6,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.BaseTests),
Expand Down Expand Up @@ -598,7 +598,7 @@ internal sealed class InheritedTestsFromDifferentProjectTests_BaseTestWithMultip
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 5,
LineNumber = 12,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.BaseTests),
Expand Down Expand Up @@ -698,7 +698,7 @@ internal sealed class InheritedTestsFromDifferentProjectTests_Test_TestSource_GU
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 5,
LineNumber = 9,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests),
Expand Down Expand Up @@ -800,7 +800,7 @@ internal sealed class InheritedTestsFromDifferentProjectTests_GenericMethodDataS
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 5,
LineNumber = 14,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests),
Expand Down Expand Up @@ -936,7 +936,7 @@ internal sealed class InheritedTestsFromDifferentProjectTests_NonGenericMethodDa
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 5,
LineNumber = 20,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests),
Expand Down Expand Up @@ -1059,7 +1059,7 @@ internal sealed class InheritedTestsFromDifferentProjectTests_VerifyInheritedCat
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 5,
LineNumber = 26,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ internal sealed class ConcreteClass2_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 2,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down Expand Up @@ -231,7 +231,7 @@ internal sealed class ConcreteClass2_SecondTest_TestSource_GUID : global::TUnit.
},
InheritanceDepth = 0,
FilePath = @"",
LineNumber = 3,
LineNumber = 11,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2),
Expand Down Expand Up @@ -329,7 +329,7 @@ internal sealed class ConcreteClass1_AssertClassName_TestSource_GUID : global::T
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 3,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.AbstractTests.AbstractBaseClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ internal sealed class Tests_Test_TestSource_GUID : global::TUnit.Core.Interfaces
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 23,
LineNumber = 11,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass),
Expand Down Expand Up @@ -398,7 +398,7 @@ internal sealed class Tests2_Test_TestSource_GUID : global::TUnit.Core.Interface
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 26,
LineNumber = 11,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass),
Expand Down Expand Up @@ -556,7 +556,7 @@ internal sealed class Tests3_Test_TestSource_GUID : global::TUnit.Core.Interface
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 29,
LineNumber = 11,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class DerivedTest_Test1_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down Expand Up @@ -136,7 +136,7 @@ internal sealed class DerivedTest_Test2_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 10,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down Expand Up @@ -262,7 +262,7 @@ internal sealed class DerivedTest_Test3_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 16,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class DerivedTest_Test1_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down Expand Up @@ -136,7 +136,7 @@ internal sealed class DerivedTest_Test2_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 10,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down Expand Up @@ -262,7 +262,7 @@ internal sealed class DerivedTest_Test3_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 16,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class DerivedTest_Test1_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 5,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down Expand Up @@ -136,7 +136,7 @@ internal sealed class DerivedTest_Test2_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 10,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down Expand Up @@ -262,7 +262,7 @@ internal sealed class DerivedTest_Test3_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 16,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest<DummyReferenceTypeClass>),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ internal sealed class DerivedTest_Test1_TestSource_GUID : global::TUnit.Core.Int
},
InheritanceDepth = 1,
FilePath = @"",
LineNumber = 6,
LineNumber = 13,
MethodMetadata = new global::TUnit.Core.MethodMetadata
{
Type = typeof(global::TUnit.TestProject.Library.Bugs._1899.BaseClass<DummyReferenceTypeClass>),
Expand Down
11 changes: 9 additions & 2 deletions TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,19 @@
// Calculate inheritance depth for this test
int inheritanceDepth = CalculateInheritanceDepth(classInfo.TypeSymbol, method);

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;

var testMethodMetadata = new TestMethodMetadata
{
MethodSymbol = concreteMethod ?? method, // Use concrete method if found, otherwise base method
TypeSymbol = classInfo.TypeSymbol,
FilePath = classInfo.ClassSyntax.GetLocation().SourceTree?.FilePath ?? testAttribute.ConstructorArguments.ElementAtOrDefault(0).Value?.ToString() ?? classInfo.ClassSyntax.SyntaxTree.FilePath,
LineNumber = classInfo.ClassSyntax.GetLocation().GetLineSpan().StartLinePosition.Line + 1,
FilePath = filePath,
LineNumber = lineNumber,
TestAttribute = testAttribute,
Context = null, // No context for inherited tests
MethodSyntax = null, // No syntax for inherited methods
Expand Down Expand Up @@ -721,7 +728,7 @@
}

// Find the data source method
var dataSourceMethod = targetType.GetMembers(methodName)

Check warning on line 731 in TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Possible null reference argument for parameter 'name' in 'ImmutableArray<ISymbol> INamespaceOrTypeSymbol.GetMembers(string name)'.

Check warning on line 731 in TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Possible null reference argument for parameter 'name' in 'ImmutableArray<ISymbol> INamespaceOrTypeSymbol.GetMembers(string name)'.

Check warning on line 731 in TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (windows-latest)

Possible null reference argument for parameter 'name' in 'ImmutableArray<ISymbol> INamespaceOrTypeSymbol.GetMembers(string name)'.

Check warning on line 731 in TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (ubuntu-latest)

Possible null reference argument for parameter 'name' in 'ImmutableArray<ISymbol> INamespaceOrTypeSymbol.GetMembers(string name)'.

Check warning on line 731 in TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (ubuntu-latest)

Possible null reference argument for parameter 'name' in 'ImmutableArray<ISymbol> INamespaceOrTypeSymbol.GetMembers(string name)'.

Check warning on line 731 in TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs

View workflow job for this annotation

GitHub Actions / modularpipeline (macos-latest)

Possible null reference argument for parameter 'name' in 'ImmutableArray<ISymbol> INamespaceOrTypeSymbol.GetMembers(string name)'.
.OfType<IMethodSymbol>()
.FirstOrDefault();

Expand Down
20 changes: 20 additions & 0 deletions TUnit.TestProject/Bugs/SourceLocationRepro.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace TUnit.TestProject.Bugs;

public abstract class BaseTestForSourceLocationCheck
{
[Test]
public async Task BaseTestMethod()
{
await Assert.That(Environment.ProcessorCount).IsGreaterThan(0);
}
}

[InheritsTests]
public sealed class DerivedTestForSourceLocationCheck : BaseTestForSourceLocationCheck
{
[Test]
public async Task DerivedTestMethod()
{
await Assert.That(Environment.ProcessorCount).IsGreaterThan(0);
}
}
Loading