Skip to content

Commit 7a2961d

Browse files
authored
+semver:minor - perf: shrink generated TestEntry builder IL via shared TUnit.Core factory helpers (#6231)
* perf: shrink generated TestEntry builder IL via shared TUnit.Core factory helpers Discovery-time tier-0 JIT cost scales with the IL size of the generated per-class Entries builders. Two emit-shape changes move the repeated construction patterns into TUnit.Core so they are JIT-compiled once instead of per call site: - DataSourceFactories: each [MethodDataSource] previously inlined a full compiler-generated async-iterator state machine differing only in one invocation expression. Generated code now passes that invocation as a static lambda to a shared helper selected by the member's declared return type (value/enumerable/Task/ValueTask/IAsyncEnumerable, with static and instance variants preserving the exact branch semantics and TestClassInstance error message). - TestEntryFactory.Create<T>: TestEntry construction is now a single factory call with named arguments instead of a ~17-property object initializer; default-valued arguments (empty arrays, zero columns, repeatCount 0) are omitted entirely. Snapshots re-verified across all TFMs; PublicAPI snapshots updated for the two new public types. Snapshot scrubbing extended to the new named-argument source-location lines, which are also omitted when zero. Closes #6227 * refactor: address review nits on TestEntry factory helpers - Scope CS1998 suppression to the four sync-only async iterators in DataSourceFactories instead of file-wide, so a genuine missing await in future helpers still surfaces. - Split IsTask/IsValueTask in TestMetadataGenerator's data-source factory dispatch so kind selection reads as a flat decision tree. Behavior and generated output are identical (snapshots unchanged).
1 parent baef6f3 commit 7a2961d

136 files changed

Lines changed: 6972 additions & 11297 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete1.verified.txt

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,17 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass
4545
}
4646
public static readonly global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass1>[] Entries_0 = new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass1>[]
4747
{
48-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass1>
49-
{
50-
MethodName = "AssertClassName",
51-
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
52-
FilePath = "",
53-
LineNumber = 6,
54-
Categories = global::System.Array.Empty<string>(),
55-
Properties = global::System.Array.Empty<string>(),
56-
HasDataSource = false,
57-
RepeatCount = 0,
58-
DependsOn = global::System.Array.Empty<string>(),
59-
MethodMetadata = __mm_0,
60-
CreateInstance = __CreateInstance_0,
61-
InvokeBody = __Invoke_0,
62-
MethodIndex = 0,
63-
CreateAttributes = __Attributes_0,
64-
AttributeGroupIndex = 0,
65-
},
48+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AbstractTests.ConcreteClass1>(
49+
methodName: "AssertClassName",
50+
fullyQualifiedName: "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
51+
filePath: "",
52+
lineNumber: 6,
53+
methodMetadata: __mm_0,
54+
createInstance: __CreateInstance_0,
55+
invokeBody: __Invoke_0,
56+
methodIndex: 0,
57+
createAttributes: __Attributes_0,
58+
attributeGroupIndex: 0),
6659
};
6760
}
6861
internal static partial class TUnit_TestRegistration

TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete2.verified.txt

Lines changed: 33 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,17 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass2__TestSource
6363
}
6464
public static readonly global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass2>[] Entries = new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass2>[]
6565
{
66-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass2>
67-
{
68-
MethodName = "SecondTest",
69-
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass2.SecondTest",
70-
FilePath = "",
71-
LineNumber = 11,
72-
Categories = global::System.Array.Empty<string>(),
73-
Properties = global::System.Array.Empty<string>(),
74-
HasDataSource = false,
75-
RepeatCount = 0,
76-
DependsOn = global::System.Array.Empty<string>(),
77-
MethodMetadata = __mm_0,
78-
CreateInstance = __CreateInstance,
79-
InvokeBody = __Invoke,
80-
MethodIndex = 0,
81-
CreateAttributes = __Attributes,
82-
AttributeGroupIndex = 0,
83-
},
66+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AbstractTests.ConcreteClass2>(
67+
methodName: "SecondTest",
68+
fullyQualifiedName: "TUnit.TestProject.AbstractTests.ConcreteClass2.SecondTest",
69+
filePath: "",
70+
lineNumber: 11,
71+
methodMetadata: __mm_0,
72+
createInstance: __CreateInstance,
73+
invokeBody: __Invoke,
74+
methodIndex: 0,
75+
createAttributes: __Attributes,
76+
attributeGroupIndex: 0),
8477
};
8578
}
8679
internal static partial class TUnit_TestRegistration
@@ -139,24 +132,17 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass
139132
}
140133
public static readonly global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass2>[] Entries_0 = new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass2>[]
141134
{
142-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass2>
143-
{
144-
MethodName = "AssertClassName",
145-
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName",
146-
FilePath = "",
147-
LineNumber = 6,
148-
Categories = global::System.Array.Empty<string>(),
149-
Properties = global::System.Array.Empty<string>(),
150-
HasDataSource = false,
151-
RepeatCount = 0,
152-
DependsOn = global::System.Array.Empty<string>(),
153-
MethodMetadata = __mm_0,
154-
CreateInstance = __CreateInstance_0,
155-
InvokeBody = __Invoke_0,
156-
MethodIndex = 0,
157-
CreateAttributes = __Attributes_0,
158-
AttributeGroupIndex = 0,
159-
},
135+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AbstractTests.ConcreteClass2>(
136+
methodName: "AssertClassName",
137+
fullyQualifiedName: "TUnit.TestProject.AbstractTests.ConcreteClass2.AssertClassName",
138+
filePath: "",
139+
lineNumber: 6,
140+
methodMetadata: __mm_0,
141+
createInstance: __CreateInstance_0,
142+
invokeBody: __Invoke_0,
143+
methodIndex: 0,
144+
createAttributes: __Attributes_0,
145+
attributeGroupIndex: 0),
160146
};
161147
}
162148
internal static partial class TUnit_TestRegistration
@@ -214,24 +200,17 @@ internal static class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass
214200
}
215201
public static readonly global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass1>[] Entries_0 = new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass1>[]
216202
{
217-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AbstractTests.ConcreteClass1>
218-
{
219-
MethodName = "AssertClassName",
220-
FullyQualifiedName = "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
221-
FilePath = "",
222-
LineNumber = 6,
223-
Categories = global::System.Array.Empty<string>(),
224-
Properties = global::System.Array.Empty<string>(),
225-
HasDataSource = false,
226-
RepeatCount = 0,
227-
DependsOn = global::System.Array.Empty<string>(),
228-
MethodMetadata = __mm_0,
229-
CreateInstance = __CreateInstance_0,
230-
InvokeBody = __Invoke_0,
231-
MethodIndex = 0,
232-
CreateAttributes = __Attributes_0,
233-
AttributeGroupIndex = 0,
234-
},
203+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AbstractTests.ConcreteClass1>(
204+
methodName: "AssertClassName",
205+
fullyQualifiedName: "TUnit.TestProject.AbstractTests.ConcreteClass1.AssertClassName",
206+
filePath: "",
207+
lineNumber: 6,
208+
methodMetadata: __mm_0,
209+
createInstance: __CreateInstance_0,
210+
invokeBody: __Invoke_0,
211+
methodIndex: 0,
212+
createAttributes: __Attributes_0,
213+
attributeGroupIndex: 0),
235214
};
236215
}
237216
internal static partial class TUnit_TestRegistration

TUnit.Core.SourceGenerator.Tests/AfterAllTests.Test.verified.txt

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,28 @@ internal static class TUnit_TestProject_AfterTests_CleanupTests__TestSource
7272
}
7373
public static readonly global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>[] Entries = new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>[]
7474
{
75-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>
76-
{
77-
MethodName = "Test1",
78-
FullyQualifiedName = "TUnit.TestProject.AfterTests.CleanupTests.Test1",
79-
FilePath = "",
80-
LineNumber = 98,
81-
Categories = global::System.Array.Empty<string>(),
82-
Properties = global::System.Array.Empty<string>(),
83-
HasDataSource = false,
84-
RepeatCount = 0,
85-
DependsOn = global::System.Array.Empty<string>(),
86-
MethodMetadata = __mm_0,
87-
CreateInstance = __CreateInstance,
88-
InvokeBody = __Invoke,
89-
MethodIndex = 0,
90-
CreateAttributes = __Attributes,
91-
AttributeGroupIndex = 0,
92-
},
93-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>
94-
{
95-
MethodName = "Test2",
96-
FullyQualifiedName = "TUnit.TestProject.AfterTests.CleanupTests.Test2",
97-
FilePath = "",
98-
LineNumber = 104,
99-
Categories = global::System.Array.Empty<string>(),
100-
Properties = global::System.Array.Empty<string>(),
101-
HasDataSource = false,
102-
RepeatCount = 0,
103-
DependsOn = global::System.Array.Empty<string>(),
104-
MethodMetadata = __mm_1,
105-
CreateInstance = __CreateInstance,
106-
InvokeBody = __Invoke,
107-
MethodIndex = 1,
108-
CreateAttributes = __Attributes,
109-
AttributeGroupIndex = 0,
110-
},
75+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AfterTests.CleanupTests>(
76+
methodName: "Test1",
77+
fullyQualifiedName: "TUnit.TestProject.AfterTests.CleanupTests.Test1",
78+
filePath: "",
79+
lineNumber: 98,
80+
methodMetadata: __mm_0,
81+
createInstance: __CreateInstance,
82+
invokeBody: __Invoke,
83+
methodIndex: 0,
84+
createAttributes: __Attributes,
85+
attributeGroupIndex: 0),
86+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AfterTests.CleanupTests>(
87+
methodName: "Test2",
88+
fullyQualifiedName: "TUnit.TestProject.AfterTests.CleanupTests.Test2",
89+
filePath: "",
90+
lineNumber: 104,
91+
methodMetadata: __mm_1,
92+
createInstance: __CreateInstance,
93+
invokeBody: __Invoke,
94+
methodIndex: 1,
95+
createAttributes: __Attributes,
96+
attributeGroupIndex: 0),
11197
};
11298
}
11399
internal static partial class TUnit_TestRegistration

TUnit.Core.SourceGenerator.Tests/AfterTests.Test.verified.txt

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,28 @@ internal static class TUnit_TestProject_AfterTests_CleanupTests__TestSource
7272
}
7373
public static readonly global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>[] Entries = new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>[]
7474
{
75-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>
76-
{
77-
MethodName = "Test1",
78-
FullyQualifiedName = "TUnit.TestProject.AfterTests.CleanupTests.Test1",
79-
FilePath = "",
80-
LineNumber = 98,
81-
Categories = global::System.Array.Empty<string>(),
82-
Properties = global::System.Array.Empty<string>(),
83-
HasDataSource = false,
84-
RepeatCount = 0,
85-
DependsOn = global::System.Array.Empty<string>(),
86-
MethodMetadata = __mm_0,
87-
CreateInstance = __CreateInstance,
88-
InvokeBody = __Invoke,
89-
MethodIndex = 0,
90-
CreateAttributes = __Attributes,
91-
AttributeGroupIndex = 0,
92-
},
93-
new global::TUnit.Core.TestEntry<global::TUnit.TestProject.AfterTests.CleanupTests>
94-
{
95-
MethodName = "Test2",
96-
FullyQualifiedName = "TUnit.TestProject.AfterTests.CleanupTests.Test2",
97-
FilePath = "",
98-
LineNumber = 104,
99-
Categories = global::System.Array.Empty<string>(),
100-
Properties = global::System.Array.Empty<string>(),
101-
HasDataSource = false,
102-
RepeatCount = 0,
103-
DependsOn = global::System.Array.Empty<string>(),
104-
MethodMetadata = __mm_1,
105-
CreateInstance = __CreateInstance,
106-
InvokeBody = __Invoke,
107-
MethodIndex = 1,
108-
CreateAttributes = __Attributes,
109-
AttributeGroupIndex = 0,
110-
},
75+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AfterTests.CleanupTests>(
76+
methodName: "Test1",
77+
fullyQualifiedName: "TUnit.TestProject.AfterTests.CleanupTests.Test1",
78+
filePath: "",
79+
lineNumber: 98,
80+
methodMetadata: __mm_0,
81+
createInstance: __CreateInstance,
82+
invokeBody: __Invoke,
83+
methodIndex: 0,
84+
createAttributes: __Attributes,
85+
attributeGroupIndex: 0),
86+
global::TUnit.Core.TestEntryFactory.Create<global::TUnit.TestProject.AfterTests.CleanupTests>(
87+
methodName: "Test2",
88+
fullyQualifiedName: "TUnit.TestProject.AfterTests.CleanupTests.Test2",
89+
filePath: "",
90+
lineNumber: 104,
91+
methodMetadata: __mm_1,
92+
createInstance: __CreateInstance,
93+
invokeBody: __Invoke,
94+
methodIndex: 1,
95+
createAttributes: __Attributes,
96+
attributeGroupIndex: 0),
11197
};
11298
}
11399
internal static partial class TUnit_TestRegistration

0 commit comments

Comments
 (0)