Skip to content

Commit

Permalink
manually construct attributes (#1451)
Browse files Browse the repository at this point in the history
* WIP

* Fixes

* Fixes

* Tidy

* Tidy

* Switch to Verify

* Commit verified code

* Tidy .csprojs
  • Loading branch information
thomhurst authored Dec 24, 2024
1 parent e85f79e commit f3af70c
Show file tree
Hide file tree
Showing 104 changed files with 29,056 additions and 1,375 deletions.
1 change: 1 addition & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<PackageVersion Include="TUnit" Version="0.5.28" />
<PackageVersion Include="TUnit.Core" Version="0.5.28" />
<PackageVersion Include="TUnit.Assertions" Version="0.5.28" />
<PackageVersion Include="Verify.TUnit" Version="28.7.0" />
<PackageVersion Include="Vogen" Version="5.0.6" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
Expand Down
3 changes: 0 additions & 3 deletions TUnit.Assertions.Analyzers/TUnit.Assertions.Analyzers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,4 @@
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Remove="compiler-diagnostics.sarif" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[
// <auto-generated/>
#pragma warning disable
using global::System.Linq;
using global::System.Reflection;
using global::TUnit.Core;
using global::TUnit.Core.Extensions;

namespace TUnit.SourceGenerated;

[global::System.Diagnostics.StackTraceHidden]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class Inherited_ConcreteClass1 : TUnit.Core.Interfaces.SourceGenerator.ITestSource
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialise()
{
SourceRegistrar.Register(new Inherited_ConcreteClass1());
}
public global::System.Collections.Generic.IReadOnlyList<SourceGeneratedTestNode> CollectTests(string sessionId)
{
return Tests0(sessionId);
}
private global::System.Collections.Generic.List<SourceGeneratedTestNode> Tests0(string sessionId)
{
global::System.Collections.Generic.List<SourceGeneratedTestNode> nodes = [];
var classDataIndex = 0;
var testMethodDataIndex = 0;
try
{
var testClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1);
var methodInfo = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1).GetMethod("AssertClassName", 0, []);

var testBuilderContext = new global::TUnit.Core.TestBuilderContext();
var testBuilderContextAccessor = new global::TUnit.Core.TestBuilderContextAccessor(testBuilderContext);

var resettableClassFactoryDelegate = () => new ResettableLazy<global::TUnit.TestProject.AbstractTests.ConcreteClass1>(() =>
new global::TUnit.TestProject.AbstractTests.ConcreteClass1()
, sessionId, testBuilderContext);

var resettableClassFactory = resettableClassFactoryDelegate();

nodes.Add(new TestMetadata<global::TUnit.TestProject.AbstractTests.ConcreteClass1>
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName:0",
TestClassArguments = [],
TestMethodArguments = [],
TestClassProperties = [],
CurrentRepeatAttempt = 0,
RepeatLimit = 0,
MethodInfo = methodInfo,
ResettableClassFactory = resettableClassFactory,
TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.AssertClassName()),
TestFilePath = @"",
TestLineNumber = 8,
TestAttributes = [ new global::TUnit.Core.TestAttribute()
{

} ],
ClassAttributes = [ new global::TUnit.Core.InheritsTestsAttribute()
{

} ],
AssemblyAttributes = [ ],
DataAttributes = [ ],
TestBuilderContext = testBuilderContext,
});
resettableClassFactory = resettableClassFactoryDelegate();
testBuilderContext = new();
testBuilderContextAccessor.Current = testBuilderContext;
}
catch (global::System.Exception exception)
{
nodes.Add(new FailedInitializationTest
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName:0",
TestClass = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1),
ReturnType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1).GetMethod("AssertClassName", 0, []).ReturnType,
ParameterTypeFullNames = [],
TestName = "AssertClassName",
TestFilePath = @"",
TestLineNumber = 8,
Exception = exception,
});
}
return nodes;
}
}

]
274 changes: 274 additions & 0 deletions TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete2.verified.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,274 @@
[
// <auto-generated/>
#pragma warning disable
using global::System.Linq;
using global::System.Reflection;
using global::TUnit.Core;
using global::TUnit.Core.Extensions;

namespace TUnit.SourceGenerated;

[global::System.Diagnostics.StackTraceHidden]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class ConcreteClass2 : TUnit.Core.Interfaces.SourceGenerator.ITestSource
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialise()
{
SourceRegistrar.Register(new ConcreteClass2());
}
public global::System.Collections.Generic.IReadOnlyList<SourceGeneratedTestNode> CollectTests(string sessionId)
{
return Tests0(sessionId);
}
private global::System.Collections.Generic.List<SourceGeneratedTestNode> Tests0(string sessionId)
{
global::System.Collections.Generic.List<SourceGeneratedTestNode> nodes = [];
var classDataIndex = 0;
var testMethodDataIndex = 0;
try
{
var testClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2);
var methodInfo = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2).GetMethod("SecondTest", 0, []);

var testBuilderContext = new global::TUnit.Core.TestBuilderContext();
var testBuilderContextAccessor = new global::TUnit.Core.TestBuilderContextAccessor(testBuilderContext);

var resettableClassFactoryDelegate = () => new ResettableLazy<global::TUnit.TestProject.AbstractTests.ConcreteClass2>(() =>
new global::TUnit.TestProject.AbstractTests.ConcreteClass2()
, sessionId, testBuilderContext);

var resettableClassFactory = resettableClassFactoryDelegate();

nodes.Add(new TestMetadata<global::TUnit.TestProject.AbstractTests.ConcreteClass2>
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass2.SecondTest:0",
TestClassArguments = [],
TestMethodArguments = [],
TestClassProperties = [],
CurrentRepeatAttempt = 0,
RepeatLimit = 0,
MethodInfo = methodInfo,
ResettableClassFactory = resettableClassFactory,
TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.SecondTest()),
TestFilePath = @"",
TestLineNumber = 11,
TestAttributes = [ new global::TUnit.Core.TestAttribute()
{

} ],
ClassAttributes = [ new global::TUnit.Core.InheritsTestsAttribute()
{

}, new global::TUnit.Core.InheritsTestsAttribute()
{

} ],
AssemblyAttributes = [ ],
DataAttributes = [ ],
TestBuilderContext = testBuilderContext,
});
resettableClassFactory = resettableClassFactoryDelegate();
testBuilderContext = new();
testBuilderContextAccessor.Current = testBuilderContext;
}
catch (global::System.Exception exception)
{
nodes.Add(new FailedInitializationTest
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass2.SecondTest:0",
TestClass = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2),
ReturnType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2).GetMethod("SecondTest", 0, []).ReturnType,
ParameterTypeFullNames = [],
TestName = "SecondTest",
TestFilePath = @"",
TestLineNumber = 11,
Exception = exception,
});
}
return nodes;
}
}


// <auto-generated/>
#pragma warning disable
using global::System.Linq;
using global::System.Reflection;
using global::TUnit.Core;
using global::TUnit.Core.Extensions;

namespace TUnit.SourceGenerated;

[global::System.Diagnostics.StackTraceHidden]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class Inherited_ConcreteClass2 : TUnit.Core.Interfaces.SourceGenerator.ITestSource
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialise()
{
SourceRegistrar.Register(new Inherited_ConcreteClass2());
}
public global::System.Collections.Generic.IReadOnlyList<SourceGeneratedTestNode> CollectTests(string sessionId)
{
return Tests0(sessionId);
}
private global::System.Collections.Generic.List<SourceGeneratedTestNode> Tests0(string sessionId)
{
global::System.Collections.Generic.List<SourceGeneratedTestNode> nodes = [];
var classDataIndex = 0;
var testMethodDataIndex = 0;
try
{
var testClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2);
var methodInfo = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2).GetMethod("AssertClassName", 0, []);

var testBuilderContext = new global::TUnit.Core.TestBuilderContext();
var testBuilderContextAccessor = new global::TUnit.Core.TestBuilderContextAccessor(testBuilderContext);

var resettableClassFactoryDelegate = () => new ResettableLazy<global::TUnit.TestProject.AbstractTests.ConcreteClass2>(() =>
new global::TUnit.TestProject.AbstractTests.ConcreteClass2()
, sessionId, testBuilderContext);

var resettableClassFactory = resettableClassFactoryDelegate();

nodes.Add(new TestMetadata<global::TUnit.TestProject.AbstractTests.ConcreteClass2>
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName:0",
TestClassArguments = [],
TestMethodArguments = [],
TestClassProperties = [],
CurrentRepeatAttempt = 0,
RepeatLimit = 0,
MethodInfo = methodInfo,
ResettableClassFactory = resettableClassFactory,
TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.AssertClassName()),
TestFilePath = @"",
TestLineNumber = 8,
TestAttributes = [ new global::TUnit.Core.TestAttribute()
{

} ],
ClassAttributes = [ new global::TUnit.Core.InheritsTestsAttribute()
{

}, new global::TUnit.Core.InheritsTestsAttribute()
{

} ],
AssemblyAttributes = [ ],
DataAttributes = [ ],
TestBuilderContext = testBuilderContext,
});
resettableClassFactory = resettableClassFactoryDelegate();
testBuilderContext = new();
testBuilderContextAccessor.Current = testBuilderContext;
}
catch (global::System.Exception exception)
{
nodes.Add(new FailedInitializationTest
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName:0",
TestClass = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2),
ReturnType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2).GetMethod("AssertClassName", 0, []).ReturnType,
ParameterTypeFullNames = [],
TestName = "AssertClassName",
TestFilePath = @"",
TestLineNumber = 8,
Exception = exception,
});
}
return nodes;
}
}


// <auto-generated/>
#pragma warning disable
using global::System.Linq;
using global::System.Reflection;
using global::TUnit.Core;
using global::TUnit.Core.Extensions;

namespace TUnit.SourceGenerated;

[global::System.Diagnostics.StackTraceHidden]
[global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
file partial class Inherited_ConcreteClass1 : TUnit.Core.Interfaces.SourceGenerator.ITestSource
{
[global::System.Runtime.CompilerServices.ModuleInitializer]
public static void Initialise()
{
SourceRegistrar.Register(new Inherited_ConcreteClass1());
}
public global::System.Collections.Generic.IReadOnlyList<SourceGeneratedTestNode> CollectTests(string sessionId)
{
return Tests0(sessionId);
}
private global::System.Collections.Generic.List<SourceGeneratedTestNode> Tests0(string sessionId)
{
global::System.Collections.Generic.List<SourceGeneratedTestNode> nodes = [];
var classDataIndex = 0;
var testMethodDataIndex = 0;
try
{
var testClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1);
var methodInfo = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1).GetMethod("AssertClassName", 0, []);

var testBuilderContext = new global::TUnit.Core.TestBuilderContext();
var testBuilderContextAccessor = new global::TUnit.Core.TestBuilderContextAccessor(testBuilderContext);

var resettableClassFactoryDelegate = () => new ResettableLazy<global::TUnit.TestProject.AbstractTests.ConcreteClass1>(() =>
new global::TUnit.TestProject.AbstractTests.ConcreteClass1()
, sessionId, testBuilderContext);

var resettableClassFactory = resettableClassFactoryDelegate();

nodes.Add(new TestMetadata<global::TUnit.TestProject.AbstractTests.ConcreteClass1>
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName:0",
TestClassArguments = [],
TestMethodArguments = [],
TestClassProperties = [],
CurrentRepeatAttempt = 0,
RepeatLimit = 0,
MethodInfo = methodInfo,
ResettableClassFactory = resettableClassFactory,
TestMethodFactory = (classInstance, cancellationToken) => AsyncConvert.Convert(() => classInstance.AssertClassName()),
TestFilePath = @"",
TestLineNumber = 8,
TestAttributes = [ new global::TUnit.Core.TestAttribute()
{

} ],
ClassAttributes = [ new global::TUnit.Core.InheritsTestsAttribute()
{

} ],
AssemblyAttributes = [ ],
DataAttributes = [ ],
TestBuilderContext = testBuilderContext,
});
resettableClassFactory = resettableClassFactoryDelegate();
testBuilderContext = new();
testBuilderContextAccessor.Current = testBuilderContext;
}
catch (global::System.Exception exception)
{
nodes.Add(new FailedInitializationTest
{
TestId = $"TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName:0",
TestClass = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1),
ReturnType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1).GetMethod("AssertClassName", 0, []).ReturnType,
ParameterTypeFullNames = [],
TestName = "AssertClassName",
TestFilePath = @"",
TestLineNumber = 8,
Exception = exception,
});
}
return nodes;
}
}

]
Loading

0 comments on commit f3af70c

Please sign in to comment.