diff --git a/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt b/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt index 5f282702bb..e69de29bb2 100644 --- a/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AbstractTests.AbstractClass.verified.txt @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TUnit.Core.SourceGenerator.Tests/AotConverterGeneratorTests.GeneratesCode.verified.txt b/TUnit.Core.SourceGenerator.Tests/AotConverterGeneratorTests.GeneratesCode.verified.txt deleted file mode 100644 index 16ab7c3f35..0000000000 --- a/TUnit.Core.SourceGenerator.Tests/AotConverterGeneratorTests.GeneratesCode.verified.txt +++ /dev/null @@ -1,1376 +0,0 @@ -// -#pragma warning disable - -#nullable enable -using System; -using TUnit.Core.Converters; -namespace TUnit.Generated; -internal sealed class AotConverter_0 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.AllDataSourcesCombinedTests.DataSource1); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.AllDataSourcesCombinedTests.DataSource1 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_1 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.AllDataSourcesCombinedTests.DataSource2); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.AllDataSourcesCombinedTests.DataSource2 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_2 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.AllDataSourcesCombinedTests.DataSource3); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.AllDataSourcesCombinedTests.DataSource3 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_3 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.AllDataSourcesCombinedTestsVerification.DataSource1); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.AllDataSourcesCombinedTestsVerification.DataSource1 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_4 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.AllDataSourcesCombinedTestsVerification.DataSource2); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.AllDataSourcesCombinedTestsVerification.DataSource2 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_5 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.AllDataSourcesCombinedTestsVerification.DataSource3); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.AllDataSourcesCombinedTestsVerification.DataSource3 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_6 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ArgumentsWithClassDataSourceTests.IntDataSource1); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ArgumentsWithClassDataSourceTests.IntDataSource1 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_7 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ArgumentsWithClassDataSourceTests.IntDataSource2); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ArgumentsWithClassDataSourceTests.IntDataSource2 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_8 : IAotConverter -{ - public Type SourceType => typeof(int); - public Type TargetType => typeof(global::TUnit.TestProject.ExplicitInteger); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.ExplicitInteger targetTypedValue) - { - return targetTypedValue; - } - if (value is int sourceTypedValue) - { - global::TUnit.TestProject.ExplicitInteger converted = (global::TUnit.TestProject.ExplicitInteger)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_9 : IAotConverter -{ - public Type SourceType => typeof(int); - public Type TargetType => typeof(global::TUnit.TestProject.ImplicitInteger); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.ImplicitInteger targetTypedValue) - { - return targetTypedValue; - } - if (value is int sourceTypedValue) - { - global::TUnit.TestProject.ImplicitInteger converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_10 : IAotConverter -{ - public Type SourceType => typeof(byte); - public Type TargetType => typeof(byte?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is byte targetTypedValue) - { - return targetTypedValue; - } - if (value is byte sourceTypedValue) - { - byte? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_11 : IAotConverter -{ - public Type SourceType => typeof(byte?); - public Type TargetType => typeof(byte); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is byte targetTypedValue) - { - return targetTypedValue; - } - if (value is byte sourceTypedValue) - { - byte converted = (byte)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_12 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ClassDataSourceEnumerableTest.EnumerableDataSource); - public Type TargetType => typeof(string); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is string targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ClassDataSourceEnumerableTest.EnumerableDataSource sourceTypedValue) - { - string converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_13 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ClassDataSourceWithMethodDataSourceTests.DataSource1); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ClassDataSourceWithMethodDataSourceTests.DataSource1 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_14 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ClassDataSourceWithMethodDataSourceTests.DataSource2); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ClassDataSourceWithMethodDataSourceTests.DataSource2 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_15 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ClassDataSourceWithMethodDataSourceTests.DataSource3); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ClassDataSourceWithMethodDataSourceTests.DataSource3 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_16 : IAotConverter -{ - public Type SourceType => typeof(int); - public Type TargetType => typeof(int?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is int sourceTypedValue) - { - int? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_17 : IAotConverter -{ - public Type SourceType => typeof(int?); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is int sourceTypedValue) - { - int converted = (int)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_18 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.ComprehensiveCountTest.ClassData); - public Type TargetType => typeof(string); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is string targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.ComprehensiveCountTest.ClassData sourceTypedValue) - { - string converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_19 : IAotConverter -{ - public Type SourceType => typeof(bool); - public Type TargetType => typeof(bool?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is bool targetTypedValue) - { - return targetTypedValue; - } - if (value is bool sourceTypedValue) - { - bool? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_20 : IAotConverter -{ - public Type SourceType => typeof(bool?); - public Type TargetType => typeof(bool); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is bool targetTypedValue) - { - return targetTypedValue; - } - if (value is bool sourceTypedValue) - { - bool converted = (bool)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_21 : IAotConverter -{ - public Type SourceType => typeof(byte); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is byte sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_22 : IAotConverter -{ - public Type SourceType => typeof(sbyte); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is sbyte sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_23 : IAotConverter -{ - public Type SourceType => typeof(short); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is short sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_24 : IAotConverter -{ - public Type SourceType => typeof(ushort); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is ushort sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_25 : IAotConverter -{ - public Type SourceType => typeof(char); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is char sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_26 : IAotConverter -{ - public Type SourceType => typeof(int); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is int sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_27 : IAotConverter -{ - public Type SourceType => typeof(uint); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is uint sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_28 : IAotConverter -{ - public Type SourceType => typeof(long); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is long sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_29 : IAotConverter -{ - public Type SourceType => typeof(ulong); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is ulong sourceTypedValue) - { - decimal converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_30 : IAotConverter -{ - public Type SourceType => typeof(float); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is float sourceTypedValue) - { - decimal converted = (decimal)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_31 : IAotConverter -{ - public Type SourceType => typeof(double); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is double sourceTypedValue) - { - decimal converted = (decimal)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_32 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(byte); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is byte targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - byte converted = (byte)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_33 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(sbyte); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is sbyte targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - sbyte converted = (sbyte)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_34 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(char); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is char targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - char converted = (char)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_35 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(short); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is short targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - short converted = (short)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_36 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(ushort); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is ushort targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - ushort converted = (ushort)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_37 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - int converted = (int)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_38 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(uint); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is uint targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - uint converted = (uint)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_39 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(long); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is long targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - long converted = (long)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_40 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(ulong); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is ulong targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - ulong converted = (ulong)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_41 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(float); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is float targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - float converted = (float)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_42 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(double); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is double targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - double converted = (double)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_43 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.TestEnum); - public Type TargetType => typeof(global::TUnit.TestProject.TestEnum?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.TestEnum targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.TestEnum sourceTypedValue) - { - global::TUnit.TestProject.TestEnum? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_44 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.TestEnum?); - public Type TargetType => typeof(global::TUnit.TestProject.TestEnum); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.TestEnum targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.TestEnum sourceTypedValue) - { - global::TUnit.TestProject.TestEnum converted = (global::TUnit.TestProject.TestEnum)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_45 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedDataSourceBugTest.ClassData1); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedDataSourceBugTest.ClassData1 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_46 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedDataSourceBugTest.ClassData2); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedDataSourceBugTest.ClassData2 sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_47 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum4); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion1); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion1 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum4 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTestsUnion1 converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_48 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion1); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum4); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum4 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion1 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTests.Enum4 converted = (global::TUnit.TestProject.MixedMatrixTests.Enum4)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_49 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum5); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion1); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion1 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum5 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTestsUnion1 converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_50 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion1); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum5); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum5 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion1 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTests.Enum5 converted = (global::TUnit.TestProject.MixedMatrixTests.Enum5)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_51 : IAotConverter -{ - public Type SourceType => typeof(string); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion1); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion1 targetTypedValue) - { - return targetTypedValue; - } - if (value is string sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTestsUnion1 converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_52 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion1); - public Type TargetType => typeof(string); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is string targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion1 sourceTypedValue) - { - string converted = (string)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_53 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum4); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion2); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion2 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum4 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTestsUnion2 converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_54 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion2); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum4); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum4 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion2 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTests.Enum4 converted = (global::TUnit.TestProject.MixedMatrixTests.Enum4)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_55 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum5); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion2); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion2 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum5 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTestsUnion2 converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_56 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion2); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTests.Enum5); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTests.Enum5 targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion2 sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTests.Enum5 converted = (global::TUnit.TestProject.MixedMatrixTests.Enum5)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_57 : IAotConverter -{ - public Type SourceType => typeof(string); - public Type TargetType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion2); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion2 targetTypedValue) - { - return targetTypedValue; - } - if (value is string sourceTypedValue) - { - global::TUnit.TestProject.MixedMatrixTestsUnion2 converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_58 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.MixedMatrixTestsUnion2); - public Type TargetType => typeof(string); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is string targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.MixedMatrixTestsUnion2 sourceTypedValue) - { - string converted = (string)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_59 : IAotConverter -{ - public Type SourceType => typeof(decimal); - public Type TargetType => typeof(decimal?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - decimal? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_60 : IAotConverter -{ - public Type SourceType => typeof(decimal?); - public Type TargetType => typeof(decimal); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is decimal targetTypedValue) - { - return targetTypedValue; - } - if (value is decimal sourceTypedValue) - { - decimal converted = (decimal)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_61 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.TestCountVerificationTests.TestDataSource); - public Type TargetType => typeof(int); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is int targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.TestCountVerificationTests.TestDataSource sourceTypedValue) - { - int converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_62 : IAotConverter -{ - public Type SourceType => typeof(int); - public Type TargetType => typeof(global::TUnit.TestProject.Bugs._2757.Foo); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.Bugs._2757.Foo targetTypedValue) - { - return targetTypedValue; - } - if (value is int sourceTypedValue) - { - global::TUnit.TestProject.Bugs._2757.Foo converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_63 : IAotConverter -{ - public Type SourceType => typeof(global::System.ValueTuple); - public Type TargetType => typeof(global::TUnit.TestProject.Bugs._2798.Foo); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.Bugs._2798.Foo targetTypedValue) - { - return targetTypedValue; - } - if (value is global::System.ValueTuple sourceTypedValue) - { - global::TUnit.TestProject.Bugs._2798.Foo converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_64 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.Bugs._3185.FlagMock); - public Type TargetType => typeof(global::TUnit.TestProject.Bugs._3185.FlagMock?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.Bugs._3185.FlagMock targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.Bugs._3185.FlagMock sourceTypedValue) - { - global::TUnit.TestProject.Bugs._3185.FlagMock? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_65 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.Bugs._3185.FlagMock?); - public Type TargetType => typeof(global::TUnit.TestProject.Bugs._3185.FlagMock); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.Bugs._3185.FlagMock targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.Bugs._3185.FlagMock sourceTypedValue) - { - global::TUnit.TestProject.Bugs._3185.FlagMock converted = (global::TUnit.TestProject.Bugs._3185.FlagMock)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_66 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.Bugs._3185.RegularEnum); - public Type TargetType => typeof(global::TUnit.TestProject.Bugs._3185.RegularEnum?); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.Bugs._3185.RegularEnum targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.Bugs._3185.RegularEnum sourceTypedValue) - { - global::TUnit.TestProject.Bugs._3185.RegularEnum? converted = sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal sealed class AotConverter_67 : IAotConverter -{ - public Type SourceType => typeof(global::TUnit.TestProject.Bugs._3185.RegularEnum?); - public Type TargetType => typeof(global::TUnit.TestProject.Bugs._3185.RegularEnum); - public object? Convert(object? value) - { - if (value == null) return null; - if (value is global::TUnit.TestProject.Bugs._3185.RegularEnum targetTypedValue) - { - return targetTypedValue; - } - if (value is global::TUnit.TestProject.Bugs._3185.RegularEnum sourceTypedValue) - { - global::TUnit.TestProject.Bugs._3185.RegularEnum converted = (global::TUnit.TestProject.Bugs._3185.RegularEnum)sourceTypedValue; - return converted; - } - return value; // Return original value if type doesn't match - } -} -internal static class AotConverterRegistration -{ - [global::System.Runtime.CompilerServices.ModuleInitializer] - [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Performance", "CA2255:The 'ModuleInitializer' attribute should not be used in libraries", - Justification = "Test framework needs to register AOT converters for conversion operators")] - public static void Initialize() - { - AotConverterRegistry.Register(new AotConverter_0()); - AotConverterRegistry.Register(new AotConverter_1()); - AotConverterRegistry.Register(new AotConverter_2()); - AotConverterRegistry.Register(new AotConverter_3()); - AotConverterRegistry.Register(new AotConverter_4()); - AotConverterRegistry.Register(new AotConverter_5()); - AotConverterRegistry.Register(new AotConverter_6()); - AotConverterRegistry.Register(new AotConverter_7()); - AotConverterRegistry.Register(new AotConverter_8()); - AotConverterRegistry.Register(new AotConverter_9()); - AotConverterRegistry.Register(new AotConverter_10()); - AotConverterRegistry.Register(new AotConverter_11()); - AotConverterRegistry.Register(new AotConverter_12()); - AotConverterRegistry.Register(new AotConverter_13()); - AotConverterRegistry.Register(new AotConverter_14()); - AotConverterRegistry.Register(new AotConverter_15()); - AotConverterRegistry.Register(new AotConverter_16()); - AotConverterRegistry.Register(new AotConverter_17()); - AotConverterRegistry.Register(new AotConverter_18()); - AotConverterRegistry.Register(new AotConverter_19()); - AotConverterRegistry.Register(new AotConverter_20()); - AotConverterRegistry.Register(new AotConverter_21()); - AotConverterRegistry.Register(new AotConverter_22()); - AotConverterRegistry.Register(new AotConverter_23()); - AotConverterRegistry.Register(new AotConverter_24()); - AotConverterRegistry.Register(new AotConverter_25()); - AotConverterRegistry.Register(new AotConverter_26()); - AotConverterRegistry.Register(new AotConverter_27()); - AotConverterRegistry.Register(new AotConverter_28()); - AotConverterRegistry.Register(new AotConverter_29()); - AotConverterRegistry.Register(new AotConverter_30()); - AotConverterRegistry.Register(new AotConverter_31()); - AotConverterRegistry.Register(new AotConverter_32()); - AotConverterRegistry.Register(new AotConverter_33()); - AotConverterRegistry.Register(new AotConverter_34()); - AotConverterRegistry.Register(new AotConverter_35()); - AotConverterRegistry.Register(new AotConverter_36()); - AotConverterRegistry.Register(new AotConverter_37()); - AotConverterRegistry.Register(new AotConverter_38()); - AotConverterRegistry.Register(new AotConverter_39()); - AotConverterRegistry.Register(new AotConverter_40()); - AotConverterRegistry.Register(new AotConverter_41()); - AotConverterRegistry.Register(new AotConverter_42()); - AotConverterRegistry.Register(new AotConverter_43()); - AotConverterRegistry.Register(new AotConverter_44()); - AotConverterRegistry.Register(new AotConverter_45()); - AotConverterRegistry.Register(new AotConverter_46()); - AotConverterRegistry.Register(new AotConverter_47()); - AotConverterRegistry.Register(new AotConverter_48()); - AotConverterRegistry.Register(new AotConverter_49()); - AotConverterRegistry.Register(new AotConverter_50()); - AotConverterRegistry.Register(new AotConverter_51()); - AotConverterRegistry.Register(new AotConverter_52()); - AotConverterRegistry.Register(new AotConverter_53()); - AotConverterRegistry.Register(new AotConverter_54()); - AotConverterRegistry.Register(new AotConverter_55()); - AotConverterRegistry.Register(new AotConverter_56()); - AotConverterRegistry.Register(new AotConverter_57()); - AotConverterRegistry.Register(new AotConverter_58()); - AotConverterRegistry.Register(new AotConverter_59()); - AotConverterRegistry.Register(new AotConverter_60()); - AotConverterRegistry.Register(new AotConverter_61()); - AotConverterRegistry.Register(new AotConverter_62()); - AotConverterRegistry.Register(new AotConverter_63()); - AotConverterRegistry.Register(new AotConverter_64()); - AotConverterRegistry.Register(new AotConverter_65()); - AotConverterRegistry.Register(new AotConverter_66()); - AotConverterRegistry.Register(new AotConverter_67()); - } -} diff --git a/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt index 4bd714eb7b..a8b459eccf 100644 --- a/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt @@ -53,32 +53,32 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Collect } case 1: { - instance.Params((args[0] is null ? null : args[0] is string[] arr ? arr : new string[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); + instance.Params((args[0] is null ? null : args[0] is string[] arr ? arr : new string[] { (string)args[0] })); return default(global::System.Threading.Tasks.ValueTask); } case 2: { - instance.Params(new string[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]) }); + instance.Params(new string[] { (string)args[0], (string)args[1] }); return default(global::System.Threading.Tasks.ValueTask); } case 3: { - instance.Params(new string[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); + instance.Params(new string[] { (string)args[0], (string)args[1], (string)args[2] }); return default(global::System.Threading.Tasks.ValueTask); } case 4: { - instance.Params(new string[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); + instance.Params(new string[] { (string)args[0], (string)args[1], (string)args[2], (string)args[3] }); return default(global::System.Threading.Tasks.ValueTask); } case 5: { - instance.Params(new string[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); + instance.Params(new string[] { (string)args[0], (string)args[1], (string)args[2], (string)args[3], (string)args[4] }); return default(global::System.Threading.Tasks.ValueTask); } case 6: { - instance.Params(new string[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), global::TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); + instance.Params(new string[] { (string)args[0], (string)args[1], (string)args[2], (string)args[3], (string)args[4], (string)args[5] }); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -98,37 +98,37 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Collect { case 0: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable(new string[0]); return default(global::System.Threading.Tasks.ValueTask); } case 1: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable((args[0] is null ? null : args[0] is global::System.Collections.Generic.IEnumerable arr ? arr : new string[] { (string)args[0] })); return default(global::System.Threading.Tasks.ValueTask); } case 2: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable(new string[] { (string)args[0], (string)args[1] }); return default(global::System.Threading.Tasks.ValueTask); } case 3: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable(new string[] { (string)args[0], (string)args[1], (string)args[2] }); return default(global::System.Threading.Tasks.ValueTask); } case 4: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable(new string[] { (string)args[0], (string)args[1], (string)args[2], (string)args[3] }); return default(global::System.Threading.Tasks.ValueTask); } case 5: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable(new string[] { (string)args[0], (string)args[1], (string)args[2], (string)args[3], (string)args[4] }); return default(global::System.Threading.Tasks.ValueTask); } case 6: { - instance.ParamsEnumerable(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + instance.ParamsEnumerable(new string[] { (string)args[0], (string)args[1], (string)args[2], (string)args[3], (string)args[4], (string)args[5] }); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -148,37 +148,37 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Collect { case 1: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], new string[0]); return default(global::System.Threading.Tasks.ValueTask); } case 2: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], (args[1] is null ? null : args[1] is global::System.Collections.Generic.IEnumerable arr ? arr : new string[] { (string)args[1] })); return default(global::System.Threading.Tasks.ValueTask); } case 3: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], new string[] { (string)args[1], (string)args[2] }); return default(global::System.Threading.Tasks.ValueTask); } case 4: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], new string[] { (string)args[1], (string)args[2], (string)args[3] }); return default(global::System.Threading.Tasks.ValueTask); } case 5: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], new string[] { (string)args[1], (string)args[2], (string)args[3], (string)args[4] }); return default(global::System.Threading.Tasks.ValueTask); } case 6: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], new string[] { (string)args[1], (string)args[2], (string)args[3], (string)args[4], (string)args[5] }); return default(global::System.Threading.Tasks.ValueTask); } case 7: { - instance.Following_Non_Params(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + instance.Following_Non_Params((int)args[0], new string[] { (string)args[1], (string)args[2], (string)args[3], (string)args[4], (string)args[5], (string)args[6] }); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt index 4d4f8cd19b..c03f6969d6 100644 --- a/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt @@ -43,7 +43,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - instance.Explicit(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Explicit((global::TUnit.TestProject.ExplicitInteger)(int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -63,7 +63,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - instance.Implicit(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Implicit((global::TUnit.TestProject.ImplicitInteger)(int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.Net4_7.verified.txt index 4086603606..c7a10a0de9 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt index 5f282702bb..e69de29bb2 100644 --- a/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Basic.Test.verified.txt @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.Net4_7.verified.txt index 4086603606..c7a10a0de9 100644 --- a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt index 0467212ff8..506a18ca13 100644 --- a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt index 92d82718eb..b87eda6aba 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt @@ -33,7 +33,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "arg2", new g }); private static global::TUnit.TestProject.ClassAndMethodArgumentsTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.ClassAndMethodArgumentsTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.ClassAndMethodArgumentsTests((string)args[0]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.ClassAndMethodArgumentsTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { @@ -58,7 +58,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "arg2", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.WithMethodLevel(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.WithMethodLevel((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -77,7 +77,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "arg2", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.IgnoreParameters(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.IgnoreParameters((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt index cbf117d53a..0d66926c12 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -73,7 +73,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - instance.DataSource_Class(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Class((global::TUnit.TestProject.Library.Models.SomeAsyncDisposableClass)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -93,7 +93,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - instance.DataSource_Class_Generic(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Class_Generic((global::TUnit.TestProject.Library.Models.SomeAsyncDisposableClass)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -113,7 +113,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_1_ClassDataSource(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_1_ClassDataSource((global::TUnit.TestProject.Library.Models.InitializableClass)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -132,7 +132,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_2_ClassDataSources(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_2_ClassDataSources((global::TUnit.TestProject.Library.Models.InitializableClass)args[0], (global::TUnit.TestProject.Library.Models.InitializableClass)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -151,7 +151,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_3_ClassDataSources(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_3_ClassDataSources((global::TUnit.TestProject.Library.Models.InitializableClass)args[0], (global::TUnit.TestProject.Library.Models.InitializableClass)args[1], (global::TUnit.TestProject.Library.Models.InitializableClass)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -170,7 +170,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 4: { - return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_4_ClassDataSources(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_4_ClassDataSources((global::TUnit.TestProject.Library.Models.InitializableClass)args[0], (global::TUnit.TestProject.Library.Models.InitializableClass)args[1], (global::TUnit.TestProject.Library.Models.InitializableClass)args[2], (global::TUnit.TestProject.Library.Models.InitializableClass)args[3])); } default: throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); @@ -189,7 +189,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 5: { - return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_5_ClassDataSources(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]))); + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_5_ClassDataSources((global::TUnit.TestProject.Library.Models.InitializableClass)args[0], (global::TUnit.TestProject.Library.Models.InitializableClass)args[1], (global::TUnit.TestProject.Library.Models.InitializableClass)args[2], (global::TUnit.TestProject.Library.Models.InitializableClass)args[3], (global::TUnit.TestProject.Library.Models.InitializableClass)args[4])); } default: throw new global::System.ArgumentException($"Expected exactly 5 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt index 8d9a296e22..dd1bfd32a1 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -26,7 +26,7 @@ internal static class TUnit_TestProject_ClassDataSourceDrivenTests2__TestSource private static readonly global::TUnit.Core.MethodMetadata __mm_1 = global::TUnit.Core.MethodMetadataFactory.Create("Base_Derived2", __classType, typeof(void), __classMetadata); private static global::TUnit.TestProject.ClassDataSourceDrivenTests2 __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.ClassDataSourceDrivenTests2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.ClassDataSourceDrivenTests2((args[0] switch { global::TUnit.TestProject.ClassDataSourceDrivenTests2.Derived1 __s => (global::TUnit.TestProject.ClassDataSourceDrivenTests2.Base)__s, global::TUnit.TestProject.ClassDataSourceDrivenTests2.Derived2 __s => (global::TUnit.TestProject.ClassDataSourceDrivenTests2.Base)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.ClassDataSourceDrivenTests2 instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { diff --git a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt index 1d2d7b5c14..a0f43abe99 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -43,7 +43,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - instance.DataSource_Class(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Class((global::TUnit.TestProject.Library.Models.SomeAsyncDisposableClass)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -63,7 +63,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 1: { - instance.DataSource_Class_Generic(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Class_Generic((global::TUnit.TestProject.Library.Models.SomeAsyncDisposableClass)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.BasicTest_WithConflictingNamespace.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.BasicTest_WithConflictingNamespace.Net4_7.verified.txt index 4086603606..c7a10a0de9 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.BasicTest_WithConflictingNamespace.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.BasicTest_WithConflictingNamespace.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet10_0.verified.txt index d755ba780c..a7b4b28191 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet10_0.verified.txt @@ -76,7 +76,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Method((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -96,7 +96,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 2: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); + instance.DataSource_Method((int)args[0], (string)args[1]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -116,7 +116,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EnumValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EnumValue((args[0] switch { global::TUnit.TestProject.TestEnum __s => __s, int __s => (global::TUnit.TestProject.TestEnum)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -156,7 +156,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.NonEmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.NonEmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -216,7 +216,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.Type(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Type((global::System.Type)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -236,7 +236,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntegerArray(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntegerArray((int[])args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -256,7 +256,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntMaxValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntMaxValue((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet8_0.verified.txt index d755ba780c..a7b4b28191 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet8_0.verified.txt @@ -76,7 +76,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Method((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -96,7 +96,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 2: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); + instance.DataSource_Method((int)args[0], (string)args[1]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -116,7 +116,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EnumValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EnumValue((args[0] switch { global::TUnit.TestProject.TestEnum __s => __s, int __s => (global::TUnit.TestProject.TestEnum)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -156,7 +156,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.NonEmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.NonEmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -216,7 +216,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.Type(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Type((global::System.Type)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -236,7 +236,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntegerArray(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntegerArray((int[])args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -256,7 +256,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntMaxValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntMaxValue((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet9_0.verified.txt index d755ba780c..a7b4b28191 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.DotNet9_0.verified.txt @@ -76,7 +76,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Method((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -96,7 +96,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 2: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); + instance.DataSource_Method((int)args[0], (string)args[1]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -116,7 +116,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EnumValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EnumValue((args[0] switch { global::TUnit.TestProject.TestEnum __s => __s, int __s => (global::TUnit.TestProject.TestEnum)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -156,7 +156,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.NonEmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.NonEmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -216,7 +216,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.Type(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Type((global::System.Type)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -236,7 +236,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntegerArray(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntegerArray((int[])args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -256,7 +256,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntMaxValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntMaxValue((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.Net4_7.verified.txt index d1793df3ab..c8c83e5d1e 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.DataDrivenTest_WithConflictingNamespace.Net4_7.verified.txt @@ -76,7 +76,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Method((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -96,7 +96,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 2: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); + instance.DataSource_Method((int)args[0], (string)args[1]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -116,7 +116,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EnumValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EnumValue((args[0] switch { global::TUnit.TestProject.TestEnum __s => __s, int __s => (global::TUnit.TestProject.TestEnum)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -156,7 +156,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.NonEmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.NonEmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -216,7 +216,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.Type(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Type((global::System.Type)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -236,7 +236,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntegerArray(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntegerArray((int[])args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -256,7 +256,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntMaxValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntMaxValue((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.HooksTest_WithConflictingNamespace.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.HooksTest_WithConflictingNamespace.Net4_7.verified.txt index 731032feb0..2f50bccc15 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.HooksTest_WithConflictingNamespace.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.HooksTest_WithConflictingNamespace.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet10_0.verified.txt index ebe16e36c3..910f38a52c 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet10_0.verified.txt @@ -100,7 +100,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One((string)args[0], (int)args[1], (bool)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 4: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two((int)args[0], (int)args[1], (int)args[2], (bool)args[3])); } default: throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); @@ -138,7 +138,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum((int)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), (TestEnum?)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -157,7 +157,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools((string)args[0], (bool)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2((string)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -328,7 +328,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues((bool)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet8_0.verified.txt index ebe16e36c3..910f38a52c 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet8_0.verified.txt @@ -100,7 +100,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One((string)args[0], (int)args[1], (bool)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 4: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two((int)args[0], (int)args[1], (int)args[2], (bool)args[3])); } default: throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); @@ -138,7 +138,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum((int)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), (TestEnum?)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -157,7 +157,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools((string)args[0], (bool)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2((string)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -328,7 +328,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues((bool)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet9_0.verified.txt index ebe16e36c3..910f38a52c 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.DotNet9_0.verified.txt @@ -100,7 +100,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One((string)args[0], (int)args[1], (bool)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 4: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two((int)args[0], (int)args[1], (int)args[2], (bool)args[3])); } default: throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); @@ -138,7 +138,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum((int)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), (TestEnum?)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -157,7 +157,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools((string)args[0], (bool)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2((string)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -328,7 +328,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues((bool)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.Net4_7.verified.txt index a07386699e..938afac314 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MatrixTest_WithConflictingNamespace.Net4_7.verified.txt @@ -100,7 +100,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One((string)args[0], (int)args[1], (bool)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 4: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two((int)args[0], (int)args[1], (int)args[2], (bool)args[3])); } default: throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); @@ -138,7 +138,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum((int)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), (TestEnum?)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -157,7 +157,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools((string)args[0], (bool)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2((string)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -328,7 +328,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues((bool)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MethodDataSource_WithConflictingNamespace.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MethodDataSource_WithConflictingNamespace.Net4_7.verified.txt index 2e2148a732..17e51d2fa4 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MethodDataSource_WithConflictingNamespace.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.MethodDataSource_WithConflictingNamespace.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.TupleDataSource_WithConflictingNamespace.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.TupleDataSource_WithConflictingNamespace.Net4_7.verified.txt index 0a26c26995..f8e5acfcdf 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.TupleDataSource_WithConflictingNamespace.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConflictingNamespaceTests.TupleDataSource_WithConflictingNamespace.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt index eab8497950..c2f04fcade 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt @@ -63,7 +63,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.String1(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.String1((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -82,7 +82,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Int(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Int((int)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -101,7 +101,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Double(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Double((double)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -120,7 +120,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Float(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Float((float)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -139,7 +139,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Long(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Long((long)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -158,7 +158,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.UInt(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.UInt((uint)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -177,7 +177,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(ulong), "dummy", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.ULong(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.ULong((ulong)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt index 189dce3fa8..06a5b68a7d 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt @@ -39,7 +39,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "value", new { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.SomeTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.SomeTest((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt index dfdc065625..bba5e03427 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt @@ -39,7 +39,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "value", new { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.SomeTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.SomeTest((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt index 95973f1f10..9cb1a4411f 100644 --- a/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -94,7 +94,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "password", n { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.Test3(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.Test3((string)args[0], (int)args[1], (bool)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -132,7 +132,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "password", n { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.TestParameterNamePrefixBug(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.TestParameterNamePrefixBug((int)args[0], (string)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -151,7 +151,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "password", n { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.PasswordTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.PasswordTest((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt index d755ba780c..c8c83e5d1e 100644 --- a/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -76,7 +76,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.DataSource_Method((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -96,7 +96,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 2: { - instance.DataSource_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); + instance.DataSource_Method((int)args[0], (string)args[1]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -116,7 +116,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EnumValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EnumValue((args[0] switch { global::TUnit.TestProject.TestEnum __s => __s, int __s => (global::TUnit.TestProject.TestEnum)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -156,7 +156,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.EmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.EmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.NonEmptyString(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.NonEmptyString((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -216,7 +216,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.Type(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Type((global::System.Type)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -236,7 +236,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntegerArray(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntegerArray((int[])args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -256,7 +256,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - instance.IntMaxValue(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.IntMaxValue((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt b/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt index 7bd5762252..4d12305309 100644 --- a/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -42,7 +42,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "value3", new g }); private static global::TUnit.TestProject.DataSourceGeneratorTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.DataSourceGeneratorTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return new global::TUnit.TestProject.DataSourceGeneratorTests((args[0] switch { global::System.ValueTuple __s => global::TUnit.Core.Helpers.CastHelper.Cast(__s), int __s => __s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) }), (string)args[1], (bool)args[2]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.DataSourceGeneratorTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { @@ -56,7 +56,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "value3", new g { case 1: { - instance.GeneratedData_Method(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.GeneratedData_Method((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -76,7 +76,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "value3", new g { case 3: { - instance.GeneratedData_Method2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2])); + instance.GeneratedData_Method2((int)args[0], (string)args[1], (bool)args[2]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt index 6dbf771d6d..1654b3c7af 100644 --- a/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -91,7 +91,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(decimal), "batchingSiz { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.Transfer(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.Transfer((args[0] switch { double __s => (decimal)__s, int __s => (decimal)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) }), (args[1] switch { double __s => (decimal)__s, int __s => (decimal)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[1]) }))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -224,7 +224,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(decimal), "batchingSiz { case 1: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test((args[0] switch { double __s => (decimal)__s, int __s => (decimal)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -244,7 +244,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(decimal), "batchingSiz { case 6: { - instance.TransactionDiscountCalculations(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), global::TUnit.Core.Helpers.CastHelper.Cast(args[5])); + instance.TransactionDiscountCalculations(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), (bool)args[5]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.Net4_7.verified.txt index 4086603606..c7a10a0de9 100644 --- a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet10_0.verified.txt index e0a05c3d5f..6b3a32caa8 100644 --- a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet10_0.verified.txt @@ -78,16 +78,16 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } - var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests); + var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests); // Force module initializer to complete before proceeding // RunClassConstructor triggers static constructor, which can only run AFTER module initializer completes global::System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type_2.TypeHandle); try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } } @@ -95,7 +95,7 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests: " + ex.Message); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests: " + ex.Message); } catch { /* TUnit.Core not available - skip logging */ } } diff --git a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet8_0.verified.txt index e0a05c3d5f..6b3a32caa8 100644 --- a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet8_0.verified.txt @@ -78,16 +78,16 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } - var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests); + var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests); // Force module initializer to complete before proceeding // RunClassConstructor triggers static constructor, which can only run AFTER module initializer completes global::System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type_2.TypeHandle); try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } } @@ -95,7 +95,7 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests: " + ex.Message); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests: " + ex.Message); } catch { /* TUnit.Core not available - skip logging */ } } diff --git a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet9_0.verified.txt index e0a05c3d5f..6b3a32caa8 100644 --- a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.DotNet9_0.verified.txt @@ -78,16 +78,16 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } - var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests); + var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests); // Force module initializer to complete before proceeding // RunClassConstructor triggers static constructor, which can only run AFTER module initializer completes global::System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type_2.TypeHandle); try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } } @@ -95,7 +95,7 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests: " + ex.Message); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests: " + ex.Message); } catch { /* TUnit.Core not available - skip logging */ } } diff --git a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.Net4_7.verified.txt index e03a68e441..6b3a32caa8 100644 --- a/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DuplicateTypeNameAcrossAssembliesTests.InfrastructureGenerator_WithDuplicateTypeNames_CompilesSuccessfully.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable using TUnit.Core.Logging; @@ -78,16 +78,16 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Loading assembly containing: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } - var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests); + var type_2 = typeof(global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests); // Force module initializer to complete before proceeding // RunClassConstructor triggers static constructor, which can only run AFTER module initializer completes global::System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor(type_2.TypeHandle); try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests"); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Assembly initialized: global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests"); } catch { /* TUnit.Core not available - skip logging */ } } @@ -95,7 +95,7 @@ file static class TUnitInfrastructure { try { - global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.AotConverterGeneratorTests: " + ex.Message); + global::TUnit.Core.GlobalContext.Current.GlobalLogger.LogTrace("[ModuleInitializer:TestsBase`1] Failed to load global::TUnit.Core.SourceGenerator.Tests.FullProjectGenerationTests: " + ex.Message); } catch { /* TUnit.Core not available - skip logging */ } } diff --git a/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt index fcbb6a38cd..2366ceb79e 100644 --- a/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt @@ -39,7 +39,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "value", new { case 1: { - instance.SomeTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.SomeTest((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt index 3b0d288124..c43348edb4 100644 --- a/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -46,7 +46,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Type), { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.TypedArguments(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.TypedArguments((args[0] switch { byte __s => (object)__s, double __s => (object)__s, float __s => (object)__s, int __s => (object)__s, long __s => (object)__s, sbyte __s => (object)__s, short __s => (object)__s, uint __s => (object)__s, ulong __s => (object)__s, ushort __s => (object)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) }), (global::System.Type)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -65,7 +65,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Type), { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.EnumTypes(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.EnumTypes((args[0] switch { global::TUnit.TestProject.ByteEnum __s => (object)__s, global::TUnit.TestProject.Int16Enum __s => (object)__s, global::TUnit.TestProject.Int32Enum __s => (object)__s, global::TUnit.TestProject.Int64Enum __s => (object)__s, global::TUnit.TestProject.SByteEnum __s => (object)__s, global::TUnit.TestProject.UInt16Enum __s => (object)__s, global::TUnit.TestProject.UInt32Enum __s => (object)__s, global::TUnit.TestProject.UInt64Enum __s => (object)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) }), (global::System.Type)args[1], (global::System.Type)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/AotConverterGeneratorTests.cs b/TUnit.Core.SourceGenerator.Tests/FullProjectGenerationTests.cs similarity index 82% rename from TUnit.Core.SourceGenerator.Tests/AotConverterGeneratorTests.cs rename to TUnit.Core.SourceGenerator.Tests/FullProjectGenerationTests.cs index 3c1095c104..ebafaf4c4e 100644 --- a/TUnit.Core.SourceGenerator.Tests/AotConverterGeneratorTests.cs +++ b/TUnit.Core.SourceGenerator.Tests/FullProjectGenerationTests.cs @@ -2,11 +2,11 @@ namespace TUnit.Core.SourceGenerator.Tests; -public class AotConverterGeneratorTests : TestsBase +public class FullProjectGenerationTests : TestsBase { [Test] [Skip("Need to investigate - Behaves differently on local vs CI")] - public Task GeneratesCode() => AotConverterGenerator.RunTest( + public Task GeneratesCode() => TestMetadataGenerator.RunTest( Path.GetTempFileName(), new RunTestOptions { diff --git a/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt index a64949adef..9da3cd10e8 100644 --- a/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -25,7 +25,7 @@ internal static class TUnit_TestProject_Bugs__1589_MyTests__TestSource private static readonly global::TUnit.Core.MethodMetadata __mm_0 = global::TUnit.Core.MethodMetadataFactory.Create("Test1", __classType, typeof(global::System.Threading.Tasks.Task), __classMetadata); private static global::TUnit.TestProject.Bugs._1589.MyTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.Bugs._1589.MyTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.Bugs._1589.MyTests((global::TUnit.TestProject.Bugs._1589.MyFixture)args[0]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.Bugs._1589.MyTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { diff --git a/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt index 7fc58c8b28..5b9642b72e 100644 --- a/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -25,7 +25,7 @@ internal static class TUnit_TestProject_Bugs__1594_MyTests__TestSource private static readonly global::TUnit.Core.MethodMetadata __mm_0 = global::TUnit.Core.MethodMetadataFactory.Create("Test1", __classType, typeof(void), __classMetadata); private static global::TUnit.TestProject.Bugs._1594.MyTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.Bugs._1594.MyTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.Bugs._1594.MyTests((global::TUnit.TestProject.Bugs._1594.MyFixture)args[0]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.Bugs._1594.MyTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { diff --git a/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt b/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt index 5f282702bb..e69de29bb2 100644 --- a/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/HooksTests.NullableByteArgumentTests.verified.txt @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt index bc92075324..31e82b7b93 100644 --- a/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt @@ -59,7 +59,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Test((int)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -167,7 +167,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Test((int)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -267,7 +267,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Test((int)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -367,7 +367,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "value", new glo { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Test((int)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt index 69a67571e7..88fc72f3a3 100644 --- a/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt @@ -50,8 +50,8 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool?), "boolean", new }); private static readonly global::TUnit.Core.MethodMetadata __mm_5 = global::TUnit.Core.MethodMetadataFactory.Create("ImplicitConversion", __classType, typeof(global::System.Threading.Tasks.Task), __classMetadata, parameters: new global::TUnit.Core.ParameterMetadata[] { -global::TUnit.Core.ParameterMetadataFactory.Create(typeof(OneOf), "enum", new global::TUnit.Core.ConcreteType(typeof(OneOf)), false, reflectionInfoFactory: static () => typeof(global::TUnit.TestProject.MatrixTests).GetMethod("ImplicitConversion", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(OneOf), typeof(bool) }, null)!.GetParameters()[0]), -global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "boolean", new global::TUnit.Core.ConcreteType(typeof(bool)), false, reflectionInfoFactory: static () => typeof(global::TUnit.TestProject.MatrixTests).GetMethod("ImplicitConversion", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(OneOf), typeof(bool) }, null)!.GetParameters()[1]) +global::TUnit.Core.ParameterMetadataFactory.Create(typeof(OneOf), "enum", new global::TUnit.Core.ConcreteType(typeof(OneOf)), false, reflectionInfoFactory: static () => typeof(global::TUnit.TestProject.MatrixTests).GetMethod("ImplicitConversion", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(OneOf), typeof(bool) }, null)!.GetParameters()[0]), +global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "boolean", new global::TUnit.Core.ConcreteType(typeof(bool)), false, reflectionInfoFactory: static () => typeof(global::TUnit.TestProject.MatrixTests).GetMethod("ImplicitConversion", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(OneOf), typeof(bool) }, null)!.GetParameters()[1]) }); private static readonly global::TUnit.Core.MethodMetadata __mm_6 = global::TUnit.Core.MethodMetadataFactory.Create("ExcludingAutoGeneratedMatrixValues", __classType, typeof(global::System.Threading.Tasks.Task), __classMetadata, parameters: new global::TUnit.Core.ParameterMetadata[] { @@ -100,7 +100,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One((string)args[0], (int)args[1], (bool)args[2])); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 4: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two((int)args[0], (int)args[1], (int)args[2], (bool)args[3])); } default: throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); @@ -138,7 +138,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 3: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum((int)args[0], (args[1] switch { global::TUnit.TestProject.TestEnum __s => __s, int __s => (global::TUnit.TestProject.TestEnum)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[1]) }), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]))); } default: throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); @@ -157,7 +157,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools((string)args[0], (bool)args[1])); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -176,7 +176,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2((string)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -195,7 +195,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.ImplicitConversion(global::TUnit.Core.Helpers.CastHelper.Cast>(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.ImplicitConversion((args[0] switch { global::TUnit.TestProject.TestEnum __s => global::TUnit.Core.Helpers.CastHelper.Cast>(__s), global::TUnit.TestProject.TestEnum2 __s => global::TUnit.Core.Helpers.CastHelper.Cast>(__s), _ => global::TUnit.Core.Helpers.CastHelper.Cast>(args[0]) }), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); @@ -328,7 +328,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::TUnit.TestProj { case 2: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixMethod_WithEnumParameter_UsesOnlyMethodValues((bool)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1]))); } default: throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/MatrixTests.cs b/TUnit.Core.SourceGenerator.Tests/MatrixTests.cs index 8b545cc6df..d03a26e99a 100644 --- a/TUnit.Core.SourceGenerator.Tests/MatrixTests.cs +++ b/TUnit.Core.SourceGenerator.Tests/MatrixTests.cs @@ -14,7 +14,10 @@ public Task Test() => RunTest(Path.Combine(Git.RootDirectory.FullName, [ Path.Combine(Git.RootDirectory.FullName, "TUnit.TestProject", - "TestEnum.cs") + "TestEnum.cs"), + Path.Combine(Git.RootDirectory.FullName, + "TUnit.TestProject", + "TestEnum2.cs") ] }, async generatedFiles => diff --git a/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt index e8701ea576..c4bb0888ea 100644 --- a/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -30,7 +30,7 @@ internal static class TUnit_TestProject_MultipleClassDataSourceDrivenTests__Test private static readonly global::TUnit.Core.MethodMetadata __mm_1 = global::TUnit.Core.MethodMetadataFactory.Create("Test2", __classType, typeof(void), __classMetadata); private static global::TUnit.TestProject.MultipleClassDataSourceDrivenTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.MultipleClassDataSourceDrivenTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4])); + return new global::TUnit.TestProject.MultipleClassDataSourceDrivenTests((global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject1)args[0], (global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject2)args[1], (global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject3)args[2], (global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject4)args[3], (global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject5)args[4]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { diff --git a/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt index df8a04147c..03ba384fee 100644 --- a/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt @@ -39,7 +39,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "name", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.TestName(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.TestName((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt index a72bd1f019..7086bacb6a 100644 --- a/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt @@ -64,7 +64,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(byte?), "byte2", new g { case 2: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); + instance.Test2((byte)args[0], global::TUnit.Core.Helpers.CastHelper.Cast(args[1])); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt index ec2d51d119..fcb9d8ff71 100644 --- a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt @@ -59,7 +59,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Int(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Int((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -79,7 +79,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Double(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Double((double)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -99,7 +99,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Float(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Float((float)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Long(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Long((long)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -139,7 +139,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.ULong(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.ULong((ulong)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -159,7 +159,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.UInt(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.UInt((uint)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt index ec2d51d119..fcb9d8ff71 100644 --- a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt @@ -59,7 +59,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Int(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Int((int)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -79,7 +79,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Double(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Double((double)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -99,7 +99,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Float(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Float((float)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -119,7 +119,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.Long(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Long((long)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -139,7 +139,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.ULong(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.ULong((ulong)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -159,7 +159,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(uint), "i", new global { case 1: { - instance.UInt(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.UInt((uint)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.Net4_7.verified.txt index 008d7c89a1..7b75d88de4 100644 --- a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.Net4_7.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable diff --git a/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt index f9e9b93a72..1493f9b6dc 100644 --- a/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt @@ -43,7 +43,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "s", new glob { case 1: { - instance.Normal(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Normal((string)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt index 5f282702bb..e69de29bb2 100644 --- a/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/TestDiscoveryHookTests.Test.verified.txt @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt index 60956f2ede..06f10639c1 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt @@ -87,7 +87,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "input", new { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.TryParse_ValidString_ReturnsAccountId(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.TryParse_ValidString_ReturnsAccountId((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt index a64949adef..9da3cd10e8 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -25,7 +25,7 @@ internal static class TUnit_TestProject_Bugs__1589_MyTests__TestSource private static readonly global::TUnit.Core.MethodMetadata __mm_0 = global::TUnit.Core.MethodMetadataFactory.Create("Test1", __classType, typeof(global::System.Threading.Tasks.Task), __classMetadata); private static global::TUnit.TestProject.Bugs._1589.MyTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.Bugs._1589.MyTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.Bugs._1589.MyTests((global::TUnit.TestProject.Bugs._1589.MyFixture)args[0]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.Bugs._1589.MyTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt index 7fc58c8b28..5b9642b72e 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -25,7 +25,7 @@ internal static class TUnit_TestProject_Bugs__1594_MyTests__TestSource private static readonly global::TUnit.Core.MethodMetadata __mm_0 = global::TUnit.Core.MethodMetadataFactory.Create("Test1", __classType, typeof(void), __classMetadata); private static global::TUnit.TestProject.Bugs._1594.MyTests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.Bugs._1594.MyTests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.Bugs._1594.MyTests((global::TUnit.TestProject.Bugs._1594.MyFixture)args[0]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.Bugs._1594.MyTests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt index eebed70f39..e8d71996b2 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt @@ -43,7 +43,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(short), "value", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Casted_Integer_To_Short_Converts(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Casted_Integer_To_Short_Converts((short)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -62,7 +62,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(short), "value", new g { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Integer_To_Short_Converts(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Integer_To_Short_Converts((short)(int)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt index d9ab80e920..7a6b824432 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt @@ -32,7 +32,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "value", new }); private static global::TUnit.TestProject.Bugs._1821.Tests __CreateInstance(global::System.Type[] typeArgs, object?[] args) { - return new global::TUnit.TestProject.Bugs._1821.Tests(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return new global::TUnit.TestProject.Bugs._1821.Tests((global::TUnit.TestProject.Bugs._1821.MyData)args[0]); } private static global::System.Threading.Tasks.ValueTask __Invoke(global::TUnit.TestProject.Bugs._1821.Tests instance, int methodIndex, object?[] args, global::System.Threading.CancellationToken cancellationToken) { @@ -65,7 +65,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(string), "value", new { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixDataSource(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixDataSource((string)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet10_0.verified.txt index e12b6432db..d88983e6d4 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet10_0.verified.txt @@ -112,7 +112,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test2((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -205,7 +205,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test3(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test3((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet8_0.verified.txt index e12b6432db..d88983e6d4 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet8_0.verified.txt @@ -112,7 +112,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test2((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -205,7 +205,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test3(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test3((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet9_0.verified.txt index e12b6432db..d88983e6d4 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet9_0.verified.txt @@ -112,7 +112,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test2((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -205,7 +205,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test3(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test3((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.Net4_7.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.Net4_7.verified.txt index 862d9edb8b..b538655288 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.Net4_7.verified.txt @@ -112,7 +112,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test2((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -205,7 +205,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(bool), "condition", ne { case 1: { - instance.Test3(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.Test3((bool)args[0]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt index 5f282702bb..e69de29bb2 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1899.BaseClass.verified.txt @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt index 5f282702bb..e69de29bb2 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2075.Test.verified.txt @@ -1 +0,0 @@ - \ No newline at end of file diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt index 465569e292..fcc71ab5ec 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt @@ -1,4 +1,4 @@ -// +// #pragma warning disable #nullable enable @@ -39,7 +39,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(long), "value", new gl { case 1: { - instance.MyTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0])); + instance.MyTest((args[0] switch { byte __s => (long)__s, char __s => (long)__s, int __s => (long)__s, long __s => __s, short __s => (long)__s, _ => global::TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt index bc619a2256..4ba36e77d9 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt @@ -43,7 +43,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(float), "d", new globa { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Double_SpecialConsts(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Double_SpecialConsts((double)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -62,7 +62,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(float), "d", new globa { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.Float_SpecialConsts(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + return new global::System.Threading.Tasks.ValueTask(instance.Float_SpecialConsts((float)args[0])); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt index 546d777591..b734cce4bc 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt @@ -45,37 +45,37 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(long[]), "arr", new gl { case 1: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[0]); + instance.Test((int)args[0], new long[0]); return default(global::System.Threading.Tasks.ValueTask); } case 2: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]) })); + instance.Test((int)args[0], (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { (long)args[1] })); return default(global::System.Threading.Tasks.ValueTask); } case 3: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); + instance.Test((int)args[0], new long[] { (long)args[1], (long)args[2] }); return default(global::System.Threading.Tasks.ValueTask); } case 4: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); + instance.Test((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3] }); return default(global::System.Threading.Tasks.ValueTask); } case 5: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); + instance.Test((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3], (long)args[4] }); return default(global::System.Threading.Tasks.ValueTask); } case 6: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), global::TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); + instance.Test((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3], (long)args[4], (long)args[5] }); return default(global::System.Threading.Tasks.ValueTask); } case 7: { - instance.Test(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), global::TUnit.Core.Helpers.CastHelper.Cast(args[5]), global::TUnit.Core.Helpers.CastHelper.Cast(args[6]) }); + instance.Test((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3], (long)args[4], (long)args[5], (long)args[6] }); return default(global::System.Threading.Tasks.ValueTask); } default: @@ -95,37 +95,37 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(long[]), "arr", new gl { case 1: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[0]); + instance.Test2((int)args[0], new long[0]); return default(global::System.Threading.Tasks.ValueTask); } case 2: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]) })); + instance.Test2((int)args[0], (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { (long)args[1] })); return default(global::System.Threading.Tasks.ValueTask); } case 3: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); + instance.Test2((int)args[0], new long[] { (long)args[1], (long)args[2] }); return default(global::System.Threading.Tasks.ValueTask); } case 4: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); + instance.Test2((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3] }); return default(global::System.Threading.Tasks.ValueTask); } case 5: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); + instance.Test2((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3], (long)args[4] }); return default(global::System.Threading.Tasks.ValueTask); } case 6: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), global::TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); + instance.Test2((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3], (long)args[4], (long)args[5] }); return default(global::System.Threading.Tasks.ValueTask); } case 7: { - instance.Test2(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2]), global::TUnit.Core.Helpers.CastHelper.Cast(args[3]), global::TUnit.Core.Helpers.CastHelper.Cast(args[4]), global::TUnit.Core.Helpers.CastHelper.Cast(args[5]), global::TUnit.Core.Helpers.CastHelper.Cast(args[6]) }); + instance.Test2((int)args[0], new long[] { (long)args[1], (long)args[2], (long)args[3], (long)args[4], (long)args[5], (long)args[6] }); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator.Tests/TestsBase.cs b/TUnit.Core.SourceGenerator.Tests/TestsBase.cs index 91ff554b83..8e44857d42 100644 --- a/TUnit.Core.SourceGenerator.Tests/TestsBase.cs +++ b/TUnit.Core.SourceGenerator.Tests/TestsBase.cs @@ -16,7 +16,6 @@ protected TestsBase() } public TestsBase TestMetadataGenerator = new(); - public TestsBase AotConverterGenerator = new(); public TestsBase HooksGenerator = new(); public TestsBase InfrastructureGenerator = new(); public TestsBase DynamicTestsGenerator = new(); diff --git a/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt index 1e3f6fac51..6f41093178 100644 --- a/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt @@ -99,7 +99,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Threadi { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.DataTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.Execution.CancellationToken ?? global::System.Threading.CancellationToken.None)); + return new global::System.Threading.Tasks.ValueTask(instance.DataTest((int)args[0], context?.Execution.CancellationToken ?? global::System.Threading.CancellationToken.None)); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); @@ -139,7 +139,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(global::System.Threadi { case 1: { - return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.Execution.CancellationToken ?? global::System.Threading.CancellationToken.None)); + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest((int)args[0], context?.Execution.CancellationToken ?? global::System.Threading.CancellationToken.None)); } default: throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); diff --git a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt index 80bc533698..1c3a252f7b 100644 --- a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt @@ -41,7 +41,7 @@ global::TUnit.Core.ParameterMetadataFactory.Create(typeof(int), "c", new global: { case 3: { - instance.TestWithDataSource(global::TUnit.Core.Helpers.CastHelper.Cast(args[0]), global::TUnit.Core.Helpers.CastHelper.Cast(args[1]), global::TUnit.Core.Helpers.CastHelper.Cast(args[2])); + instance.TestWithDataSource((int)args[0], (int)args[1], (int)args[2]); return default(global::System.Threading.Tasks.ValueTask); } default: diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/CastExpressionHelper.cs b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/CastExpressionHelper.cs new file mode 100644 index 0000000000..7b51601e23 --- /dev/null +++ b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/CastExpressionHelper.cs @@ -0,0 +1,198 @@ +using System; +using System.Collections.Generic; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using TUnit.Core.SourceGenerator.Extensions; + +namespace TUnit.Core.SourceGenerator.CodeGenerators.Helpers; + +internal static class CastExpressionHelper +{ + /// + /// Dispatches to the appropriate cast generation strategy based on the source type info at the given position. + /// When is provided, it is used as the source type for unknown positions + /// instead of falling back to CastHelper.Cast (useful for params elements where the element type is statically known). + /// + public static string GenerateCastForPosition( + SourceTypeInfo? sourceTypeInfo, + int position, + ITypeSymbol targetType, + string argsExpression, + CSharpCompilation? compilation, + ITypeSymbol? fallbackSourceType = null) + { + if (sourceTypeInfo != null) + { + var types = sourceTypeInfo.GetTypes(position); + + if (types != null) + { + if (types.Count == 1) + { + return GenerateCast(types[0], targetType, argsExpression, compilation); + } + + return GenerateMultiSourceCast(types, targetType, argsExpression, compilation); + } + } + + // Unknown type at this position + return GenerateCast(fallbackSourceType, targetType, argsExpression, compilation); + } + + /// + /// Generates a pattern-matching switch expression for positions with multiple known source types. + /// Each source type gets its own pattern match arm with the appropriate cast. + /// The default arm handles any unexpected types via direct cast. + /// + public static string GenerateMultiSourceCast( + IReadOnlyList sourceTypes, + ITypeSymbol targetType, + string argsExpression, + CSharpCompilation? compilation) + { + var targetGQ = targetType.GloballyQualified(); + var arms = new List(); + + // Sort source types so that derived types come before their base types. + // Without this, a base type pattern arm would catch derived instances first, + // causing CS8510 "unreachable pattern" errors. + var sorted = SortMostDerivedFirst(sourceTypes); + + // In switch arms the pattern match performs the unbox, so only a single cast + // to the target type is needed (unlike GenerateCast which needs a double-cast + // (TargetType)(SourceType)expr to first unbox then convert). + foreach (var sourceType in sorted) + { + var sourceGQ = sourceType.GloballyQualified(); + + if (SymbolEqualityComparer.Default.Equals(sourceType, targetType)) + { + arms.Add($"{sourceGQ} __s => __s"); + } + else if (compilation != null && compilation.ClassifyConversion(sourceType, targetType) is { IsImplicit: true } or { IsExplicit: true }) + { + arms.Add($"{sourceGQ} __s => ({targetGQ})__s"); + } + else + { + arms.Add($"{sourceGQ} __s => global::TUnit.Core.Helpers.CastHelper.Cast<{targetGQ}>(__s)"); + } + } + + arms.Add($"_ => global::TUnit.Core.Helpers.CastHelper.Cast<{targetGQ}>({argsExpression})"); + + return $"({argsExpression} switch {{ {string.Join(", ", arms)} }})"; + } + + private static List SortMostDerivedFirst(IReadOnlyList types) + { + var result = new List(types); + + result.Sort((a, b) => + { + if (SymbolEqualityComparer.Default.Equals(a, b)) + { + return 0; + } + + if (IsBaseTypeOf(a, b)) + { + return 1; + } + + if (IsBaseTypeOf(b, a)) + { + return -1; + } + + // Deterministic tiebreaker for unrelated types to satisfy Introsort's total-order requirement + return string.Compare(a.ToDisplayString(), b.ToDisplayString(), StringComparison.Ordinal); + }); + + return result; + } + + private static bool IsBaseTypeOf(ITypeSymbol potentialBase, ITypeSymbol derived) + { + var current = derived.BaseType; + + while (current != null) + { + if (SymbolEqualityComparer.Default.Equals(current, potentialBase)) + { + return true; + } + + current = current.BaseType; + } + + return false; + } + + /// + /// Generates a typed cast expression, or falls back to CastHelper.Cast when source type is unknown. + /// + public static string GenerateCast( + ITypeSymbol? sourceType, + ITypeSymbol targetType, + string argsExpression, + CSharpCompilation? compilation) + { + var targetGQ = targetType.GloballyQualified(); + + // Unknown source or no compilation → CastHelper fallback + if (sourceType == null || compilation == null) + { + return $"global::TUnit.Core.Helpers.CastHelper.Cast<{targetGQ}>({argsExpression})"; + } + + // Same type → simple cast (unbox for value types, reference cast for reference types) + if (SymbolEqualityComparer.Default.Equals(sourceType, targetType)) + { + return $"({targetGQ}){argsExpression}"; + } + + if (IsDecimalLike(targetType) && !IsDecimalLike(sourceType)) + { + return $"global::TUnit.Core.Helpers.CastHelper.Cast<{targetGQ}>({argsExpression})"; + } + + // Check if compiler can resolve conversion + var conversion = compilation.ClassifyConversion(sourceType, targetType); + + // Boxing to object/ValueType/Enum: args[i] is already typed correctly, no cast needed. + // Do NOT skip the cast for boxing-to-interface (e.g. int → IComparable) — + // args[i] is object?, which cannot be implicitly converted to an interface type. + if (conversion.IsBoxing + && targetType.SpecialType is SpecialType.System_Object + or SpecialType.System_ValueType + or SpecialType.System_Enum) + { + return argsExpression; + } + + if (conversion.IsImplicit || conversion.IsExplicit) + { + var sourceGQ = sourceType.GloballyQualified(); + return $"({targetGQ})({sourceGQ}){argsExpression}"; + } + + // No known conversion → CastHelper fallback + return $"global::TUnit.Core.Helpers.CastHelper.Cast<{targetGQ}>({argsExpression})"; + } + + private static bool IsDecimalLike(ITypeSymbol type) + { + if (type.SpecialType == SpecialType.System_Decimal) + { + return true; + } + + return type is INamedTypeSymbol + { + ConstructedFrom.SpecialType: SpecialType.System_Nullable_T, + TypeArguments: [{ SpecialType: SpecialType.System_Decimal }] + }; + } +} diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/DataSourceAttributeHelper.cs b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/DataSourceAttributeHelper.cs index 935fec6b69..60bcd038c6 100644 --- a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/DataSourceAttributeHelper.cs +++ b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/DataSourceAttributeHelper.cs @@ -5,6 +5,9 @@ namespace TUnit.Core.SourceGenerator.CodeGenerators.Helpers; internal static class DataSourceAttributeHelper { + // GloballyQualified() emits open generics as Foo<>, not Foo`1 + private const string TypedDataSourceInterfacePattern = "global::TUnit.Core.ITypedDataSourceAttribute<>"; + public static bool IsDataSourceAttribute(INamedTypeSymbol? attributeClass) { if (attributeClass == null) @@ -12,7 +15,6 @@ public static bool IsDataSourceAttribute(INamedTypeSymbol? attributeClass) return false; } - // Check if the attribute implements IDataSourceAttribute (using cache) return InterfaceCache.ImplementsInterface(attributeClass, "global::TUnit.Core.IDataSourceAttribute"); } @@ -23,8 +25,7 @@ public static bool IsTypedDataSourceAttribute(INamedTypeSymbol? attributeClass) return false; } - // Check if the attribute implements ITypedDataSourceAttribute (using cache) - return InterfaceCache.ImplementsGenericInterface(attributeClass, "global::TUnit.Core.ITypedDataSourceAttribute`1"); + return InterfaceCache.ImplementsGenericInterface(attributeClass, TypedDataSourceInterfacePattern); } public static ITypeSymbol? GetTypedDataSourceType(INamedTypeSymbol? attributeClass) @@ -34,7 +35,7 @@ public static bool IsTypedDataSourceAttribute(INamedTypeSymbol? attributeClass) return null; } - var typedInterface = InterfaceCache.GetGenericInterface(attributeClass, "global::TUnit.Core.ITypedDataSourceAttribute`1"); + var typedInterface = InterfaceCache.GetGenericInterface(attributeClass, TypedDataSourceInterfacePattern); return typedInterface?.TypeArguments.FirstOrDefault(); } diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/InstanceFactoryGenerator.cs b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/InstanceFactoryGenerator.cs index f7fa4ae085..e0de514f6b 100644 --- a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/InstanceFactoryGenerator.cs +++ b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/InstanceFactoryGenerator.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using TUnit.Core.SourceGenerator.Extensions; using TUnit.Core.SourceGenerator.Models; @@ -198,7 +199,7 @@ public static void GenerateInstanceFactoryAsMethod(CodeWriter writer, ITypeSymbo /// Used by the per-class helper pipeline where ISymbol is available during the transform step /// but not during source output. /// - public static string GenerateInstanceFactoryBody(ITypeSymbol typeSymbol) + public static string GenerateInstanceFactoryBody(ITypeSymbol typeSymbol, CSharpCompilation? compilation = null) { var bodyWriter = new CodeWriter(includeHeader: false); var className = typeSymbol.GloballyQualified(); @@ -212,7 +213,8 @@ public static string GenerateInstanceFactoryBody(ITypeSymbol typeSymbol) var constructor = GetPrimaryConstructor(typeSymbol); if (constructor != null) { - GenerateTypedConstructorCallBody(bodyWriter, className, constructor); + var sourceTypes = SourceTypeAnalyzer.GetConstructorParameterSourceTypes(typeSymbol as INamedTypeSymbol); + GenerateTypedConstructorCallBody(bodyWriter, className, constructor, sourceTypes, compilation); } else { @@ -247,7 +249,7 @@ public static string GenerateInstanceFactoryBody(ITypeSymbol typeSymbol) return bodyWriter.ToString(); } - private static IMethodSymbol? GetPrimaryConstructor(ITypeSymbol typeSymbol) + internal static IMethodSymbol? GetPrimaryConstructor(ITypeSymbol typeSymbol) { // Materialize constructors once to avoid multiple enumerations var constructors = typeSymbol.GetMembers() @@ -287,7 +289,7 @@ private static void GenerateTypedConstructorCall(CodeWriter writer, string class writer.AppendLine("},"); } - private static void GenerateTypedConstructorCallBody(CodeWriter writer, string className, IMethodSymbol constructor) + private static void GenerateTypedConstructorCallBody(CodeWriter writer, string className, IMethodSymbol constructor, SourceTypeInfo? sourceTypeInfo = null, CSharpCompilation? compilation = null) { // Check for required properties var requiredProperties = RequiredPropertyHelper.GetAllRequiredProperties(constructor.ContainingType); @@ -313,8 +315,8 @@ private static void GenerateTypedConstructorCallBody(CodeWriter writer, string c var parameterType = parameterTypes[i]; var argAccess = $"args[{i}]"; - // Use CastHelper which now has AOT converter registry support - writer.Append($"global::TUnit.Core.Helpers.CastHelper.Cast<{parameterType.GloballyQualified()}>({argAccess})"); + writer.Append(CastExpressionHelper.GenerateCastForPosition( + sourceTypeInfo, i, parameterType, argAccess, compilation)); } writer.Append(")"); diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/SourceTypeAnalyzer.cs b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/SourceTypeAnalyzer.cs new file mode 100644 index 0000000000..4daf7ed0f7 --- /dev/null +++ b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/SourceTypeAnalyzer.cs @@ -0,0 +1,482 @@ +using System.Collections.Immutable; +using Microsoft.CodeAnalysis; + +namespace TUnit.Core.SourceGenerator.CodeGenerators.Helpers; + +/// +/// Holds per-position source type information for data source attributes. +/// Each position may have zero, one, or multiple possible source types. +/// A null entry at a position means the type is unknown (falls back to CastHelper.Cast). +/// +internal sealed class SourceTypeInfo +{ + private readonly IReadOnlyList?[] _typesPerPosition; + + public SourceTypeInfo(IReadOnlyList?[] typesPerPosition) + { + _typesPerPosition = typesPerPosition; + } + + public int Length => _typesPerPosition.Length; + + /// + /// Returns all known source types at the given position, or null if unknown/out-of-range. + /// + public IReadOnlyList? GetTypes(int index) + { + return (uint)index < (uint)_typesPerPosition.Length ? _typesPerPosition[index] : null; + } +} + +internal static class SourceTypeAnalyzer +{ + /// + /// Analyzes data source attributes on a method to determine the compile-time source type + /// for each parameter position. Returns null if no data sources exist. + /// A null entry at a position means that position's source type is unknown (falls back to CastHelper.Cast). + /// + public static SourceTypeInfo? GetMethodParameterSourceTypes(IMethodSymbol method) + { + var dataSources = new List(); + + foreach (var attr in method.GetAttributes()) + { + if (!DataSourceAttributeHelper.IsDataSourceAttribute(attr.AttributeClass)) + { + continue; + } + + dataSources.Add(attr); + } + + // No data sources at all -> no source type info + if (dataSources.Count == 0) + { + return null; + } + + // Filter to non-CancellationToken parameters + var parameterCount = 0; + var hasParams = false; + foreach (var p in method.Parameters) + { + if (p.Type.Name != "CancellationToken" || p.Type.ContainingNamespace?.ToString() != "System.Threading") + { + parameterCount++; + if (p.IsParams) + { + hasParams = true; + } + } + } + + if (parameterCount == 0) + { + return null; + } + + // For params methods with [Arguments], size the array to max argument count + var arraySize = hasParams ? GetMaxArgumentCount(dataSources, parameterCount) : parameterCount; + + return ExtractSourceTypesFromAllAttributes(dataSources, arraySize, method.Parameters); + } + + /// + /// Analyzes class-level data source attributes to determine source types for constructor parameters. + /// + public static SourceTypeInfo? GetConstructorParameterSourceTypes(INamedTypeSymbol? classType) + { + if (classType == null) + { + return null; + } + + var dataSources = new List(); + + foreach (var attr in classType.GetAttributes()) + { + if (!DataSourceAttributeHelper.IsDataSourceAttribute(attr.AttributeClass)) + { + continue; + } + + dataSources.Add(attr); + } + + if (dataSources.Count == 0) + { + return null; + } + + // Use the same constructor selection as InstanceFactoryGenerator to ensure + // source type analysis targets the constructor that will actually be called. + var constructor = InstanceFactoryGenerator.GetPrimaryConstructor(classType); + + if (constructor == null || constructor.Parameters.Length == 0) + { + return null; + } + + var ctorParamCount = constructor.Parameters.Length; + var ctorHasParams = constructor.Parameters[ctorParamCount - 1].IsParams; + var ctorArraySize = ctorHasParams ? GetMaxArgumentCount(dataSources, ctorParamCount) : ctorParamCount; + + return ExtractSourceTypesFromAllAttributes(dataSources, ctorArraySize, constructor.Parameters); + } + + /// + /// Processes ALL data source attributes and merges per-position source types. + /// + private static SourceTypeInfo ExtractSourceTypesFromAllAttributes( + List dataSources, + int parameterCount, + ImmutableArray parameters) + { + // Each position accumulates a set of possible source types. + // null = unknown (some attribute couldn't determine the type for this position). + var positionTypes = new List?[parameterCount]; + var positionUnknown = new bool[parameterCount]; + + foreach (var attr in dataSources) + { + if (IsArgumentsAttribute(attr)) + { + ProcessArgumentsAttribute(attr, positionTypes, positionUnknown, parameterCount); + } + else if (attr.AttributeClass != null && DataSourceAttributeHelper.IsTypedDataSourceAttribute(attr.AttributeClass)) + { + ProcessTypedDataSource(attr, positionTypes, positionUnknown, parameterCount); + } + else if (IsMatrixDataSourceAttribute(attr)) + { + ProcessMatrixDataSource(parameters, positionTypes, positionUnknown, parameterCount); + } + else + { + // Unknown data source type (e.g., MethodDataSource, non-generic ClassDataSource + // without typeof args) -> mark ALL positions as unknown + for (var i = 0; i < parameterCount; i++) + { + positionUnknown[i] = true; + } + } + } + + // Build the final result: null entries where unknown + var result = new IReadOnlyList?[parameterCount]; + for (var i = 0; i < parameterCount; i++) + { + if (positionUnknown[i] || positionTypes[i] == null || positionTypes[i]!.Count == 0) + { + result[i] = null; + } + else + { + result[i] = positionTypes[i]; + } + } + + return new SourceTypeInfo(result); + } + + private static void ProcessArgumentsAttribute( + AttributeData attr, + List?[] positionTypes, + bool[] positionUnknown, + int parameterCount) + { + var values = GetArgumentValues(attr); + + if (values == null) + { + // Can't extract values from this attribute -> mark all positions as unknown + for (var i = 0; i < parameterCount; i++) + { + positionUnknown[i] = true; + } + + return; + } + + for (var i = 0; i < parameterCount && i < values.Value.Length; i++) + { + if (positionUnknown[i]) + { + continue; + } + + var tc = values.Value[i]; + + // Null literal or error -> unknown source type for this position + if (tc.IsNull || tc.Kind == TypedConstantKind.Error || tc.Type == null) + { + positionUnknown[i] = true; + continue; + } + + AddTypeToPosition(positionTypes, i, tc.Type); + } + } + + /// + /// Processes any attribute implementing ITypedDataSourceAttribute<T>. + /// For single-generic attributes (e.g., ClassDataSourceAttribute<T>), T maps to position 0. + /// For multi-generic attributes, each type argument maps to its corresponding position. + /// Works with ClassDataSourceAttribute<T> and any user-created custom data source + /// that extends TypedDataSourceAttribute<T>. + /// + private static void ProcessTypedDataSource( + AttributeData attr, + List?[] positionTypes, + bool[] positionUnknown, + int parameterCount) + { + var attrClass = attr.AttributeClass; + + if (attrClass == null) + { + return; + } + + if (attrClass.IsGenericType) + { + var typeArgs = attrClass.TypeArguments; + + if (typeArgs.Length == 1) + { + // Single generic: e.g., ClassDataSourceAttribute -> T maps to position 0 + var sourceType = DataSourceAttributeHelper.GetTypedDataSourceType(attrClass); + + if (sourceType != null && parameterCount > 0 && !positionUnknown[0]) + { + AddTypeToPosition(positionTypes, 0, sourceType); + } + } + else + { + // Multi-generic: e.g., ClassDataSourceAttribute -> each Tn maps to position n + for (var i = 0; i < parameterCount && i < typeArgs.Length; i++) + { + if (positionUnknown[i]) + { + continue; + } + + var typeArg = typeArgs[i]; + + if (typeArg is IErrorTypeSymbol) + { + positionUnknown[i] = true; + } + else + { + AddTypeToPosition(positionTypes, i, typeArg); + } + } + } + } + else + { + // Non-generic typed data source: try to extract T from ITypedDataSourceAttribute + var sourceType = DataSourceAttributeHelper.GetTypedDataSourceType(attrClass); + + if (sourceType != null && parameterCount > 0 && !positionUnknown[0]) + { + AddTypeToPosition(positionTypes, 0, sourceType); + } + else + { + // Can't determine source type statically -> mark all positions as unknown + for (var i = 0; i < parameterCount; i++) + { + positionUnknown[i] = true; + } + } + } + } + + /// + /// Adds a source type to the given position, deduplicating with SymbolEqualityComparer. + /// + private static void AddTypeToPosition(List?[] positionTypes, int index, ITypeSymbol type) + { + if (positionTypes[index] == null) + { + positionTypes[index] = new List { type }; + return; + } + + // Deduplicate + foreach (var existing in positionTypes[index]!) + { + if (SymbolEqualityComparer.Default.Equals(existing, type)) + { + return; + } + } + + positionTypes[index]!.Add(type); + } + + private static int GetMaxArgumentCount(List dataSources, int baseCount) + { + foreach (var attr in dataSources) + { + if (!IsArgumentsAttribute(attr)) + { + continue; + } + + var values = GetArgumentValues(attr); + if (values != null && values.Value.Length > baseCount) + { + baseCount = values.Value.Length; + } + } + + return baseCount; + } + + /// + /// Extracts the TypedConstant values from an [Arguments] attribute. + /// For non-generic: ConstructorArguments[0] is a params array. + /// For generic (Arguments<T>): ConstructorArguments[0] is the single typed value. + /// + private static ImmutableArray? GetArgumentValues(AttributeData attr) + { + if (attr.ConstructorArguments.Length == 0) + { + return null; + } + + var firstArg = attr.ConstructorArguments[0]; + + // Non-generic [Arguments(params object?[] args)] — the first arg is an array + if (firstArg.Kind == TypedConstantKind.Array) + { + return firstArg.Values.IsDefault ? null : firstArg.Values; + } + + // Generic [Arguments(T value)] — single typed value + // Return all constructor args as individual values + return attr.ConstructorArguments; + } + + private static bool IsArgumentsAttribute(AttributeData attr) + { + return attr.AttributeClass?.Name is "ArgumentsAttribute" + && attr.AttributeClass.ToDisplayString() == WellKnownFullyQualifiedClassNames.ArgumentsAttribute.WithoutGlobalPrefix; + } + + /// + /// Returns true if the type is an enum or Nullable<TEnum>. + /// MatrixDataSource boxes auto-generated enum values as their underlying type (via + /// Enum.GetValuesAsUnderlyingType), so direct casts from object to enum type would fail. + /// + private static bool IsEnumLike(ITypeSymbol type) + { + if (type.TypeKind == TypeKind.Enum) + { + return true; + } + + // Check for Nullable + if (type is INamedTypeSymbol { IsGenericType: true, ConstructedFrom.SpecialType: SpecialType.System_Nullable_T } nullable) + { + return nullable.TypeArguments[0].TypeKind == TypeKind.Enum; + } + + return false; + } + + private static bool IsMatrixDataSourceAttribute(AttributeData attr) + { + return attr.AttributeClass?.Name is "MatrixDataSourceAttribute"; + } + + /// + /// Processes a MatrixDataSource by examining per-parameter [Matrix] attributes + /// to extract the compile-time source types for each position. + /// + private static void ProcessMatrixDataSource( + ImmutableArray parameters, + List?[] positionTypes, + bool[] positionUnknown, + int parameterCount) + { + var paramIndex = 0; + + foreach (var param in parameters) + { + if (paramIndex >= parameterCount) + { + break; + } + + // Skip CancellationToken parameters (same filter as caller) + if (param.Type.Name == "CancellationToken" && param.Type.ContainingNamespace?.ToString() == "System.Threading") + { + continue; + } + + if (positionUnknown[paramIndex]) + { + paramIndex++; + continue; + } + + var hasMatrixAttr = false; + + foreach (var paramAttr in param.GetAttributes()) + { + if (paramAttr.AttributeClass?.Name is not ("MatrixAttribute" or "MatrixMethodAttribute" or "MatrixRangeAttribute")) + { + continue; + } + + hasMatrixAttr = true; + + // MatrixMethod and MatrixRange don't have compile-time values we can extract + if (paramAttr.AttributeClass.Name is "MatrixMethodAttribute" or "MatrixRangeAttribute") + { + positionUnknown[paramIndex] = true; + break; + } + + // Extract value types from [Matrix(val1, val2, ...)] constructor args + if (paramAttr.ConstructorArguments.Length == 0) + { + continue; + } + + var firstArg = paramAttr.ConstructorArguments[0]; + + if (firstArg.Kind == TypedConstantKind.Array && !firstArg.Values.IsDefault) + { + foreach (var val in firstArg.Values) + { + if (val.IsNull || val.Kind == TypedConstantKind.Error || val.Type == null) + { + positionUnknown[paramIndex] = true; + break; + } + + AddTypeToPosition(positionTypes, paramIndex, val.Type); + } + } + } + + // No [Matrix] attribute on this parameter -> auto-generated (bool/enum). + // For bool: runtime type is bool, so direct cast works. + // For enum: MatrixDataSource uses Enum.GetValuesAsUnderlyingType which boxes as the + // underlying type (e.g., int), NOT the enum type. Direct cast (EnumType)args[n] + // would fail at runtime, so we must fall back to CastHelper for enums. + if (!hasMatrixAttr && !positionUnknown[paramIndex] && !IsEnumLike(param.Type)) + { + AddTypeToPosition(positionTypes, paramIndex, param.Type); + } + + paramIndex++; + } + } +} diff --git a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/TupleArgumentHelper.cs b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/TupleArgumentHelper.cs index ec78c7f4d3..f2a0f166ba 100644 --- a/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/TupleArgumentHelper.cs +++ b/TUnit.Core.SourceGenerator/CodeGenerators/Helpers/TupleArgumentHelper.cs @@ -1,38 +1,35 @@ using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; using TUnit.Core.SourceGenerator.Extensions; namespace TUnit.Core.SourceGenerator.CodeGenerators.Helpers; -public static class TupleArgumentHelper +internal static class TupleArgumentHelper { - /// - /// Generates method invocation arguments. - /// - /// The method parameters - /// The name of the arguments array - /// Comma-separated argument expressions for method invocation - public static string GenerateMethodInvocationArguments(IList parameters, string argumentsArrayName) + public static string GenerateMethodInvocationArguments( + IList parameters, + string argumentsArrayName, + SourceTypeInfo? sourceTypeInfo = null, + CSharpCompilation? compilation = null) { var allArguments = new List(); for (var i = 0; i < parameters.Count; i++) { var parameter = parameters[i]; - var castExpression = $"global::TUnit.Core.Helpers.CastHelper.Cast<{parameter.Type.GloballyQualified()}>({argumentsArrayName}[{i}])"; + var castExpression = CastExpressionHelper.GenerateCastForPosition(sourceTypeInfo, i, parameter.Type, $"{argumentsArrayName}[{i}]", compilation); allArguments.Add(castExpression); } return string.Join(", ", allArguments); } - /// - /// Generates argument access for a method with possible params array, given a specific argument count. - /// - /// The method parameters - /// The name of the arguments array - /// The actual number of arguments provided - /// List of argument expressions for method invocation - public static List GenerateArgumentAccessWithParams(IList parameters, string argumentsArrayName, object argumentCount) + public static List GenerateArgumentAccessWithParams( + IList parameters, + string argumentsArrayName, + object argumentCount, + SourceTypeInfo? sourceTypeInfo = null, + CSharpCompilation? compilation = null) { var argumentExpressions = new List(); @@ -59,24 +56,12 @@ public static List GenerateArgumentAccessWithParams(IList({argumentsArrayName}[{i}])"; - argumentExpressions.Add(castExpression); - } - } - else + var upperBound = Math.Min(parameters.Count, argCount); + for (var i = 0; i < upperBound; i++) { - for (var i = 0; i < parameters.Count && i < argCount; i++) - { - var param = parameters[i]; - var castExpression = $"global::TUnit.Core.Helpers.CastHelper.Cast<{param.Type.GloballyQualified()}>({argumentsArrayName}[{i}])"; - argumentExpressions.Add(castExpression); - } + var param = parameters[i]; + var castExpression = CastExpressionHelper.GenerateCastForPosition(sourceTypeInfo, i, param.Type, $"{argumentsArrayName}[{i}]", compilation); + argumentExpressions.Add(castExpression); } } else @@ -85,36 +70,29 @@ public static List GenerateArgumentAccessWithParams(IList({argumentsArrayName}[{i}])"; - argumentExpressions.Add(castExpression); - } - } - else - { - for (var i = 0; i < regularParamCount && i < argCount; i++) - { - var param = parameters[i]; - var castExpression = $"global::TUnit.Core.Helpers.CastHelper.Cast<{param.Type.GloballyQualified()}>({argumentsArrayName}[{i}])"; - argumentExpressions.Add(castExpression); - } + var param = parameters[i]; + var castExpression = CastExpressionHelper.GenerateCastForPosition(sourceTypeInfo, i, param.Type, $"{argumentsArrayName}[{i}]", compilation); + argumentExpressions.Add(castExpression); } // Handle params array parameter var paramsParam = parameters[parameters.Count - 1]; - var elementType = (paramsParam.Type as IArrayTypeSymbol)?.ElementType; + var elementType = GetParamsElementType(paramsParam.Type); if (elementType != null) { + // For params elements, use the element's source type if available + // (params elements are beyond the regular parameter positions, so source types may not cover them) + var elementTargetGQ = elementType.GloballyQualified(); + if (argCountExpression != null) { // Dynamic count - create array from remaining arguments - var arrayInit = $"({argumentsArrayName}.Length > {regularParamCount} ? global::System.Linq.Enumerable.Range({regularParamCount}, {argCountExpression} - {regularParamCount}).Select(i => global::TUnit.Core.Helpers.CastHelper.Cast<{elementType.GloballyQualified()}>({argumentsArrayName}[i])).ToArray() : new {elementType.GloballyQualified()}[0])"; + // For dynamic count, we can't determine source types per element, so use CastHelper + var arrayInit = $"({argumentsArrayName}.Length > {regularParamCount} ? global::System.Linq.Enumerable.Range({regularParamCount}, {argCountExpression} - {regularParamCount}).Select(i => global::TUnit.Core.Helpers.CastHelper.Cast<{elementTargetGQ}>({argumentsArrayName}[i])).ToArray() : new {elementTargetGQ}[0])"; argumentExpressions.Add(arrayInit); } else @@ -124,17 +102,15 @@ public static List GenerateArgumentAccessWithParams(IList({singleArg}) }})"; + var paramsTypeGQ = paramsParam.Type.GloballyQualified(); + var elementCast = GenerateElementCast(elementType, regularParamCount, singleArg, sourceTypeInfo, compilation); + var checkAndCast = $"({singleArg} is null ? null : {singleArg} is {paramsTypeGQ} arr ? arr : new {elementTargetGQ}[] {{ {elementCast} }})"; argumentExpressions.Add(checkAndCast); } else @@ -143,20 +119,55 @@ public static List GenerateArgumentAccessWithParams(IList(); for (var i = regularParamCount; i < argCount; i++) { - arrayElements.Add($"global::TUnit.Core.Helpers.CastHelper.Cast<{elementType.GloballyQualified()}>({argumentsArrayName}[{i}])"); + var elementCast = GenerateElementCast(elementType, i, $"{argumentsArrayName}[{i}]", sourceTypeInfo, compilation); + arrayElements.Add(elementCast); } - argumentExpressions.Add($"new {elementType.GloballyQualified()}[] {{ {string.Join(", ", arrayElements)} }}"); + argumentExpressions.Add($"new {elementTargetGQ}[] {{ {string.Join(", ", arrayElements)} }}"); } } } else { // Fallback if we can't determine element type - var castExpression = $"global::TUnit.Core.Helpers.CastHelper.Cast<{paramsParam.Type.GloballyQualified()}>({argumentsArrayName}[{regularParamCount}])"; + var castExpression = CastExpressionHelper.GenerateCastForPosition(sourceTypeInfo, regularParamCount, paramsParam.Type, $"{argumentsArrayName}[{regularParamCount}]", compilation); argumentExpressions.Add(castExpression); } } return argumentExpressions; } + + /// + /// Extracts the element type from a params parameter type. + /// Handles T[] (IArrayTypeSymbol) and generic collection types like IEnumerable<T>, List<T>, etc. + /// + private static ITypeSymbol? GetParamsElementType(ITypeSymbol paramsType) + { + if (paramsType is IArrayTypeSymbol arrayType) + { + return arrayType.ElementType; + } + + // C# 13 params collections: IEnumerable, ReadOnlySpan, List, etc. + if (paramsType is INamedTypeSymbol { IsGenericType: true, TypeArguments.Length: 1 } namedType) + { + return namedType.TypeArguments[0]; + } + + return null; + } + + private static string GenerateElementCast( + ITypeSymbol elementType, + int argIndex, + string argExpression, + SourceTypeInfo? sourceTypeInfo, + CSharpCompilation? compilation) + { + // For params overflow positions, the element type is statically known — pass it as + // fallbackSourceType so unknown positions get a direct cast instead of CastHelper.Cast. + return CastExpressionHelper.GenerateCastForPosition( + sourceTypeInfo, argIndex, elementType, argExpression, compilation, + fallbackSourceType: elementType); + } } diff --git a/TUnit.Core.SourceGenerator/Generators/AotConverterGenerator.cs b/TUnit.Core.SourceGenerator/Generators/AotConverterGenerator.cs deleted file mode 100644 index 234a4a802a..0000000000 --- a/TUnit.Core.SourceGenerator/Generators/AotConverterGenerator.cs +++ /dev/null @@ -1,726 +0,0 @@ -using System.Collections.Immutable; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using TUnit.Core.SourceGenerator.Extensions; -using TUnit.Core.SourceGenerator.Models; - -namespace TUnit.Core.SourceGenerator.Generators; - -[Generator] -public class AotConverterGenerator : IIncrementalGenerator -{ - public static string ParseAotConverter = "ParseCompilationMetadata"; - - public void Initialize(IncrementalGeneratorInitializationContext context) - { - var enabledProvider = context.AnalyzerConfigOptionsProvider - .Select((options, _) => - { - options.GlobalOptions.TryGetValue("build_property.EnableTUnitSourceGeneration", out var value); - return !string.Equals(value, "false", StringComparison.OrdinalIgnoreCase); - }); - - var allTypes = context.CompilationProvider - .Select((compilation, ct) => - { - try - { - var conversionInfos = new List(); - ScanTestParameters(compilation, conversionInfos, ct); - - // Deduplicate conversions based on source and target types - var seenConversions = new HashSet<(ITypeSymbol Source, ITypeSymbol Target)>( - new TypePairEqualityComparer()); - var uniqueConversions = new List(); - - foreach (var conversion in conversionInfos) - { - if (conversion == null) - { - continue; - } - - var key = (conversion.SourceType, conversion.TargetType); - if (seenConversions.Add(key)) - { - uniqueConversions.Add(conversion); - } - } - - return uniqueConversions.Select(c => - { - var sourceType = ToTypeMetadata(c.SourceType); - var targetType = ToTypeMetadata(c.TargetType); - - return new ConversionMetadata() - { - SourceType = sourceType, - TargetType = targetType, - TypesAreDifferent = !SymbolEqualityComparer.Default.Equals(c.SourceType, c.TargetType), - IsImplicit = c.IsImplicit, - }; - }).ToEquatableArray(); - } - catch (NullReferenceException ex) - { - var stackTrace = ex.StackTrace ?? "No stack trace"; - throw new InvalidOperationException($"NullReferenceException in ScanTestParameters: {ex.Message}\nStack: {stackTrace}", ex); - } - catch (Exception ex) when (ex is not OperationCanceledException) - { - throw new InvalidOperationException($"Error in AotConverterGenerator.ScanTestParameters: {ex.GetType().Name}: {ex.Message}", ex); - } - }) - .Combine(enabledProvider) - .WithTrackingName(ParseAotConverter); - - context.RegisterSourceOutput(allTypes, (spc, data) => - { - var (source, isEnabled) = data; - if (!isEnabled) - { - return; - } - try - { - GenerateConverters(spc, source); - } - catch (Exception e) - { - spc.ReportDiagnostic(Diagnostic.Create( - new DiagnosticDescriptor( - id: "TUNITGEN001", - title: "TUnit.AotConverterGenerator Failed", - messageFormat: "AotConverterGenerator failed: {0}: {1}", - category: "TUnit.Generator", - defaultSeverity: DiagnosticSeverity.Error, - isEnabledByDefault: true, - description: e.ToString()), - Location.None, - e.GetType().Name, - e.Message)); - } - }); - } - - private void ScanTestParameters(Compilation compilation, List conversionInfos, CancellationToken cancellationToken) - { - var typesToScan = new HashSet(SymbolEqualityComparer.Default); - - foreach (var tree in compilation.SyntaxTrees) - { - cancellationToken.ThrowIfCancellationRequested(); - - var semanticModel = compilation.GetSemanticModel(tree); - var root = tree.GetRoot(); - - foreach(var nodes in root.DescendantNodes()) - { - cancellationToken.ThrowIfCancellationRequested(); - - if(nodes is MethodDeclarationSyntax method) - { - var methodSymbol = semanticModel.GetDeclaredSymbol(method); - if (methodSymbol == null) - { - continue; - } - - if (!IsTestMethod(methodSymbol)) - { - continue; - } - - foreach (var parameter in methodSymbol.Parameters) - { - typesToScan.Add(parameter.Type); - ScanAttributesForTypes(parameter.GetAttributes(), typesToScan); - } - - ScanAttributesForTypes(methodSymbol.GetAttributes(), typesToScan); - } - else if (nodes is ClassDeclarationSyntax classDecl) - { - var classSymbol = semanticModel.GetDeclaredSymbol(classDecl); - if (classSymbol == null) - { - continue; - } - - if (!IsTestClass(classSymbol)) - { - continue; - } - - ScanAttributesForTypes(classSymbol.GetAttributes(), typesToScan); - - foreach (var constructor in classSymbol.Constructors) - { - if (constructor.IsImplicitlyDeclared) - { - continue; - } - - foreach (var parameter in constructor.Parameters) - { - typesToScan.Add(parameter.Type); - ScanAttributesForTypes(parameter.GetAttributes(), typesToScan); - } - } - } - } - } - - foreach (var type in typesToScan) - { - cancellationToken.ThrowIfCancellationRequested(); - CollectConversionsForType(type, conversionInfos, compilation); - } - } - - private static bool IsTestMethod(IMethodSymbol method) - { - return method.GetAttributes().Any(attr => - { - var attrClass = attr.AttributeClass; - if (attrClass == null) - { - return false; - } - - var baseType = attrClass; - while (baseType != null) - { - if (baseType.ToDisplayString() == WellKnownFullyQualifiedClassNames.BaseTestAttribute.WithoutGlobalPrefix) - { - return true; - } - baseType = baseType.BaseType; - } - - return false; - }); - } - - private bool IsTestClass(INamedTypeSymbol classSymbol) - { - return classSymbol.GetMembers() - .OfType() - .Any(IsTestMethod); - } - - private void ScanAttributesForTypes(ImmutableArray attributes, HashSet typesToScan) - { - foreach (var attribute in attributes) - { - if (attribute.AttributeClass == null) - { - continue; - } - - if (!IsDataSourceAttribute(attribute.AttributeClass)) - { - continue; - } - - if (attribute.AttributeClass.IsGenericType) - { - foreach (var typeArg in attribute.AttributeClass.TypeArguments) - { - typesToScan.Add(typeArg); - } - } - - foreach (var arg in attribute.ConstructorArguments) - { - ScanTypedConstantForTypes(arg, typesToScan); - } - - foreach (var namedArg in attribute.NamedArguments) - { - ScanTypedConstantForTypes(namedArg.Value, typesToScan); - } - } - } - - private bool IsDataSourceAttribute(INamedTypeSymbol attributeClass) - { - var currentType = attributeClass; - while (currentType != null) - { - var fullName = currentType.ToDisplayString(); - if (fullName == WellKnownFullyQualifiedClassNames.AsyncDataSourceGeneratorAttribute.WithoutGlobalPrefix || - fullName == WellKnownFullyQualifiedClassNames.AsyncUntypedDataSourceGeneratorAttribute.WithoutGlobalPrefix || - fullName == WellKnownFullyQualifiedClassNames.ArgumentsAttribute.WithoutGlobalPrefix) - { - return true; - } - - if (currentType.AllInterfaces.Any(i => - i.ToDisplayString() == WellKnownFullyQualifiedClassNames.IDataSourceAttribute.WithoutGlobalPrefix)) - { - return true; - } - - currentType = currentType.BaseType; - } - - return false; - } - - private void ScanTypedConstantForTypes(TypedConstant constant, HashSet typesToScan) - { - if (constant.IsNull) - { - return; - } - - if (constant is { Kind: TypedConstantKind.Type, Value: ITypeSymbol typeValue }) - { - typesToScan.Add(typeValue); - } - - else if (constant is { Kind: TypedConstantKind.Array, IsNull: false }) - { - foreach (var element in constant.Values) - { - ScanTypedConstantForTypes(element, typesToScan); - } - } - else if (constant.Kind != TypedConstantKind.Array && constant is { Value: not null, Type: not null }) - { - typesToScan.Add(constant.Type); - } - } - - private void CollectConversionsForType(ITypeSymbol type, List conversionInfos, Compilation compilation) - { - if (type is not INamedTypeSymbol namedType) - { - return; - } - - if (!ShouldIncludeType(namedType, compilation)) - { - return; - } - - var conversionOperators = namedType.GetMembers() - .OfType() - .Where(m => (m.Name == "op_Implicit" || m.Name == "op_Explicit") && - m is { IsStatic: true, Parameters.Length: 1 }); - - foreach (var method in conversionOperators) - { - var conversionInfo = GetConversionInfoFromSymbol(method, compilation); - if (conversionInfo != null) - { - conversionInfos.Add(conversionInfo); - } - } - - if (namedType.IsGenericType) - { - foreach (var typeArg in namedType.TypeArguments) - { - CollectConversionsForType(typeArg, conversionInfos, compilation); - } - } - } - - private bool ShouldIncludeType(INamedTypeSymbol type, Compilation compilation) - { - var typeAssembly = type.ContainingAssembly; - var currentAssembly = compilation.Assembly; - - if (currentAssembly == null) - { - return false; - } - - if (SymbolEqualityComparer.Default.Equals(typeAssembly, currentAssembly)) - { - return true; - } - - if (type.DeclaredAccessibility == Accessibility.Public) - { - return true; - } - - if (type.DeclaredAccessibility == Accessibility.Internal) - { - if (typeAssembly != null && typeAssembly.GivesAccessTo(currentAssembly)) - { - return true; - } - } - - return false; - } - - private bool IsAccessibleType(ITypeSymbol type, Compilation compilation) - { - if (type == null || compilation == null) - { - return false; - } - - if (type.SpecialType != SpecialType.None) - { - return true; - } - - if (type.TypeKind == TypeKind.TypeParameter) - { - return true; - } - - if (type is INamedTypeSymbol namedType) - { - var typeAssembly = namedType.ContainingAssembly; - var currentAssembly = compilation.Assembly; - - if (currentAssembly != null && SymbolEqualityComparer.Default.Equals(typeAssembly, currentAssembly)) - { - return true; - } - - if (namedType.DeclaredAccessibility == Accessibility.Public) - { - return true; - } - - if (namedType.DeclaredAccessibility == Accessibility.Internal) - { - if (currentAssembly == null) - { - return false; - } - - if (typeAssembly != null && typeAssembly.GivesAccessTo(currentAssembly)) - { - return true; - } - - return false; - } - - if (namedType.IsGenericType) - { - foreach (var typeArg in namedType.TypeArguments) - { - if (!IsAccessibleType(typeArg, compilation)) - { - return false; - } - } - } - - if (namedType.ContainingType != null) - { - return IsAccessibleType(namedType.ContainingType, compilation); - } - - return false; - } - - if (type is IArrayTypeSymbol arrayType) - { - return IsAccessibleType(arrayType.ElementType, compilation); - } - - if (type is IPointerTypeSymbol pointerType) - { - return IsAccessibleType(pointerType.PointedAtType, compilation); - } - - return false; - } - - private ConversionInfo? GetConversionInfoFromSymbol(IMethodSymbol methodSymbol, Compilation compilation) - { - var containingType = methodSymbol.ContainingType; - if (containingType == null) - { - return null; - } - - var sourceType = methodSymbol.Parameters[0].Type; - var targetType = methodSymbol.ReturnType; - var isImplicit = methodSymbol.Name == "op_Implicit"; - - if (sourceType.IsGenericDefinition() || targetType.IsGenericDefinition()) - { - return null; - } - - if (TypeContainsGenericTypeParameters(sourceType) || TypeContainsGenericTypeParameters(targetType)) - { - return null; - } - - if (sourceType.IsRefLikeType || targetType.IsRefLikeType) - { - return null; - } - - if (sourceType.TypeKind == TypeKind.Pointer || targetType.TypeKind == TypeKind.Pointer || - sourceType.SpecialType == SpecialType.System_Void || targetType.SpecialType == SpecialType.System_Void) - { - return null; - } - - if (!IsAccessibleType(containingType, compilation)) - { - return null; - } - - if (!IsAccessibleType(sourceType, compilation) || !IsAccessibleType(targetType, compilation)) - { - return null; - } - - return new ConversionInfo - { - SourceType = sourceType, - TargetType = targetType, - IsImplicit = isImplicit, - }; - } - - private bool TypeContainsGenericTypeParameters(ITypeSymbol type) - { - if (type.TypeKind == TypeKind.TypeParameter) - { - return true; - } - - if (type is INamedTypeSymbol namedTypeSymbol) - { - foreach (var typeArgument in namedTypeSymbol.TypeArguments) - { - if (TypeContainsGenericTypeParameters(typeArgument)) - { - return true; - } - } - } - - if (type is IArrayTypeSymbol arrayTypeSymbol) - { - return TypeContainsGenericTypeParameters(arrayTypeSymbol.ElementType); - } - - if (type is IPointerTypeSymbol pointerTypeSymbol) - { - return TypeContainsGenericTypeParameters(pointerTypeSymbol.PointedAtType); - } - - return false; - } - - private void GenerateConverters(SourceProductionContext context, EquatableArray conversions) - { - var writer = new CodeWriter(); - writer.AppendLine("#nullable enable"); - - if (conversions.Length == 0) - { - writer.AppendLine(); - writer.AppendLine("// No conversion operators found"); - context.AddSource("AotConverters.g.cs", writer.ToString()); - return; - } - - writer.AppendLine(); - writer.AppendLine("using System;"); - writer.AppendLine("using TUnit.Core.Converters;"); - writer.AppendLine(); - writer.AppendLine("namespace TUnit.Generated;"); - writer.AppendLine(); - - var converterIndex = 0; - var registrations = new List(); - - foreach (var conversion in conversions) - { - try - { - if (conversion.SourceType == null || conversion.TargetType == null) - { - var sourceDisplay = conversion.SourceType?.DisplayString ?? "null"; - var targetDisplay = conversion.TargetType?.DisplayString ?? "null"; - context.ReportDiagnostic(Diagnostic.Create( - new DiagnosticDescriptor( - id: "TUNITGEN002", - title: "Null type in conversion", - messageFormat: "Skipping converter generation: SourceType={0}, TargetType={1}. Check test data sources that use implicit conversions between these types.", - category: "TUnit.Generator", - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true), - Location.None, - sourceDisplay, - targetDisplay)); - continue; - } - } - catch (Exception ex) - { - var sourceDisplay = conversion.SourceType?.DisplayString ?? "unknown"; - var targetDisplay = conversion.TargetType?.DisplayString ?? "unknown"; - context.ReportDiagnostic(Diagnostic.Create( - new DiagnosticDescriptor( - id: "TUNITGEN003", - title: "Error checking conversion types", - messageFormat: "Error checking conversion types (SourceType={0}, TargetType={1}): {2}", - category: "TUnit.Generator", - defaultSeverity: DiagnosticSeverity.Warning, - isEnabledByDefault: true), - Location.None, - sourceDisplay, - targetDisplay, - ex.ToString())); - continue; - } - - var converterClassName = $"AotConverter_{converterIndex++}"; - var sourceTypeName = conversion.SourceType.GloballyQualified; - var targetTypeName = conversion.TargetType.GloballyQualified; - - writer.AppendLine($"internal sealed class {converterClassName} : IAotConverter"); - writer.AppendLine("{"); - writer.Indent(); - - writer.AppendLine($"public Type SourceType => typeof({sourceTypeName});"); - writer.AppendLine($"public Type TargetType => typeof({targetTypeName});"); - writer.AppendLine(); - - writer.AppendLine("public object? Convert(object? value)"); - writer.AppendLine("{"); - writer.Indent(); - - writer.AppendLine("if (value == null) return null;"); - - // Use Zen's more robust approach for handling nullable types and type checks - var sourceType = conversion.SourceType; - var targetType = conversion.TargetType; - - writer.AppendLine($"if (value is {targetType.PatternTypeName} targetTypedValue)"); - writer.AppendLine("{"); - writer.Indent(); - writer.AppendLine("return targetTypedValue;"); - writer.Unindent(); - writer.AppendLine("}"); - - // 2. If types are different, generate the fallback check for the source type. - // This handles cases that require an implicit conversion. - if (conversion.TypesAreDifferent) - { - writer.AppendLine(); - writer.AppendLine($"if (value is {sourceType.PatternTypeName} sourceTypedValue)"); - writer.AppendLine("{"); - writer.Indent(); - // For explicit conversions, we need to use an explicit cast - // For implicit conversions, variable assignment works fine - if (conversion.IsImplicit) - { - writer.AppendLine($"{targetTypeName} converted = sourceTypedValue;"); - } - else - { - writer.AppendLine($"{targetTypeName} converted = ({targetTypeName})sourceTypedValue;"); - } - writer.AppendLine("return converted;"); - writer.Unindent(); - writer.AppendLine("}"); - } - - writer.AppendLine("return value; // Return original value if type doesn't match"); - - writer.Unindent(); - writer.AppendLine("}"); - - writer.Unindent(); - writer.AppendLine("}"); - writer.AppendLine(); - - registrations.Add($"AotConverterRegistry.Register(new {converterClassName}());"); - } - - writer.AppendLine("internal static class AotConverterRegistration"); - writer.AppendLine("{"); - writer.Indent(); - - writer.AppendLine("[global::System.Runtime.CompilerServices.ModuleInitializer]"); - writer.AppendLine("[global::System.Diagnostics.CodeAnalysis.SuppressMessage(\"Performance\", \"CA2255:The 'ModuleInitializer' attribute should not be used in libraries\","); - writer.AppendLine(" Justification = \"Test framework needs to register AOT converters for conversion operators\")]"); - writer.AppendLine("public static void Initialize()"); - writer.AppendLine("{"); - writer.Indent(); - - foreach (var registration in registrations) - { - writer.AppendLine(registration); - } - - writer.Unindent(); - writer.AppendLine("}"); - - writer.Unindent(); - writer.AppendLine("}"); - - context.AddSource("AotConverters.g.cs", writer.ToString()); - } - - private static TypeMetadata ToTypeMetadata(ITypeSymbol type) - { - var globallyQualified = type.GloballyQualified(); - - // For pattern matching, we must unwrap nullable types (C# language requirement - CS8116) - string patternTypeName = globallyQualified; - if (type is INamedTypeSymbol { OriginalDefinition.SpecialType: SpecialType.System_Nullable_T, TypeArguments.Length: > 0 } nullableSourceType) - { - patternTypeName = nullableSourceType.TypeArguments[0].GloballyQualified(); - } - return new TypeMetadata(globallyQualified, type.ToDisplayString(), patternTypeName); - } - - public record TypeMetadata(string GloballyQualified, string DisplayString, string PatternTypeName); - - public record ConversionMetadata - { - public required TypeMetadata SourceType { get; init; } - public required TypeMetadata TargetType { get; init; } - public required bool TypesAreDifferent { get; init; } - public required bool IsImplicit { get; init; } - } - - private class ConversionInfo - { - public required ITypeSymbol SourceType { get; init; } - public required ITypeSymbol TargetType { get; init; } - public required bool IsImplicit { get; init; } - } - - private class TypePairEqualityComparer : IEqualityComparer<(ITypeSymbol Source, ITypeSymbol Target)> - { - public bool Equals((ITypeSymbol Source, ITypeSymbol Target) x, (ITypeSymbol Source, ITypeSymbol Target) y) - { - return SymbolEqualityComparer.Default.Equals(x.Source, y.Source) && - SymbolEqualityComparer.Default.Equals(x.Target, y.Target); - } - - public int GetHashCode((ITypeSymbol Source, ITypeSymbol Target) obj) - { - unchecked - { - var hash = 17; - hash = hash * 31 + SymbolEqualityComparer.Default.GetHashCode(obj.Source); - hash = hash * 31 + SymbolEqualityComparer.Default.GetHashCode(obj.Target); - return hash; - } - } - } -} diff --git a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs index 226f8a6119..8dc27734c1 100644 --- a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs @@ -19,6 +19,7 @@ namespace TUnit.Core.SourceGenerator.Generators; public sealed class TestMetadataGenerator : IIncrementalGenerator { private const string GeneratedNamespace = "TUnit.Generated"; + public const string ParseTestMetadata = "ParseTestMetadata"; public void Initialize(IncrementalGeneratorInitializationContext context) { @@ -41,15 +42,21 @@ public void Initialize(IncrementalGeneratorInitializationContext context) ); }); - var testMethodsProvider = context.SyntaxProvider + // Single ForAttributeWithMetadataName call shared by all [Test]-triggered pipelines. + // Branching here avoids duplicate attribute index scans that would occur with + // separate [Generator] classes each calling ForAttributeWithMetadataName. + var rawTestMethods = context.SyntaxProvider .ForAttributeWithMetadataName( "TUnit.Core.TestAttribute", predicate: static (node, _) => node is MethodDeclarationSyntax, - transform: static (ctx, _) => ctx) + transform: static (ctx, _) => ctx); + + var testMethodsProvider = rawTestMethods .Combine(compilationContext) .Select(static (ctx, _) => GetTestMethodMetadata(ctx.Left, ctx.Right)) .Where(static m => m is not null) - .Combine(enabledProvider); + .Combine(enabledProvider) + .WithTrackingName(ParseTestMetadata); var inheritsTestsClassesProvider = context.SyntaxProvider .ForAttributeWithMetadataName( @@ -106,6 +113,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) } GenerateInheritedTestSources(context, classInfo); }); + } private static InheritsTestsClassMetadata? GetInheritsTestsClassMetadata(GeneratorAttributeSyntaxContext context, CompilationContext compilationContext) @@ -125,6 +133,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) return new InheritsTestsClassMetadata { TypeSymbol = classSymbol, + TypeFullyQualifiedName = classSymbol.ToDisplayString(), ClassSyntax = classSyntax, Context = context, CompilationContext = compilationContext @@ -162,10 +171,15 @@ public void Initialize(IncrementalGeneratorInitializationContext context) var (filePath, lineNumber) = GetTestMethodSourceLocation(methodSyntax, testAttribute); + var methodAttributes = methodSymbol.GetAttributes(); + return new TestMethodMetadata { MethodSymbol = methodSymbol ?? throw new InvalidOperationException("Symbol is not a method"), TypeSymbol = containingType, + MethodFullyQualifiedName = methodSymbol!.ToDisplayString(), + TypeFullyQualifiedName = containingType.ToDisplayString(), + MethodAttributeHash = TestMethodMetadata.ComputeAttributeHash(methodAttributes), FilePath = filePath, LineNumber = lineNumber, TestAttribute = context.Attributes.First(), @@ -174,7 +188,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context) MethodSyntax = methodSyntax, IsGenericType = isGenericType, IsGenericMethod = isGenericMethod, - MethodAttributes = methodSymbol.GetAttributes() + MethodAttributes = methodAttributes }; } @@ -242,10 +256,16 @@ private static void GenerateInheritedTestSources(SourceProductionContext context } } + var effectiveMethod = concreteMethod ?? method; + var methodAttributes = effectiveMethod.GetAttributes(); + var testMethodMetadata = new TestMethodMetadata { - MethodSymbol = concreteMethod ?? method, // Use concrete method if found, otherwise base method + MethodSymbol = effectiveMethod, // Use concrete method if found, otherwise base method TypeSymbol = typeForMetadata, // Use constructed generic base if applicable + MethodFullyQualifiedName = effectiveMethod.ToDisplayString(), + TypeFullyQualifiedName = typeForMetadata.ToDisplayString(), + MethodAttributeHash = TestMethodMetadata.ComputeAttributeHash(methodAttributes), FilePath = filePath, LineNumber = lineNumber, TestAttribute = testAttribute, @@ -253,8 +273,8 @@ private static void GenerateInheritedTestSources(SourceProductionContext context CompilationContext = classInfo.CompilationContext, MethodSyntax = null, // No syntax for inherited methods IsGenericType = typeForMetadata.IsGenericType, - IsGenericMethod = (concreteMethod ?? method).IsGenericMethod, - MethodAttributes = (concreteMethod ?? method).GetAttributes(), // Use concrete method attributes + IsGenericMethod = effectiveMethod.IsGenericMethod, + MethodAttributes = methodAttributes, // Use concrete method attributes InheritanceDepth = inheritanceDepth }; @@ -513,6 +533,7 @@ private static void GenerateTestMetadata(CodeWriter writer, TestMethodMetadata t $"global::TUnit.Core.SourceRegistrar.RegisterEntries<{concreteClassName}>(static () => {uniqueClassName}.Entries_{registrationIndex})"); registrationIndex++; } + } /// @@ -876,13 +897,13 @@ private static void EmitConcreteInstanceCreation(CodeWriter writer, TestMethodMe else if (!testMethod.IsGenericType && !testMethod.IsGenericMethod) { // Non-generic (inherited) tests: use InstanceFactoryGenerator for proper required property handling - writer.AppendRaw(InstanceFactoryGenerator.GenerateInstanceFactoryBody(testMethod.TypeSymbol)); + writer.AppendRaw(InstanceFactoryGenerator.GenerateInstanceFactoryBody(testMethod.TypeSymbol, testMethod.CompilationContext.Compilation)); } else if (entry.ClassTypeArgs.Length > 0) { // Generic class with resolved type args: construct the concrete closed type var constructedType = testMethod.TypeSymbol.Construct(entry.ClassTypeArgs); - writer.AppendRaw(InstanceFactoryGenerator.GenerateInstanceFactoryBody(constructedType)); + writer.AppendRaw(InstanceFactoryGenerator.GenerateInstanceFactoryBody(constructedType, testMethod.CompilationContext.Compilation)); } else { @@ -967,7 +988,9 @@ private static void EmitConcreteInvokeBody(CodeWriter writer, TestMethodMetadata var parametersFromArgs = testMethod.MethodSymbol.Parameters .Where(p => p.Type.Name != "CancellationToken" || p.Type.ContainingNamespace?.ToString() != "System.Threading") .ToArray(); - GenerateConcreteTestInvokerBody(writer, methodName, returnPattern, hasCancellationToken, parametersFromArgs); + var sourceTypes = SourceTypeAnalyzer.GetMethodParameterSourceTypes(testMethod.MethodSymbol); + var comp = testMethod.CompilationContext.Compilation; + GenerateConcreteTestInvokerBody(writer, methodName, returnPattern, hasCancellationToken, parametersFromArgs, sourceTypes, comp); } } @@ -2518,23 +2541,25 @@ private static void GenerateTypedInvokers(CodeWriter writer, TestMethodMetadata { var (hasCancellationToken, parametersFromArgs) = ParseInvokerParameters(testMethod.MethodSymbol); var returnPattern = GetReturnPattern(testMethod.MethodSymbol); - GenerateConcreteTestInvoker(writer, testMethod.MethodSymbol.Name, returnPattern, hasCancellationToken, parametersFromArgs); + var sourceTypes = SourceTypeAnalyzer.GetMethodParameterSourceTypes(testMethod.MethodSymbol); + var comp = testMethod.CompilationContext.Compilation; + GenerateConcreteTestInvoker(writer, testMethod.MethodSymbol.Name, returnPattern, hasCancellationToken, parametersFromArgs, sourceTypes, comp); } } } - private static void GenerateConcreteTestInvoker(CodeWriter writer, string methodName, TestReturnPattern returnPattern, bool hasCancellationToken, IParameterSymbol[] parametersFromArgs) + private static void GenerateConcreteTestInvoker(CodeWriter writer, string methodName, TestReturnPattern returnPattern, bool hasCancellationToken, IParameterSymbol[] parametersFromArgs, SourceTypeInfo? sourceTypeInfo = null, CSharpCompilation? compilation = null) { // Generate InvokeTypedTest which is required by CreateExecutableTestFactory writer.AppendLine("InvokeTypedTest = static (instance, args, cancellationToken) =>"); writer.AppendLine("{"); writer.Indent(); - GenerateConcreteTestInvokerBody(writer, methodName, returnPattern, hasCancellationToken, parametersFromArgs); + GenerateConcreteTestInvokerBody(writer, methodName, returnPattern, hasCancellationToken, parametersFromArgs, sourceTypeInfo, compilation); writer.Unindent(); writer.AppendLine("},"); } - private static void GenerateConcreteTestInvokerBody(CodeWriter writer, string methodName, TestReturnPattern returnPattern, bool hasCancellationToken, IParameterSymbol[] parametersFromArgs) + private static void GenerateConcreteTestInvokerBody(CodeWriter writer, string methodName, TestReturnPattern returnPattern, bool hasCancellationToken, IParameterSymbol[] parametersFromArgs, SourceTypeInfo? sourceTypeInfo = null, CSharpCompilation? compilation = null) { // Wrap entire body in try-catch to handle synchronous exceptions writer.AppendLine("try"); @@ -2563,7 +2588,9 @@ private static void GenerateConcreteTestInvokerBody(CodeWriter writer, string me // Build tuple reconstruction with proper casting var tupleElements = singleTupleParam.TupleElements.Select((elem, i) => - $"global::TUnit.Core.Helpers.CastHelper.Cast<{elem.Type.GloballyQualified()}>(args[{i}])"); + { + return CastExpressionHelper.GenerateCastForPosition(sourceTypeInfo, i, elem.Type, $"args[{i}]", compilation); + }); var tupleConstruction = $"({string.Join(", ", tupleElements)})"; var methodCallReconstructed = hasCancellationToken @@ -2576,9 +2603,10 @@ private static void GenerateConcreteTestInvokerBody(CodeWriter writer, string me writer.AppendLine("{"); writer.Indent(); writer.AppendLine("// Rare case: tuple is wrapped as a single argument"); + var wrappedTupleCast = CastExpressionHelper.GenerateCast(null, singleTupleParam, "args[0]", compilation); var methodCallDirect = hasCancellationToken - ? $"instance.{methodName}(global::TUnit.Core.Helpers.CastHelper.Cast<{singleTupleParam.GloballyQualified()}>(args[0]), cancellationToken)" - : $"instance.{methodName}(global::TUnit.Core.Helpers.CastHelper.Cast<{singleTupleParam.GloballyQualified()}>(args[0]))"; + ? $"instance.{methodName}({wrappedTupleCast}, cancellationToken)" + : $"instance.{methodName}({wrappedTupleCast})"; GenerateReturnHandling(writer, methodCallDirect, returnPattern); writer.Unindent(); writer.AppendLine("}"); @@ -2623,7 +2651,7 @@ private static void GenerateConcreteTestInvokerBody(CodeWriter writer, string me writer.Indent(); // Build the arguments to pass, handling params arrays correctly - var argsToPass = TupleArgumentHelper.GenerateArgumentAccessWithParams(parametersFromArgs, "args", argCount); + var argsToPass = TupleArgumentHelper.GenerateArgumentAccessWithParams(parametersFromArgs, "args", argCount, sourceTypeInfo, compilation); // Add CancellationToken if present if (hasCancellationToken) @@ -3002,11 +3030,13 @@ private static string PreGenerateInvokeSwitchCase(TestMethodMetadata testMethod, var (hasCancellationToken, parametersFromArgs) = ParseInvokerParameters(testMethod.MethodSymbol); var returnPattern = GetReturnPattern(testMethod.MethodSymbol); + var sourceTypes = SourceTypeAnalyzer.GetMethodParameterSourceTypes(testMethod.MethodSymbol); + var compilation = testMethod.CompilationContext.Compilation; writer.AppendLine($"case {methodIndex}:"); writer.AppendLine("{"); writer.Indent(); - GenerateConcreteTestInvokerBody(writer, testMethod.MethodSymbol.Name, returnPattern, hasCancellationToken, parametersFromArgs); + GenerateConcreteTestInvokerBody(writer, testMethod.MethodSymbol.Name, returnPattern, hasCancellationToken, parametersFromArgs, sourceTypes, compilation); writer.Unindent(); writer.AppendLine("}"); @@ -3420,7 +3450,7 @@ private static IEnumerable GroupMethodsByClass(ImmutableArray { public required INamedTypeSymbol TypeSymbol { get; init; } public required ClassDeclarationSyntax ClassSyntax { get; init; } public GeneratorAttributeSyntaxContext Context { get; init; } public required CompilationContext CompilationContext { get; init; } + + // Stable string identity for incremental caching. + // Only the class name is used for equality — attribute changes on base class methods + // won't invalidate this cache entry. This is acceptable because ForAttributeWithMetadataName + // on [InheritsTests] only fires when the class's own syntax changes, so upstream caching + // already prevents re-evaluation for base class attribute changes. A clean rebuild handles + // the rare case where a base class method's attributes change without touching the subclass. + public required string TypeFullyQualifiedName { get; init; } + + public bool Equals(InheritsTestsClassMetadata? other) + { + if (ReferenceEquals(null, other)) + return false; + if (ReferenceEquals(this, other)) + return true; + + return TypeFullyQualifiedName == other.TypeFullyQualifiedName; + } + + public override bool Equals(object? obj) => Equals(obj as InheritsTestsClassMetadata); + + public override int GetHashCode() => TypeFullyQualifiedName.GetHashCode(); } diff --git a/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs b/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs index 33616e1e7d..8fe02b399f 100644 --- a/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs +++ b/TUnit.Core.SourceGenerator/Models/TestMethodMetadata.cs @@ -11,6 +11,9 @@ public record CompilationContext(CSharpCompilation Compilation, AttributeWriter /// /// Contains all the metadata about a test method discovered by the source generator. +/// Uses string-based identity for Equals/GetHashCode so that Roslyn's incremental +/// pipeline can properly cache across compilations (ISymbol instances change on every +/// keystroke, but string representations remain stable for unchanged methods). /// public class TestMethodMetadata : IEquatable { @@ -25,6 +28,19 @@ public class TestMethodMetadata : IEquatable public bool IsGenericType { get; init; } public bool IsGenericMethod { get; init; } + // Stable string identity fields — populated eagerly from ISymbol during construction. + // These survive across compilations (same string value for unchanged methods), + // enabling Roslyn's incremental caching to skip downstream stages. + public required string MethodFullyQualifiedName { get; init; } + public required string TypeFullyQualifiedName { get; init; } + + /// + /// Hash of all method attributes, computed eagerly from AttributeData. + /// Detects attribute changes (e.g., adding [Category], changing [Arguments]) + /// without storing ISymbol references in the equality path. + /// + public required int MethodAttributeHash { get; init; } + /// /// All attributes on the method, stored for later use during data combination generation /// @@ -45,14 +61,14 @@ public bool Equals(TestMethodMetadata? other) if (ReferenceEquals(this, other)) return true; - return SymbolEqualityComparer.Default.Equals(MethodSymbol, other.MethodSymbol) && - SymbolEqualityComparer.Default.Equals(TypeSymbol, other.TypeSymbol) && + return MethodFullyQualifiedName == other.MethodFullyQualifiedName && + TypeFullyQualifiedName == other.TypeFullyQualifiedName && FilePath == other.FilePath && LineNumber == other.LineNumber && IsGenericType == other.IsGenericType && IsGenericMethod == other.IsGenericMethod && - InheritanceDepth == other.InheritanceDepth; - // Note: Skipping MethodAttributes comparison to avoid complexity - these rarely change independently + InheritanceDepth == other.InheritanceDepth && + MethodAttributeHash == other.MethodAttributeHash; } public override bool Equals(object? obj) @@ -64,15 +80,68 @@ public override int GetHashCode() { unchecked { - var hashCode = SymbolEqualityComparer.Default.GetHashCode(MethodSymbol); - hashCode = (hashCode * 397) ^ SymbolEqualityComparer.Default.GetHashCode(TypeSymbol); + var hashCode = MethodFullyQualifiedName.GetHashCode(); + hashCode = (hashCode * 397) ^ TypeFullyQualifiedName.GetHashCode(); hashCode = (hashCode * 397) ^ FilePath.GetHashCode(); hashCode = (hashCode * 397) ^ LineNumber; hashCode = (hashCode * 397) ^ IsGenericType.GetHashCode(); hashCode = (hashCode * 397) ^ IsGenericMethod.GetHashCode(); hashCode = (hashCode * 397) ^ InheritanceDepth; + hashCode = (hashCode * 397) ^ MethodAttributeHash; return hashCode; } } + /// + /// Computes a stable hash of method attributes from their string representations. + /// This avoids storing ISymbol references in the equality path while still + /// detecting attribute changes across compilations. + /// + public static int ComputeAttributeHash(ImmutableArray attributes) + { + unchecked + { + var hash = 17; + foreach (var attr in attributes) + { + var attrName = attr.AttributeClass?.ToDisplayString() ?? ""; + hash = (hash * 31) ^ attrName.GetHashCode(); + + foreach (var arg in attr.ConstructorArguments) + { + hash = (hash * 31) ^ HashTypedConstant(arg); + } + + foreach (var namedArg in attr.NamedArguments) + { + hash = (hash * 31) ^ namedArg.Key.GetHashCode(); + hash = (hash * 31) ^ HashTypedConstant(namedArg.Value); + } + } + return hash; + } + } + + private static int HashTypedConstant(TypedConstant constant) + { + unchecked + { + if (constant.Kind == TypedConstantKind.Array) + { + var hash = 19; + if (!constant.IsNull) + { + foreach (var element in constant.Values) + { + hash = (hash * 31) ^ HashTypedConstant(element); + } + } + return hash; + } + + var typeHash = constant.Type?.ToDisplayString()?.GetHashCode() ?? 0; + var valueHash = constant.Value?.ToString()?.GetHashCode() ?? 0; + return (typeHash * 31) ^ valueHash; + } + } } diff --git a/TUnit.Core/Converters/FuncAotConverter.cs b/TUnit.Core/Converters/FuncAotConverter.cs index 43e9bf417d..ac36b0954e 100644 --- a/TUnit.Core/Converters/FuncAotConverter.cs +++ b/TUnit.Core/Converters/FuncAotConverter.cs @@ -4,5 +4,5 @@ public class FuncAotConverter(Func converter { public Type SourceType { get; } = typeof(TSource); public Type TargetType { get; } = typeof(TTarget); - public object? Convert(object? value) => converter((TSource)value!); + public object? Convert(object? value) => value is null ? null : converter((TSource)value); } diff --git a/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs b/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs deleted file mode 100644 index bd4f58b93f..0000000000 --- a/TUnit.SourceGenerator.Benchmarks/AotConverterGeneratorBenchmarks.cs +++ /dev/null @@ -1,33 +0,0 @@ -using BenchmarkDotNet.Attributes; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.MSBuild; -using TUnit.Core.SourceGenerator.Generators; - -namespace TUnit.SourceGenerator.Benchmarks; - -[MemoryDiagnoser] -[InProcess] -public class AotConverterGeneratorBenchmarks -{ - private const string SampleProjectPath = "../TUnit.TestProject/TUnit.TestProject.csproj"; - - private MSBuildWorkspace? _workspace; - private GeneratorDriver? _driver; - private Compilation? _compilation; - - [GlobalSetup(Target = nameof(RunGenerator))] - public void SetupRunGenerator() => - (_compilation, _driver, _workspace) = - WorkspaceHelper.SetupAsync(SampleProjectPath) - .GetAwaiter() - .GetResult(); - - [Benchmark] - public GeneratorDriver RunGenerator() => _driver!.RunGeneratorsAndUpdateCompilation(_compilation!, out _, out _); - - [GlobalCleanup] - public void Cleanup() - { - _workspace?.Dispose(); - } -} diff --git a/TUnit.SourceGenerator.Benchmarks/Program.cs b/TUnit.SourceGenerator.Benchmarks/Program.cs index 58addd6760..5229300952 100644 --- a/TUnit.SourceGenerator.Benchmarks/Program.cs +++ b/TUnit.SourceGenerator.Benchmarks/Program.cs @@ -14,7 +14,7 @@ // BenchmarkRunner.Run(); // BenchmarkRunner.Run(); // BenchmarkRunner.Run(); - // BenchmarkRunner.Run(); + // AOT converter generation is now part of TestMetadataGenerator // BenchmarkRunner.Run(); // BenchmarkRunner.Run(); } diff --git a/TUnit.SourceGenerator.IncrementalTests/AotConverterGeneratorIncrementalTests.cs b/TUnit.SourceGenerator.IncrementalTests/AotConverterGeneratorIncrementalTests.cs deleted file mode 100644 index 6c8669eb45..0000000000 --- a/TUnit.SourceGenerator.IncrementalTests/AotConverterGeneratorIncrementalTests.cs +++ /dev/null @@ -1,118 +0,0 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp; -using TUnit.Core.SourceGenerator.Generators; -using TUnit.Core.SourceGenerator.Models; - -namespace TUnit.Assertions.SourceGenerator.IncrementalTests; - -public class AotConverterGeneratorIncrementalTests -{ - private const string DefaultConverter = - """ - using global::TUnit.Core; - - #nullable enabled - public record Foo - { - public static implicit operator Foo((int Value1, int Value2) tuple) => new(); - } - - public class Tests - { - [Test] - [MethodDataSource(nameof(Data))] - public void Test1(Foo data) - { - } - - public static IEnumerable Data() => [new()]; - } - """; - - private const string SecondConverter = - """ - using global::TUnit.Core; - - #nullable enabled - public record FooBar - { - public static implicit operator FooBar((int Value1, int Value2) tuple) => new(); - } - - public class Tests1 - { - [Test] - [MethodDataSource(nameof(Data))] - public void Test1(FooBar data) - { - } - - public static IEnumerable Data() => [new()]; - } - """; - - [Fact] - public void AddUnrelatedType_MethodShouldNotRegenerate() - { - var syntaxTree = CSharpSyntaxTree.ParseText(DefaultConverter, CSharpParseOptions.Default); - var compilation1 = Fixture.CreateLibrary(syntaxTree); - - var driver1 = TestHelper.GenerateTracked(compilation1); - AssertRunReasons(driver1, IncrementalGeneratorRunReasons.New, 1); - - var compilation2 = compilation1.AddSyntaxTrees(CSharpSyntaxTree.ParseText("struct MyValue {}")); - var driver2 = driver1.RunGenerators(compilation2); - AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached, 1); - } - - [Fact] - public void AddNewConverterShouldRegenerate() - { - var syntaxTree = CSharpSyntaxTree.ParseText(DefaultConverter, CSharpParseOptions.Default); - var compilation1 = Fixture.CreateLibrary(syntaxTree); - - var driver1 = TestHelper.GenerateTracked(compilation1); - AssertRunReasons(driver1, IncrementalGeneratorRunReasons.New, 1); - - var compilation2 = compilation1.AddSyntaxTrees(CSharpSyntaxTree.ParseText(SecondConverter)); - var driver2 = driver1.RunGenerators(compilation2); - AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Modified, 2); - } - - [Fact] - public void ModifyOperatorShouldRegenerate() - { - var syntaxTree = CSharpSyntaxTree.ParseText(DefaultConverter, CSharpParseOptions.Default); - var compilation1 = Fixture.CreateLibrary(syntaxTree); - - var driver1 = TestHelper.GenerateTracked(compilation1); - AssertRunReasons(driver1, IncrementalGeneratorRunReasons.New, 1); - - var compilation2 = TestHelper.ReplaceTypeDeclaration(compilation1, "Foo", - """ - public record Foo - { - public static explicit operator Foo((int Value1, int Value2) tuple) => new(); - } - """ - ); - - var driver2 = driver1.RunGenerators(compilation2); - AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Modified, 1); - } - - private static void AssertRunReasons( - GeneratorDriver driver, - IncrementalGeneratorRunReasons reasons, - int conversionMetadataLength, - int outputIndex = 0 - ) - { - var runResult = driver.GetRunResult().Results[0]; - var runValue = runResult.TrackedSteps[AotConverterGenerator.ParseAotConverter][0].Outputs[0].Value; - var runState = (ValueTuple, bool>)runValue; - Xunit.Assert.Equal(conversionMetadataLength, runState.Item1.Length); - - TestHelper.AssertRunReason(runResult, AotConverterGenerator.ParseAotConverter, reasons.BuildStep, outputIndex); - } -} diff --git a/TUnit.SourceGenerator.IncrementalTests/TestMetadataGeneratorIncrementalTests.cs b/TUnit.SourceGenerator.IncrementalTests/TestMetadataGeneratorIncrementalTests.cs new file mode 100644 index 0000000000..1775c1304d --- /dev/null +++ b/TUnit.SourceGenerator.IncrementalTests/TestMetadataGeneratorIncrementalTests.cs @@ -0,0 +1,127 @@ +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using TUnit.Core.SourceGenerator.Generators; + +namespace TUnit.Assertions.SourceGenerator.IncrementalTests; + +/// +/// Tests that TestMetadataGenerator's incremental pipeline properly caches +/// when unrelated code changes, and re-runs when test methods change. +/// +public class TestMetadataGeneratorIncrementalTests +{ + private const string SimpleTestClass = + """ + using global::TUnit.Core; + + public class MyTests + { + [Test] + public void Test1() + { + } + } + """; + + private const string TestClassWithArguments = + """ + using global::TUnit.Core; + + public class ArgTests + { + [Test] + [Arguments("hello")] + public void Test1(string value) + { + } + } + """; + + private const string TestClassWithArrayArguments = + """ + using global::TUnit.Core; + + public class ArrayArgTests + { + [Test] + [Arguments(new[] { 1, 2, 3 })] + public void Test1(int[] values) + { + } + } + """; + + /// + /// Adding an unrelated type should NOT cause test metadata to regenerate. + /// + [Fact] + public void AddUnrelatedType_ShouldNotRegenerateTestMetadata() + { + var syntaxTree = CSharpSyntaxTree.ParseText(SimpleTestClass, CSharpParseOptions.Default); + var compilation1 = Fixture.CreateLibrary(syntaxTree); + + var driver1 = TestHelper.GenerateTracked(compilation1); + AssertRunReasons(driver1, IncrementalGeneratorRunReasons.New); + + // Add an unrelated struct — should NOT invalidate test metadata + var compilation2 = compilation1.AddSyntaxTrees(CSharpSyntaxTree.ParseText("struct UnrelatedValue {}")); + var driver2 = driver1.RunGenerators(compilation2); + AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Cached); + } + + /// + /// Changing an attribute on a test method SHOULD cause regeneration. + /// + [Fact] + public void ChangeTestAttribute_ShouldRegenerate() + { + var syntaxTree = CSharpSyntaxTree.ParseText(TestClassWithArguments, CSharpParseOptions.Default); + var compilation1 = Fixture.CreateLibrary(syntaxTree); + + var driver1 = TestHelper.GenerateTracked(compilation1); + AssertRunReasons(driver1, IncrementalGeneratorRunReasons.New); + + // Change the Arguments attribute value + var compilation2 = TestHelper.ReplaceMethodDeclaration(compilation1, "Test1", + """ + [Test] + [Arguments("world")] + public void Test1(string value) + { + } + """); + + var driver2 = driver1.RunGenerators(compilation2); + AssertRunReasons(driver2, IncrementalGeneratorRunReasons.Modified); + } + + /// + /// Tests that ComputeAttributeHash handles array-typed constructor arguments + /// without throwing (TypedConstant.Value throws for arrays — must use Values). + /// + [Fact] + public void ArrayArguments_ShouldNotThrow() + { + var syntaxTree = CSharpSyntaxTree.ParseText(TestClassWithArrayArguments, CSharpParseOptions.Default); + var compilation = Fixture.CreateLibrary(syntaxTree); + + var driver = TestHelper.GenerateTracked(compilation); + var result = driver.GetRunResult(); + + // Verify no diagnostics from our generator + var generatorDiagnostics = result.Results + .SelectMany(r => r.Diagnostics) + .Where(d => d.Id.StartsWith("TUNIT")) + .ToList(); + Xunit.Assert.Empty(generatorDiagnostics); + } + + private static void AssertRunReasons( + GeneratorDriver driver, + IncrementalGeneratorRunReasons reasons, + int outputIndex = 0) + { + var runResult = driver.GetRunResult().Results[0]; + TestHelper.AssertRunReason(runResult, TestMetadataGenerator.ParseTestMetadata, reasons.BuildStep, outputIndex); + } +} diff --git a/TUnit.TestProject/AllDataSourcesCombinedTests.cs b/TUnit.TestProject/AllDataSourcesCombinedTests.cs index cead330563..e65190ea58 100644 --- a/TUnit.TestProject/AllDataSourcesCombinedTests.cs +++ b/TUnit.TestProject/AllDataSourcesCombinedTests.cs @@ -6,9 +6,9 @@ namespace TUnit.TestProject; [EngineTest(ExpectedResult.Pass)] [Arguments(1)] [Arguments(2)] -[ClassDataSource(typeof(DataSource1))] -[ClassDataSource(typeof(DataSource2))] -[ClassDataSource(typeof(DataSource3))] +[ClassDataSource] +[ClassDataSource] +[ClassDataSource] public class AllDataSourcesCombinedTests(int classValue) { private static readonly ConcurrentBag ExecutedTests = diff --git a/TUnit.TestProject/AllDataSourcesCombinedTestsVerification.cs b/TUnit.TestProject/AllDataSourcesCombinedTestsVerification.cs index 5acf67537a..c002846422 100644 --- a/TUnit.TestProject/AllDataSourcesCombinedTestsVerification.cs +++ b/TUnit.TestProject/AllDataSourcesCombinedTestsVerification.cs @@ -6,9 +6,9 @@ namespace TUnit.TestProject; [EngineTest(ExpectedResult.Pass)] [Arguments(1)] [Arguments(2)] -[ClassDataSource(typeof(DataSource1))] -[ClassDataSource(typeof(DataSource2))] -[ClassDataSource(typeof(DataSource3))] +[ClassDataSource] +[ClassDataSource] +[ClassDataSource] public class AllDataSourcesCombinedTestsVerification { private readonly int classValue; diff --git a/TUnit.TestProject/ArgumentsWithClassDataSourceTests.cs b/TUnit.TestProject/ArgumentsWithClassDataSourceTests.cs index 866e5bb948..4ca63af49f 100644 --- a/TUnit.TestProject/ArgumentsWithClassDataSourceTests.cs +++ b/TUnit.TestProject/ArgumentsWithClassDataSourceTests.cs @@ -6,8 +6,8 @@ namespace TUnit.TestProject; [EngineTest(ExpectedResult.Pass)] [Arguments(1)] [Arguments(2)] -[ClassDataSource(typeof(IntDataSource1))] -[ClassDataSource(typeof(IntDataSource2))] +[ClassDataSource] +[ClassDataSource] public class ArgumentsWithClassDataSourceTests(int classArg) { private static readonly ConcurrentBag ExecutedTests = diff --git a/TUnit.TestProject/ClassDataSourceEnumerableTest.cs b/TUnit.TestProject/ClassDataSourceEnumerableTest.cs index ca30f6250f..61027e16a8 100644 --- a/TUnit.TestProject/ClassDataSourceEnumerableTest.cs +++ b/TUnit.TestProject/ClassDataSourceEnumerableTest.cs @@ -2,7 +2,7 @@ namespace TUnit.TestProject; -[ClassDataSource(typeof(EnumerableDataSource))] +[ClassDataSource] public class ClassDataSourceEnumerableTest(string value) { [Test] diff --git a/TUnit.TestProject/ClassDataSourceWithMethodDataSourceTests.cs b/TUnit.TestProject/ClassDataSourceWithMethodDataSourceTests.cs index 4aabddfd37..08cb25429d 100644 --- a/TUnit.TestProject/ClassDataSourceWithMethodDataSourceTests.cs +++ b/TUnit.TestProject/ClassDataSourceWithMethodDataSourceTests.cs @@ -4,9 +4,9 @@ namespace TUnit.TestProject; [EngineTest(ExpectedResult.Pass)] -[ClassDataSource(typeof(DataSource1))] -[ClassDataSource(typeof(DataSource2))] -[ClassDataSource(typeof(DataSource3))] +[ClassDataSource] +[ClassDataSource] +[ClassDataSource] public class ClassDataSourceWithMethodDataSourceTests(int classValue) { private static readonly ConcurrentBag ExecutedTests = diff --git a/TUnit.TestProject/ComprehensiveCountTest.cs b/TUnit.TestProject/ComprehensiveCountTest.cs index 23bc699356..41e437b126 100644 --- a/TUnit.TestProject/ComprehensiveCountTest.cs +++ b/TUnit.TestProject/ComprehensiveCountTest.cs @@ -2,7 +2,7 @@ namespace TUnit.TestProject; -[ClassDataSource(typeof(ClassData))] +[ClassDataSource] [Arguments("X")] [Arguments("Y")] public class ComprehensiveCountTest(string classValue) diff --git a/TUnit.TestProject/MixedDataSourceBugTest.cs b/TUnit.TestProject/MixedDataSourceBugTest.cs index a92ad9d18d..b0b626a82b 100644 --- a/TUnit.TestProject/MixedDataSourceBugTest.cs +++ b/TUnit.TestProject/MixedDataSourceBugTest.cs @@ -1,7 +1,7 @@ namespace TUnit.TestProject; -[ClassDataSource(typeof(ClassData1))] -[ClassDataSource(typeof(ClassData2))] +[ClassDataSource] +[ClassDataSource] public class MixedDataSourceBugTest(int classValue) { [Test] diff --git a/TUnit.TestProject/TestCountVerificationTests.cs b/TUnit.TestProject/TestCountVerificationTests.cs index db7b6eb3cd..8040eed418 100644 --- a/TUnit.TestProject/TestCountVerificationTests.cs +++ b/TUnit.TestProject/TestCountVerificationTests.cs @@ -2,7 +2,7 @@ namespace TUnit.TestProject; [Arguments(1)] [Arguments(2)] -[ClassDataSource(typeof(TestDataSource))] +[ClassDataSource] public class TestCountVerificationTests(int value) { [Test]