Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
b7376e1
Refactor Engine tests for a speeder pipeline
thomhurst Jun 1, 2025
123c9a4
Whoops
thomhurst Jun 1, 2025
67259ad
Update snaps
thomhurst Jun 1, 2025
77c9758
Print command
thomhurst Jun 1, 2025
85e4958
Fix
thomhurst Jun 1, 2025
e30004f
Fix
thomhurst Jun 1, 2025
294e843
WIP
thomhurst Jun 1, 2025
2c508be
Merge branch 'main' into feature/refactor-engine-tests
thomhurst Jun 2, 2025
8912536
Refactor Context objects
thomhurst Jun 2, 2025
f93f9e7
WIP
thomhurst Jun 2, 2025
40cdde8
WIP
thomhurst Jun 2, 2025
2ff72b0
WIP
thomhurst Jun 2, 2025
7258a0e
WIP
thomhurst Jun 2, 2025
1789357
Fixes
thomhurst Jun 2, 2025
9bf7157
Fixes
thomhurst Jun 2, 2025
b834e87
Fix
thomhurst Jun 2, 2025
a8d2b82
Fix
thomhurst Jun 2, 2025
a38c903
Fixes
thomhurst Jun 2, 2025
4095c5b
Fixes
thomhurst Jun 2, 2025
24f9153
Fixes
thomhurst Jun 2, 2025
b9bf46e
Fixes
thomhurst Jun 2, 2025
b7de66a
Fixes
thomhurst Jun 2, 2025
6873dd0
Fixes
thomhurst Jun 2, 2025
3deda82
Tweak
thomhurst Jun 2, 2025
a3b9110
Update WindowsOnlyAttribute.cs
thomhurst Jun 2, 2025
f1adb6d
Update snaps
thomhurst Jun 3, 2025
e9218e4
Merge branch 'main' into feature/refactor-contexts
thomhurst Jun 3, 2025
00ac473
WIP
thomhurst Jun 3, 2025
39caf82
Fix nested class data sources
thomhurst Jun 3, 2025
2dd5765
WIP
thomhurst Jun 3, 2025
b1c6283
WIP
thomhurst Jun 3, 2025
04e35e3
WIP
thomhurst Jun 3, 2025
c99ac96
WIP
thomhurst Jun 3, 2025
0065881
WIP
thomhurst Jun 3, 2025
d19de4d
WIP
thomhurst Jun 3, 2025
11cf56d
WIP
thomhurst Jun 3, 2025
8d9ad0d
Fixes
thomhurst Jun 3, 2025
72f5d6e
Fix ReturnValue tests
thomhurst Jun 4, 2025
c03b98a
WIP
thomhurst Jun 4, 2025
2408581
Fixes
thomhurst Jun 4, 2025
f0f88a1
Fix
thomhurst Jun 4, 2025
369b1b5
Fixes
thomhurst Jun 4, 2025
a68c67a
WIP
thomhurst Jun 4, 2025
f97cce7
Fix
thomhurst Jun 4, 2025
493d784
Fixes
thomhurst Jun 4, 2025
b8af095
Fixes
thomhurst Jun 4, 2025
09df420
Fixes
thomhurst Jun 4, 2025
72dfc6a
Fixes
thomhurst Jun 4, 2025
700a9d1
Fixes
thomhurst Jun 4, 2025
b306566
WIP
thomhurst Jun 4, 2025
7f1f8fd
Fixes
thomhurst Jun 4, 2025
fcaaea0
Merge branch 'main' into feature/refactor-contexts
thomhurst Jun 4, 2025
5011e5e
Fixes
thomhurst Jun 4, 2025
fd5f46f
WIP
thomhurst Jun 4, 2025
e353d1c
if statement
thomhurst Jun 4, 2025
c5a5513
PropertyInitializationGenerator
thomhurst Jun 4, 2025
ddbafa1
Fixes
thomhurst Jun 4, 2025
c26f501
Add common interface method for IDataSourceGeneratorAttribute.cs
thomhurst Jun 4, 2025
80a81e9
Fix?
thomhurst Jun 5, 2025
56f413c
Fix
thomhurst Jun 5, 2025
7b8d7d5
Fixes
thomhurst Jun 5, 2025
0c937a8
Update snaps
thomhurst Jun 5, 2025
a1cdb5a
Remove debug line
thomhurst Jun 5, 2025
fba974c
Remove logs
thomhurst Jun 5, 2025
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
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
thomhurst committed Jun 4, 2025
commit a68c67a4a237d69e241c7bf1b3a8aa34c8bc968c
2 changes: 2 additions & 0 deletions TUnit.Core/UntypedDiscoveredTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
namespace TUnit.Core;

[UnconditionalSuppressMessage("Trimming", "IL2072:Target parameter argument does not satisfy \'DynamicallyAccessedMembersAttribute\' in call to target method. The return value of the source method does not have matching annotations.")]
[UnconditionalSuppressMessage("Trimming", "IL2060:Call to \'System.Reflection.MethodInfo.MakeGenericMethod\' can not be statically analyzed. It\'s not possible to guarantee the availability of requirements of the generic method.")]
[UnconditionalSuppressMessage("AOT", "IL3050:Calling members annotated with \'RequiresDynamicCodeAttribute\' may break functionality when AOT compiling.")]
internal record UntypedDiscoveredTest(ResettableLazy<object> ResettableLazy) : DiscoveredTest
{
public override async ValueTask ExecuteTest(CancellationToken cancellationToken)
Expand Down
2 changes: 1 addition & 1 deletion TUnit.Engine/Services/ReflectionScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static HashSet<Type> GetTypes()
return e.Types.OfType<Type>();
}
})
.Where(x => x.Name == "MethodDataSourceDrivenTests")
.Where(x => x.Name == "GenericMethodTests")
.ToHashSet();
}
}
68 changes: 60 additions & 8 deletions TUnit.Engine/Services/ReflectionTestsConstructor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,7 @@ private static void BuildTests(Type type, Func<object?[]> classInstanceArguments

if (testMethod.ContainsGenericParameters)
{
var testParametersTypes = testInformation.Parameters.Select(p => p.Type).ToList();

var substitutedTypes = testMethod.GetGenericArguments()
.Select(pc => testParametersTypes.FindIndex(pt => pt == pc))
.Select(i => testMethodArguments[i]!.GetType())
.ToArray();

testMethod = testMethod.MakeGenericMethod(substitutedTypes);
testMethod = GetRuntimeMethod(testMethod, testMethodArguments);
}

testsBuilderDynamicTests.Add(new UntypedDynamicTest(type, testMethod)
Expand Down Expand Up @@ -237,6 +230,65 @@ private static void BuildTests(Type type, Func<object?[]> classInstanceArguments
}
}

private static MethodInfo GetRuntimeMethod(MethodInfo methodInfo, object?[] arguments)
{
if (!methodInfo.IsGenericMethodDefinition)
{
return methodInfo;
}

var typeArguments = methodInfo.GetGenericArguments();

var parameters = methodInfo.GetParameters();

var argumentsTypes = arguments.Select(x => x?.GetType()).ToArray();

List<Type> substituteTypes = [];

foreach (var typeArgument in typeArguments)
{
if (!HasGenericParameter(typeArgument))
{
substituteTypes.Add(typeArgument);
continue;
}

var index = Array.IndexOf(typeArguments, typeArgument);

if (index < 0 || index >= parameters.Length)
{
throw new InvalidOperationException($"Generic type parameter '{typeArgument.Name}' not found in method parameters.");
}

var parameterType = parameters[index].ParameterType;

if (HasGenericParameter(parameterType))
{
// If the parameter is a generic type parameter, we use the type argument
substituteTypes.Add(argumentsTypes[index] ?? throw new InvalidOperationException($"No argument provided for generic type parameter '{typeArgument.Name}' at index {index}."));
continue;
}

if (parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(Nullable<>))
{
// If the parameter is a nullable type, we use the underlying type
substituteTypes.Add(parameterType.GetGenericArguments()[0]);
}
else
{
substituteTypes.Add(parameterType);
}
}

return methodInfo.MakeGenericMethod(substituteTypes.ToArray());
}

private static bool HasGenericParameter(Type parameterType)
{
return parameterType.IsGenericParameter
|| parameterType.IsGenericType && parameterType.GenericTypeArguments.Any(HasGenericParameter);
}

private static void AppendOptionalParameters(ref object?[] arguments, SourceGeneratedParameterInformation[] parameters)
{
if (arguments.Length == parameters.Length)
Expand Down