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
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -50,7 +50,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -144,7 +144,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down Expand Up @@ -219,7 +219,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
24 changes: 20 additions & 4 deletions TUnit.Core.SourceGenerator.Tests/BasicTests.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using TUnit.Core.SourceGenerator.Tests.Options;

namespace TUnit.Core.SourceGenerator.Tests;

internal class BasicTests : TestsBase
{
private static readonly string InputFile = Path.Combine(Git.RootDirectory.FullName, "TUnit.TestProject", "BasicTests.cs");

[Test]
public Task Test() => RunTest(Path.Combine(Git.RootDirectory.FullName,
"TUnit.TestProject",
"BasicTests.cs"),
public Task Test() => RunTest(InputFile,
new RunTestOptions
{
VerifyConfigurator = verify => verify.UniqueForTargetFrameworkAndVersion()
},
async generatedFiles =>
{
});
var source = await File.ReadAllTextAsync(InputFile);
var syntaxTree = CSharpSyntaxTree.ParseText(source);
var firstMethod = syntaxTree.GetRoot()
.DescendantNodes()
.OfType<MethodDeclarationSyntax>()
.First(x => x.Identifier.ValueText == "SynchronousTest");

var lineSpan = firstMethod.GetLocation().GetLineSpan();
var generatedCode = string.Join(Environment.NewLine, generatedFiles);

await Assert.That(generatedCode).Contains($"LineNumber = {lineSpan.StartLinePosition.Line + 1},");
await Assert.That(generatedCode).Contains($"StartColumnNumber = {lineSpan.StartLinePosition.Character + 1},");
await Assert.That(generatedCode).Contains($"EndLineNumber = {lineSpan.EndLinePosition.Line + 1},");
await Assert.That(generatedCode).Contains($"EndColumnNumber = {lineSpan.EndLinePosition.Character + 1},");
});
}
8 changes: 6 additions & 2 deletions TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ public Task Test() => RunTest(Path.Combine(Git.RootDirectory.FullName,
{
// Scrub GUIDs from generated files before verification (same as TestsBase)
var scrubbedFiles = generatedFiles.Select(file => ScrubGuids(file)).ToArray();
await Verify(scrubbedFiles).UniqueForTargetFrameworkAndVersion();
await Verify(scrubbedFiles)
.ScrubLinesContaining("StartColumnNumber = ")
.ScrubLinesContaining("EndLineNumber = ")
.ScrubLinesContaining("EndColumnNumber = ")
.UniqueForTargetFrameworkAndVersion();
});

private string ScrubGuids(string text)
Expand All @@ -50,4 +54,4 @@ private string ScrubGuids(string text)

return scrubbedText;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -144,7 +144,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down Expand Up @@ -219,7 +219,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -266,7 +266,7 @@ internal static class TUnit_TestProject_InheritedPropertySetterTests_Test_TestSo
MethodName = "Test",
FullyQualifiedName = "TUnit.TestProject.InheritedPropertySetterTests.Test",
FilePath = @"",
LineNumber = 3,
LineNumber = 70,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -292,7 +292,7 @@ internal static class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_
MethodName = "BaseTest",
FullyQualifiedName = "TUnit.TestProject.InheritedTestsFromDifferentProjectTests.BaseTest",
FilePath = @"",
LineNumber = 5,
LineNumber = 8,
Categories = new string[] { "BaseCategory" },
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down Expand Up @@ -372,7 +372,7 @@ internal static class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_
MethodName = "BaseTestWithMultipleCategories",
FullyQualifiedName = "TUnit.TestProject.InheritedTestsFromDifferentProjectTests.BaseTestWithMultipleCategories",
FilePath = @"",
LineNumber = 5,
LineNumber = 15,
Categories = new string[] { "AnotherBaseCategory", "MultipleCategories" },
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -144,7 +144,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down Expand Up @@ -219,7 +219,7 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass
MethodName = "AssertClassName",
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
FilePath = @"",
LineNumber = 3,
LineNumber = 6,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -198,7 +198,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo
MethodName = "Test",
FullyQualifiedName = "TUnit.TestProject.Bugs._1924.None.Tests.Test",
FilePath = @"",
LineNumber = 23,
LineNumber = 16,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down Expand Up @@ -298,7 +298,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo
MethodName = "Test",
FullyQualifiedName = "TUnit.TestProject.Bugs._1924.None.Tests2.Test",
FilePath = @"",
LineNumber = 26,
LineNumber = 16,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down Expand Up @@ -398,7 +398,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo
MethodName = "Test",
FullyQualifiedName = "TUnit.TestProject.Bugs._1924.None.Tests3.Test",
FilePath = @"",
LineNumber = 29,
LineNumber = 16,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test2",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test2",
FilePath = @"",
LineNumber = 6,
LineNumber = 12,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down Expand Up @@ -235,7 +235,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test3",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test3",
FilePath = @"",
LineNumber = 6,
LineNumber = 19,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test2",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test2",
FilePath = @"",
LineNumber = 6,
LineNumber = 12,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down Expand Up @@ -235,7 +235,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test3",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test3",
FilePath = @"",
LineNumber = 6,
LineNumber = 19,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test2",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test2",
FilePath = @"",
LineNumber = 6,
LineNumber = 12,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down Expand Up @@ -235,7 +235,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test3",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test3",
FilePath = @"",
LineNumber = 6,
LineNumber = 19,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test2",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test2",
FilePath = @"",
LineNumber = 6,
LineNumber = 12,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down Expand Up @@ -235,7 +235,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne
MethodName = "Test3",
FullyQualifiedName = "TUnit.TestProject.Bugs._1889.DerivedTest.Test3",
FilePath = @"",
LineNumber = 6,
LineNumber = 19,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = true,
Expand Down
4 changes: 2 additions & 2 deletions TUnit.Core.SourceGenerator.Tests/Tests1899.Test.verified.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <auto-generated/>
// <auto-generated/>
#pragma warning disable

#nullable enable
Expand Down Expand Up @@ -52,7 +52,7 @@ internal static class TUnit_TestProject_Bugs__1899_DerivedTest_Test1_TestSource
MethodName = "Test1",
FullyQualifiedName = "TUnit.TestProject.Bugs._1899.DerivedTest.Test1",
FilePath = @"",
LineNumber = 6,
LineNumber = 14,
Categories = global::System.Array.Empty<string>(),
Properties = global::System.Array.Empty<string>(),
HasDataSource = false,
Expand Down
5 changes: 4 additions & 1 deletion TUnit.Core.SourceGenerator.Tests/TestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,10 @@ Have you added required references and additional files?
// Scrub GUIDs from generated files before verification
var scrubbedFiles = generatedFiles.Select(file => Scrub(file)).ToArray();
var verifyTask = Verify(scrubbedFiles)
.ScrubFilePaths();
.ScrubFilePaths()
.ScrubLinesContaining("StartColumnNumber = ")
.ScrubLinesContaining("EndLineNumber = ")
.ScrubLinesContaining("EndColumnNumber = ");

if (runTestOptions.VerifyConfigurator != null)
{
Expand Down
Loading
Loading