diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index c86cbf234d..78b65a0e74 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -60,9 +60,38 @@ ## Quick Reference +### ⚠️ CRITICAL: TUnit.TestProject Testing Rules + +**DO NOT run `TUnit.TestProject` without filters!** Many tests are intentionally designed to fail to verify error handling, diagnostics, and edge cases. + +```bash +# ❌ WRONG - Will show many "failures" (this is expected behavior) +cd TUnit.TestProject && dotnet run +cd TUnit.TestProject && dotnet test + +# ✅ CORRECT - Always use targeted filters when testing TUnit.TestProject +cd TUnit.TestProject && dotnet run -- --treenode-filter "/*/*/SpecificClass/*" +cd TUnit.TestProject && dotnet run -- --treenode-filter "/*/*/*/*[Category!=Performance]" + +# ✅ CORRECT - Test other test projects normally (they don't have intentional failures) +dotnet test TUnit.Engine.Tests +dotnet test TUnit.Assertions.Tests +dotnet test TUnit.Core.SourceGenerator.Tests +``` + +**Why TUnit.TestProject is special:** +- Contains negative test cases (tests that verify failures work correctly) +- Tests error messages, diagnostics, and exception handling +- Performance tests excluded by default +- Integration tests covering all edge cases + +**Golden Rule**: When verifying changes, use `dotnet test` (which excludes TUnit.TestProject), OR run TUnit.TestProject with specific `--treenode-filter` patterns. + +--- + ### Most Common Commands ```bash -# Run all tests +# Run all tests (automatically excludes TUnit.TestProject integration tests) dotnet test # Test source generator + accept snapshots diff --git a/CLAUDE.md b/CLAUDE.md index fd4913434d..1ed9227dd1 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -120,10 +120,39 @@ dotnet publish -c Release -p:PublishAot=true --use-current-runtime ## 📋 Quick Reference Card +### ⚠️ CRITICAL: TUnit.TestProject Testing Rules + +**DO NOT run `TUnit.TestProject` without filters!** Many tests are intentionally designed to fail to verify error handling. + +```bash +# ❌ WRONG - Will show many "failures" (expected behavior) +cd TUnit.TestProject && dotnet run +cd TUnit.TestProject && dotnet test + +# ✅ CORRECT - Always use targeted filters +cd TUnit.TestProject && dotnet run -- --treenode-filter "/*/*/SpecificClass/*" +cd TUnit.TestProject && dotnet run -- --treenode-filter "/*/*/*/*[Category!=Performance]" + +# ✅ CORRECT - Test other projects normally +dotnet test TUnit.Engine.Tests +dotnet test TUnit.Assertions.Tests +dotnet test TUnit.Core.SourceGenerator.Tests +``` + +**Why?** TUnit.TestProject contains: +- Tests that verify failure scenarios (expected to fail) +- Tests for error messages and diagnostics +- Performance tests that should be excluded by default +- Integration tests covering edge cases + +**Rule**: Only run TUnit.TestProject with explicit `--treenode-filter` to target specific tests or classes. + +--- + ### Most Common Commands ```bash -# Run all tests +# Run all tests (excludes TUnit.TestProject integration tests) dotnet test # Test source generator + accept snapshots diff --git a/Directory.Packages.props b/Directory.Packages.props index dd472ddf2d..d59237dee8 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -54,7 +54,7 @@ - + @@ -81,12 +81,12 @@ - - - - - - + + + + + + diff --git a/TUnit.Analyzers.Tests/DisposableFieldPropertyAnalyzerTests.cs b/TUnit.Analyzers.Tests/DisposableFieldPropertyAnalyzerTests.cs index 54e85764fa..4b545d6757 100644 --- a/TUnit.Analyzers.Tests/DisposableFieldPropertyAnalyzerTests.cs +++ b/TUnit.Analyzers.Tests/DisposableFieldPropertyAnalyzerTests.cs @@ -582,4 +582,619 @@ public async Task RecordPaymentUsingMappedCommand(CancellationToken cancellation """ ); } + + [Test] + public async Task New_Disposable_In_AsyncInitializer_Flags_Issue() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + using TUnit.Core.Interfaces; + + public class DisposableFieldTests : IAsyncInitializer + { + private HttpClient? {|#0:_httpClient|}; + + public Task InitializeAsync() + { + _httpClient = new HttpClient(); + return Task.CompletedTask; + } + + [Test] + public void Test1() + { + } + } + """, + + Verifier.Diagnostic(Rules.Dispose_Member_In_Cleanup) + .WithLocation(0) + .WithArguments("_httpClient") + ); + } + + [Test] + public async Task New_Disposable_In_AsyncInitializer_No_Issue_When_Cleaned_Up() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + using TUnit.Core.Interfaces; + + public class DisposableFieldTests : IAsyncInitializer, IAsyncDisposable + { + private HttpClient? _httpClient; + + public Task InitializeAsync() + { + _httpClient = new HttpClient(); + return Task.CompletedTask; + } + + public ValueTask DisposeAsync() + { + _httpClient?.Dispose(); + return ValueTask.CompletedTask; + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + // ======================================== + // FIELD INITIALIZATION TESTS + // ======================================== + + [Test] + public async Task FieldInitialization_Flags_Issue() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private HttpClient? {|#0:_httpClient|} = new HttpClient(); + + [Test] + public void Test1() + { + } + } + """, + + Verifier.Diagnostic(Rules.Dispose_Member_In_Cleanup) + .WithLocation(0) + .WithArguments("_httpClient") + ); + } + + [Test] + public async Task FieldInitialization_No_Issue_When_Disposed_In_Dispose() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests : IDisposable + { + private HttpClient? _httpClient = new HttpClient(); + + public void Dispose() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + [Test] + public async Task FieldInitialization_No_Issue_When_Disposed_In_DisposeAsync() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + + public class DisposableFieldTests : IAsyncDisposable + { + private HttpClient? _httpClient = new HttpClient(); + + public ValueTask DisposeAsync() + { + _httpClient?.Dispose(); + return ValueTask.CompletedTask; + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + [Test] + public async Task FieldInitialization_No_Issue_When_Disposed_In_After() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private HttpClient? _httpClient = new HttpClient(); + + [After(HookType.Test)] + public void Cleanup() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + // ======================================== + // CONSTRUCTOR INITIALIZATION TESTS + // ======================================== + + [Test] + public async Task Constructor_Flags_Issue() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private HttpClient? {|#0:_httpClient|}; + + public DisposableFieldTests() + { + _httpClient = new HttpClient(); + } + + [Test] + public void Test1() + { + } + } + """, + + Verifier.Diagnostic(Rules.Dispose_Member_In_Cleanup) + .WithLocation(0) + .WithArguments("_httpClient") + ); + } + + [Test] + public async Task Constructor_No_Issue_When_Disposed_In_Dispose() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests : IDisposable + { + private HttpClient? _httpClient; + + public DisposableFieldTests() + { + _httpClient = new HttpClient(); + } + + public void Dispose() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + [Test] + public async Task Constructor_No_Issue_When_Disposed_In_DisposeAsync() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + + public class DisposableFieldTests : IAsyncDisposable + { + private HttpClient? _httpClient; + + public DisposableFieldTests() + { + _httpClient = new HttpClient(); + } + + public ValueTask DisposeAsync() + { + _httpClient?.Dispose(); + return ValueTask.CompletedTask; + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + [Test] + public async Task Constructor_No_Issue_When_Disposed_In_After() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private HttpClient? _httpClient; + + public DisposableFieldTests() + { + _httpClient = new HttpClient(); + } + + [After(HookType.Test)] + public void Cleanup() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + // ======================================== + // BEFORE(TEST) WITH DISPOSE/DISPOSEASYNC TESTS + // ======================================== + + [Test] + public async Task BeforeTest_No_Issue_When_Disposed_In_Dispose() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests : IDisposable + { + private HttpClient? _httpClient; + + [Before(HookType.Test)] + public void Setup() + { + _httpClient = new HttpClient(); + } + + public void Dispose() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + [Test] + public async Task BeforeTest_No_Issue_When_Disposed_In_DisposeAsync() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + + public class DisposableFieldTests : IAsyncDisposable + { + private HttpClient? _httpClient; + + [Before(HookType.Test)] + public void Setup() + { + _httpClient = new HttpClient(); + } + + public ValueTask DisposeAsync() + { + _httpClient?.Dispose(); + return ValueTask.CompletedTask; + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + // ======================================== + // IASYNCINITIALIZER ADDITIONAL COMBINATIONS + // ======================================== + + [Test] + public async Task IAsyncInitializer_No_Issue_When_Disposed_In_Dispose() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + using TUnit.Core.Interfaces; + + public class DisposableFieldTests : IAsyncInitializer, IDisposable + { + private HttpClient? _httpClient; + + public Task InitializeAsync() + { + _httpClient = new HttpClient(); + return Task.CompletedTask; + } + + public void Dispose() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + [Test] + public async Task IAsyncInitializer_No_Issue_When_Disposed_In_After() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System; + using System.Net.Http; + using System.Threading.Tasks; + using TUnit.Core; + using TUnit.Core.Interfaces; + + public class DisposableFieldTests : IAsyncInitializer + { + private HttpClient? _httpClient; + + public Task InitializeAsync() + { + _httpClient = new HttpClient(); + return Task.CompletedTask; + } + + [After(HookType.Test)] + public void Cleanup() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + // ======================================== + // STATIC FIELD WITH BEFORE(ASSEMBLY) TESTS + // ======================================== + + [Test] + public async Task BeforeAssembly_Static_Flags_Issue() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private static HttpClient? {|#0:_httpClient|}; + + [Before(HookType.Assembly)] + public static void Setup() + { + _httpClient = new HttpClient(); + } + + [Test] + public void Test1() + { + } + } + """, + + Verifier.Diagnostic(Rules.Dispose_Member_In_Cleanup) + .WithLocation(0) + .WithArguments("_httpClient") + ); + } + + [Test] + public async Task BeforeAssembly_Static_No_Issue_When_Disposed_In_AfterAssembly() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private static HttpClient? _httpClient; + + [Before(HookType.Assembly)] + public static void Setup() + { + _httpClient = new HttpClient(); + } + + [After(HookType.Assembly)] + public static void Cleanup() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } + + // ======================================== + // STATIC FIELD WITH BEFORE(TESTSESSION) TESTS + // ======================================== + + [Test] + public async Task BeforeTestSession_Static_Flags_Issue() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private static HttpClient? {|#0:_httpClient|}; + + [Before(HookType.TestSession)] + public static void Setup() + { + _httpClient = new HttpClient(); + } + + [Test] + public void Test1() + { + } + } + """, + + Verifier.Diagnostic(Rules.Dispose_Member_In_Cleanup) + .WithLocation(0) + .WithArguments("_httpClient") + ); + } + + [Test] + public async Task BeforeTestSession_Static_No_Issue_When_Disposed_In_AfterTestSession() + { + await Verifier + .VerifyAnalyzerAsync( + """ + using System.Net.Http; + using TUnit.Core; + + public class DisposableFieldTests + { + private static HttpClient? _httpClient; + + [Before(HookType.TestSession)] + public static void Setup() + { + _httpClient = new HttpClient(); + } + + [After(HookType.TestSession)] + public static void Cleanup() + { + _httpClient?.Dispose(); + } + + [Test] + public void Test1() + { + } + } + """ + ); + } } diff --git a/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs b/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs index 77900e6c58..151d20de8c 100644 --- a/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs +++ b/TUnit.Analyzers/DisposableFieldPropertyAnalyzer.cs @@ -46,6 +46,16 @@ private static void CheckMethods(SyntaxNodeAnalysisContext context, IMethodSymbo var methodSymbols = methods.Where(x => x.IsStatic == isStaticMethod).ToArray(); + // Check field initializers first + if (context.Node is ClassDeclarationSyntax classDeclarationSyntax) + { + var namedTypeSymbol = context.SemanticModel.GetDeclaredSymbol(classDeclarationSyntax); + if (namedTypeSymbol != null) + { + CheckFieldInitializers(context, namedTypeSymbol, isStaticMethod, createdObjects); + } + } + foreach (var methodSymbol in methodSymbols) { CheckSetUps(context, methodSymbol, createdObjects); @@ -65,6 +75,87 @@ private static void CheckMethods(SyntaxNodeAnalysisContext context, IMethodSymbo } } + private static void CheckFieldInitializers(SyntaxNodeAnalysisContext context, INamedTypeSymbol namedTypeSymbol, bool isStatic, ConcurrentDictionary createdObjects) + { + // Directly traverse the class syntax to find field declarations + if (context.Node is not ClassDeclarationSyntax classDeclaration) + { + return; + } + + var members = classDeclaration.Members; + + foreach (var member in members) + { + // Handle field declarations: private HttpClient _client = new HttpClient(); + if (member is FieldDeclarationSyntax fieldDeclaration) + { + if (fieldDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword)) != isStatic) + { + continue; + } + + foreach (var variable in fieldDeclaration.Declaration.Variables) + { + if (variable.Initializer == null) + { + continue; + } + + // Check if the initializer contains an object creation expression + var objectCreations = variable.Initializer.Value.DescendantNodesAndSelf() + .OfType(); + + foreach (var objectCreation in objectCreations) + { + var typeInfo = context.SemanticModel.GetTypeInfo(objectCreation); + if (typeInfo.Type?.IsDisposable() is true || typeInfo.Type?.IsAsyncDisposable() is true) + { + var fieldSymbol = context.SemanticModel.GetDeclaredSymbol(variable) as IFieldSymbol; + if (fieldSymbol != null) + { + createdObjects.TryAdd(fieldSymbol, HookLevel.Test); + break; // Only need to add once + } + } + } + } + } + + // Handle property declarations: public HttpClient Client { get; set; } = new HttpClient(); + if (member is PropertyDeclarationSyntax propertyDeclaration) + { + if (propertyDeclaration.Modifiers.Any(m => m.IsKind(SyntaxKind.StaticKeyword)) != isStatic) + { + continue; + } + + if (propertyDeclaration.Initializer == null) + { + continue; + } + + // Check if the initializer contains an object creation expression + var objectCreations = propertyDeclaration.Initializer.Value.DescendantNodesAndSelf() + .OfType(); + + foreach (var objectCreation in objectCreations) + { + var typeInfo = context.SemanticModel.GetTypeInfo(objectCreation); + if (typeInfo.Type?.IsDisposable() is true || typeInfo.Type?.IsAsyncDisposable() is true) + { + var propertySymbol = context.SemanticModel.GetDeclaredSymbol(propertyDeclaration) as IPropertySymbol; + if (propertySymbol != null) + { + createdObjects.TryAdd(propertySymbol, HookLevel.Test); + break; // Only need to add once + } + } + } + } + } + } + private static void CheckSetUps(SyntaxNodeAnalysisContext context, IMethodSymbol methodSymbol, ConcurrentDictionary createdObjects) { var syntaxNodes = methodSymbol.DeclaringSyntaxReferences @@ -72,7 +163,20 @@ private static void CheckSetUps(SyntaxNodeAnalysisContext context, IMethodSymbol var isHookMethod = methodSymbol.IsHookMethod(context.Compilation, out _, out var level, out _); - if (!isHookMethod && methodSymbol.MethodKind != MethodKind.Constructor) + // Check for IAsyncInitializer.InitializeAsync() + var isInitializeAsyncMethod = false; + if (methodSymbol is { Name: "InitializeAsync", Parameters.IsDefaultOrEmpty: true }) + { + var asyncInitializer = context.Compilation.GetTypeByMetadataName("TUnit.Core.Interfaces.IAsyncInitializer"); + if (asyncInitializer != null && methodSymbol.ContainingType.Interfaces.Any(x => + SymbolEqualityComparer.Default.Equals(x, asyncInitializer))) + { + isInitializeAsyncMethod = true; + level = HookLevel.Test; + } + } + + if (!isHookMethod && methodSymbol.MethodKind != MethodKind.Constructor && !isInitializeAsyncMethod) { return; } diff --git a/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs b/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs index 750caa385b..47796a2da8 100644 --- a/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs +++ b/TUnit.Assertions.SourceGenerator/Generators/MethodAssertionGenerator.cs @@ -459,9 +459,10 @@ private static string BuildMethodCallExpression(AssertionMethodData data) if (data.IsExtensionMethod) { - // Extension method syntax: value.MethodName(params) + // Extension method syntax: value!.MethodName(params) + // Use null-forgiving operator since we've already checked for null above var paramList = string.Join(", ", data.AdditionalParameters.Select(p => $"_{p.Name}")); - return $"value.{methodName}{typeArguments}({paramList})"; + return $"value!.{methodName}{typeArguments}({paramList})"; } else { @@ -502,14 +503,18 @@ private static void GenerateExtensionMethod(StringBuilder sb, AssertionMethodDat // Additional parameters foreach (var param in data.AdditionalParameters) { - sb.Append($", {param.Type.ToDisplayString()} {param.Name}"); + var paramsModifier = param.IsParams ? "params " : ""; + sb.Append($", {paramsModifier}{param.Type.ToDisplayString()} {param.Name}"); } - // CallerArgumentExpression parameters + // CallerArgumentExpression parameters (skip for params since params must be last) for (int i = 0; i < data.AdditionalParameters.Length; i++) { var param = data.AdditionalParameters[i]; - sb.Append($", [CallerArgumentExpression(nameof({param.Name}))] string? {param.Name}Expression = null"); + if (!param.IsParams) + { + sb.Append($", [CallerArgumentExpression(nameof({param.Name}))] string? {param.Name}Expression = null"); + } } sb.AppendLine(")"); @@ -528,7 +533,9 @@ private static void GenerateExtensionMethod(StringBuilder sb, AssertionMethodDat // Build expression string if (data.AdditionalParameters.Length > 0) { - var exprList = string.Join(", ", data.AdditionalParameters.Select(p => $"{{{p.Name}Expression}}")); + // For params parameters, use parameter name directly (no Expression suffix since we didn't generate it) + var exprList = string.Join(", ", data.AdditionalParameters.Select(p => + p.IsParams ? $"{{{p.Name}}}" : $"{{{p.Name}Expression}}")); sb.AppendLine($" source.Context.ExpressionBuilder.Append($\".{methodName}({exprList})\");"); } else diff --git a/TUnit.Assertions/Assertions/GenericAssertions.cs b/TUnit.Assertions/Assertions/GenericAssertions.cs new file mode 100644 index 0000000000..61dc2282da --- /dev/null +++ b/TUnit.Assertions/Assertions/GenericAssertions.cs @@ -0,0 +1,42 @@ +using TUnit.Assertions.Attributes; + +namespace TUnit.Assertions.Assertions; + +internal static class GenericAssertions +{ + [GenerateAssertion] + public static bool IsIn(this T value, IEnumerable collection) + { + return collection.Contains(value); + } + + [GenerateAssertion] + public static bool IsIn(this T value, IEnumerable collection, IEqualityComparer equalityComparer) + { + return collection.Contains(value, equalityComparer); + } + + [GenerateAssertion] + public static bool IsIn(this T value, params T[] collection) + { + return collection.Contains(value); + } + + [GenerateAssertion] + public static bool IsNotIn(this T value, IEnumerable collection) + { + return !collection.Contains(value); + } + + [GenerateAssertion] + public static bool IsNotIn(this T value, IEnumerable collection, IEqualityComparer equalityComparer) + { + return !collection.Contains(value, equalityComparer); + } + + [GenerateAssertion] + public static bool IsNotIn(this T value, params T[] collection) + { + return !collection.Contains(value); + } +} diff --git a/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs b/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs index d78a86b509..a61b3a5efe 100644 --- a/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs +++ b/TUnit.Assertions/Conditions/HasDistinctItemsAssertion.cs @@ -31,21 +31,26 @@ protected override Task CheckAsync(EvaluationMetadata(); + var duplicates = new List(); + var totalCount = 0; - if (list.Count == distinctList.Count) + foreach (var item in value) { - return Task.FromResult(AssertionResult.Passed); + totalCount++; + if (!seen.Add(item) && !duplicates.Contains(item)) + { + duplicates.Add(item); + } } - var duplicates = list.GroupBy(x => x) - .Where(g => g.Count() > 1) - .Select(g => g.Key) - .ToList(); + if (duplicates.Count == 0) + { + return Task.FromResult(AssertionResult.Passed); + } return Task.FromResult(AssertionResult.Failed( - $"found {list.Count - distinctList.Count} duplicate(s): {string.Join(", ", duplicates)}")); + $"found {totalCount - seen.Count} duplicate(s): {string.Join(", ", duplicates)}")); } protected override string GetExpectation() => "to have distinct items"; diff --git a/TUnit.Assertions/Conditions/MembershipAssertions.cs b/TUnit.Assertions/Conditions/MembershipAssertions.cs deleted file mode 100644 index 3dbdb19fce..0000000000 --- a/TUnit.Assertions/Conditions/MembershipAssertions.cs +++ /dev/null @@ -1,101 +0,0 @@ -using System.Text; -using TUnit.Assertions.Attributes; -using TUnit.Assertions.Core; - -namespace TUnit.Assertions.Conditions; - -/// -/// Asserts that a value is in a collection. -/// -[AssertionExtension("IsIn")] -public class IsInAssertion : ComparerBasedAssertion -{ - private readonly IEnumerable _collection; - - public IsInAssertion( - AssertionContext context, - IEnumerable collection) - : base(context) - { - _collection = collection; - } - - public IsInAssertion Using(IEqualityComparer comparer) - { - SetComparer(comparer); - return this; - } - - protected override Task CheckAsync(EvaluationMetadata metadata) - { - var value = metadata.Value; - var exception = metadata.Exception; - - if (exception != null) - { - return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().Name}")); - } - - var comparer = GetComparer(); - - foreach (var item in _collection) - { - if (comparer.Equals(value!, item)) - { - return Task.FromResult(AssertionResult.Passed); - } - } - - return Task.FromResult(AssertionResult.Failed($"value {value} was not found in collection")); - } - - protected override string GetExpectation() => "to be in collection"; -} - -/// -/// Asserts that a value is NOT in a collection. -/// -[AssertionExtension("IsNotIn")] -public class IsNotInAssertion : ComparerBasedAssertion -{ - private readonly IEnumerable _collection; - - public IsNotInAssertion( - AssertionContext context, - IEnumerable collection) - : base(context) - { - _collection = collection; - } - - public IsNotInAssertion Using(IEqualityComparer comparer) - { - SetComparer(comparer); - return this; - } - - protected override Task CheckAsync(EvaluationMetadata metadata) - { - var value = metadata.Value; - var exception = metadata.Exception; - - if (exception != null) - { - return Task.FromResult(AssertionResult.Failed($"threw {exception.GetType().Name}")); - } - - var comparer = GetComparer(); - - foreach (var item in _collection) - { - if (comparer.Equals(value!, item)) - { - return Task.FromResult(AssertionResult.Failed($"value {value} was found in collection")); - } - } - - return Task.FromResult(AssertionResult.Passed); - } - - protected override string GetExpectation() => "to not be in collection"; -} diff --git a/TUnit.Assertions/Conditions/StringAssertions.cs b/TUnit.Assertions/Conditions/StringAssertions.cs index 1b6bdc4baf..95e20d0ed1 100644 --- a/TUnit.Assertions/Conditions/StringAssertions.cs +++ b/TUnit.Assertions/Conditions/StringAssertions.cs @@ -89,8 +89,8 @@ protected override Task CheckAsync(EvaluationMetadata m if (_ignoringWhitespace) { - actualValue = string.Concat(actualValue.Where(c => !char.IsWhiteSpace(c))); - expectedValue = string.Concat(expectedValue.Where(c => !char.IsWhiteSpace(c))); + actualValue = RemoveWhitespace(actualValue); + expectedValue = RemoveWhitespace(expectedValue); } if (actualValue.Contains(expectedValue, _comparison)) @@ -101,6 +101,24 @@ protected override Task CheckAsync(EvaluationMetadata m return Task.FromResult(AssertionResult.Failed($"found \"{value}\"")); } + private static string RemoveWhitespace(string input) + { + if (string.IsNullOrEmpty(input)) + { + return input; + } + + var sb = new StringBuilder(input.Length); + foreach (var c in input) + { + if (!char.IsWhiteSpace(c)) + { + sb.Append(c); + } + } + return sb.ToString(); + } + protected override string GetExpectation() => $"to contain \"{_expected}\""; } diff --git a/TUnit.Assertions/Extensions/AssertionExtensions.cs b/TUnit.Assertions/Extensions/AssertionExtensions.cs index 0349e62fc8..cf6e6e5a74 100644 --- a/TUnit.Assertions/Extensions/AssertionExtensions.cs +++ b/TUnit.Assertions/Extensions/AssertionExtensions.cs @@ -753,16 +753,22 @@ public static NotStructuralEquivalencyAssertion IsNotEquivalentTo - /// Asserts that the value satisfies the specified predicate. - /// Example: await Assert.That(x).Satisfies(v => v > 0 && v < 100); + /// Asserts that a mapped Task value satisfies custom assertions on the unwrapped result. + /// Maps the source value using a selector that returns a Task, then runs assertions on the awaited result. + /// Example: await Assert.That(model).Satisfies(m => m.AsyncValue, assert => assert.IsEqualTo("Hello")); /// - public static SatisfiesAssertion Satisfies( + public static AsyncMappedSatisfiesAssertion Satisfies( this IAssertionSource source, - Func predicate, - [CallerArgumentExpression(nameof(predicate))] string? expression = null) + Func> selector, + Func, Assertion> assertions, + [CallerArgumentExpression(nameof(selector))] string? selectorExpression = null) { - source.Context.ExpressionBuilder.Append($".Satisfies({expression})"); - return new SatisfiesAssertion(source.Context, predicate, expression ?? "predicate"); + source.Context.ExpressionBuilder.Append($".Satisfies({selectorExpression}, ...)"); + return new AsyncMappedSatisfiesAssertion( + source.Context, + selector!, + assertions, + selectorExpression ?? "selector"); } /// @@ -785,46 +791,16 @@ public static MappedSatisfiesAssertion Satisfies - /// Asserts that an async-mapped value satisfies custom assertions. - /// Maps the source value using an async selector, then runs assertions on the mapped value. - /// Example: await Assert.That(model).Satisfies(m => m.GetNameAsync(), assert => assert.IsEqualTo("John")); - /// - public static AsyncMappedSatisfiesAssertion Satisfies( - this IAssertionSource source, - Func> selector, - Func, Assertion?> assertions, - [CallerArgumentExpression(nameof(selector))] string? selectorExpression = null) - { - source.Context.ExpressionBuilder.Append($".Satisfies({selectorExpression}, ...)"); - return new AsyncMappedSatisfiesAssertion( - source.Context, - selector, - assertions, - selectorExpression ?? "selector"); - } - - /// - /// Asserts that the value is in the specified collection (params array convenience method). - /// Example: await Assert.That(5).IsIn(1, 3, 5, 7, 9); - /// - public static IsInAssertion IsIn( - this IAssertionSource source, - params TValue[] collection) - { - source.Context.ExpressionBuilder.Append($".IsIn({string.Join(", ", collection)})"); - return new IsInAssertion(source.Context, collection); - } - - /// - /// Asserts that the value is NOT in the specified collection (params array convenience method). - /// Example: await Assert.That(4).IsNotIn(1, 3, 5, 7, 9); + /// Asserts that the value satisfies the specified predicate. + /// Example: await Assert.That(x).Satisfies(v => v > 0 && v < 100); /// - public static IsNotInAssertion IsNotIn( + public static SatisfiesAssertion Satisfies( this IAssertionSource source, - params TValue[] collection) + Func predicate, + [CallerArgumentExpression(nameof(predicate))] string? expression = null) { - source.Context.ExpressionBuilder.Append($".IsNotIn({string.Join(", ", collection)})"); - return new IsNotInAssertion(source.Context, collection); + source.Context.ExpressionBuilder.Append($".Satisfies({expression})"); + return new SatisfiesAssertion(source.Context, predicate, expression ?? "predicate"); } /// diff --git a/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete1.verified.txt b/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete1.verified.txt index d08b347bec..c42ddeb5f0 100644 --- a/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete1.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete1.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute() @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1)), Name = "ConcreteClass1", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -56,9 +56,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass1(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete2.verified.txt b/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete2.verified.txt index e65f62d62c..fdd9b1edda 100644 --- a/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete2.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AbstractTests.Concrete2.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2), TestMethodName = "SecondTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2)), Name = "ConcreteClass2", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass2(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SecondTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SecondTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -117,7 +124,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -125,7 +132,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2)), Name = "ConcreteClass2", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -139,9 +146,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass2(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -176,7 +190,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute() @@ -197,7 +211,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -205,7 +219,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1)), Name = "ConcreteClass1", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -219,9 +233,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass1(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AfterAllTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AfterAllTests.Test.verified.txt index ed931b1fba..35dae8961b 100644 --- a/TUnit.Core.SourceGenerator.Tests/AfterAllTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AfterAllTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.AfterTests.CleanupTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.CleanupTests)), Name = "CleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,9 +55,16 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AfterTests.CleanupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -92,7 +99,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource TestClassType = typeof(global::TUnit.TestProject.AfterTests.CleanupTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -112,7 +119,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -120,7 +127,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.CleanupTests)), Name = "CleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -134,9 +141,16 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AfterTests.CleanupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AfterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AfterTests.Test.verified.txt index ed931b1fba..35dae8961b 100644 --- a/TUnit.Core.SourceGenerator.Tests/AfterTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AfterTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.AfterTests.CleanupTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.CleanupTests)), Name = "CleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,9 +55,16 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AfterTests.CleanupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -92,7 +99,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource TestClassType = typeof(global::TUnit.TestProject.AfterTests.CleanupTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -112,7 +119,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.CleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -120,7 +127,7 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.CleanupTests)), Name = "CleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -134,9 +141,16 @@ internal sealed class TUnit_TestProject_AfterTests_CleanupTests_Test2_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AfterTests.CleanupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt index ab7a73d1a9..adcb5e7769 100644 --- a/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ArgsAsArrayTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Params__string___TestSo TestClassType = typeof(global::TUnit.TestProject.ArgsAsArrayTests), TestMethodName = "Params", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -45,7 +45,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Params__string___TestSo ReflectionInfo = typeof(global::TUnit.TestProject.ArgsAsArrayTests).GetMethod("Params", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string[]) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgsAsArrayTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgsAsArrayTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -53,7 +53,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Params__string___TestSo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ArgsAsArrayTests)), Name = "ArgsAsArrayTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -67,35 +67,41 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Params__string___TestSo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ArgsAsArrayTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 0: - instance.Params(new string[0]); - break; - case 1: - instance.Params((args[0] is null ? null : args[0] is string[] arr ? arr : new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); - break; - case 2: - instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]) }); - break; - case 3: - instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); - break; - case 4: - instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); - break; - case 5: - instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); - break; - case 6: - instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); - break; - default: - throw new global::System.ArgumentException($"Expected between 0 and 1 arguments, but got {args.Length}"); + switch (args.Length) + { + case 0: + instance.Params(new string[0]); + return default(global::System.Threading.Tasks.ValueTask); + case 1: + instance.Params((args[0] is null ? null : args[0] is string[] arr ? arr : new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]) })); + return default(global::System.Threading.Tasks.ValueTask); + case 2: + instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 3: + instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 4: + instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 5: + instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 6: + instance.Params(new string[] { TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected between 0 and 1 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -130,7 +136,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_ParamsEnumerable__IEnum TestClassType = typeof(global::TUnit.TestProject.ArgsAsArrayTests), TestMethodName = "ParamsEnumerable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -162,7 +168,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_ParamsEnumerable__IEnum ReflectionInfo = typeof(global::TUnit.TestProject.ArgsAsArrayTests).GetMethod("ParamsEnumerable", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Collections.Generic.IEnumerable) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgsAsArrayTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgsAsArrayTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -170,7 +176,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_ParamsEnumerable__IEnum TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ArgsAsArrayTests)), Name = "ArgsAsArrayTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -184,35 +190,41 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_ParamsEnumerable__IEnum }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ArgsAsArrayTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 0: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + case 1: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + case 2: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + case 3: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + case 4: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + case 5: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + case 6: + instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected between 0 and 1 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 0: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - case 1: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - case 2: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - case 3: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - case 4: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - case 5: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - case 6: - instance.ParamsEnumerable(TUnit.Core.Helpers.CastHelper.Cast>(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected between 0 and 1 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -247,7 +259,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Following_Non_Params__i TestClassType = typeof(global::TUnit.TestProject.ArgsAsArrayTests), TestMethodName = "Following_Non_Params", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -286,7 +298,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Following_Non_Params__i ReflectionInfo = typeof(global::TUnit.TestProject.ArgsAsArrayTests).GetMethod("Following_Non_Params", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(global::System.Collections.Generic.IEnumerable) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgsAsArrayTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgsAsArrayTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -294,7 +306,7 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Following_Non_Params__i TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ArgsAsArrayTests)), Name = "ArgsAsArrayTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -308,35 +320,41 @@ internal sealed class TUnit_TestProject_ArgsAsArrayTests_Following_Non_Params__i }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ArgsAsArrayTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + case 2: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + case 3: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + case 4: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + case 5: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + case 6: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + case 7: + instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected between 1 and 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - case 2: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - case 3: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - case 4: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - case 5: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - case 6: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - case 7: - instance.Following_Non_Params(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast>(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected between 1 and 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt index 1064d7160c..e574acda8e 100644 --- a/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ArgumentWithImplicitConverterTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Expli TestClassType = typeof(global::TUnit.TestProject.ArgumentWithImplicitConverterTests), TestMethodName = "Explicit", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Expli ReflectionInfo = typeof(global::TUnit.TestProject.ArgumentWithImplicitConverterTests).GetMethod("Explicit", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.ExplicitInteger) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgumentWithImplicitConverterTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgumentWithImplicitConverterTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -56,7 +56,7 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Expli TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ArgumentWithImplicitConverterTests)), Name = "ArgumentWithImplicitConverterTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -70,17 +70,23 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Expli }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ArgumentWithImplicitConverterTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Explicit(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Explicit(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -115,7 +121,7 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Impli TestClassType = typeof(global::TUnit.TestProject.ArgumentWithImplicitConverterTests), TestMethodName = "Implicit", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -150,7 +156,7 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Impli ReflectionInfo = typeof(global::TUnit.TestProject.ArgumentWithImplicitConverterTests).GetMethod("Implicit", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.ImplicitInteger) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgumentWithImplicitConverterTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ArgumentWithImplicitConverterTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -158,7 +164,7 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Impli TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ArgumentWithImplicitConverterTests)), Name = "ArgumentWithImplicitConverterTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -172,17 +178,23 @@ internal sealed class TUnit_TestProject_ArgumentWithImplicitConverterTests_Impli }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ArgumentWithImplicitConverterTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Implicit(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Implicit(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt index ebe1796e42..a7cdbc32db 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyAfterTests.Test.verified.txt @@ -35,7 +35,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase1_AfterAll1_After ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase1_AfterAll1_After TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1)), Name = "AssemblyBase1", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -111,7 +111,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase1_AfterEach1_Afte ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -119,7 +119,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase1_AfterEach1_Afte TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase1)), Name = "AssemblyBase1", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -186,7 +186,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase2_AfterAll2_After ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -194,7 +194,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase2_AfterAll2_After TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2)), Name = "AssemblyBase2", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -262,7 +262,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase2_AfterEach2_Afte ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -270,7 +270,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase2_AfterEach2_Afte TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase2)), Name = "AssemblyBase2", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -337,7 +337,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase3_AfterAll3_After ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -345,7 +345,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase3_AfterAll3_After TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3)), Name = "AssemblyBase3", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -413,7 +413,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase3_AfterEach3_Afte ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -421,7 +421,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyBase3_AfterEach3_Afte TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyBase3)), Name = "AssemblyBase3", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -488,7 +488,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -496,7 +496,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -573,7 +573,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -581,7 +581,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -649,7 +649,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -657,7 +657,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -741,7 +741,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("AfterAllCleanUpWithContextAndToken", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -749,7 +749,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_AfterAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -817,7 +817,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -825,7 +825,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -901,7 +901,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_ ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("Cleanup", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -909,7 +909,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_Cleanup_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -985,7 +985,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupW ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -993,7 +993,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupW TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1076,7 +1076,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupW ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests).GetMethod("CleanupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.AssemblyCleanupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1084,7 +1084,7 @@ internal static class TUnit_TestProject_AfterTests_AssemblyCleanupTests_CleanupW TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.AssemblyCleanupTests)), Name = "AssemblyCleanupTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt index 5338510711..4eada6fd58 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyBeforeTests.Test.verified.txt @@ -35,7 +35,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeAll1_Bef ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeAll1_Bef TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1)), Name = "AssemblyBase1", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -111,7 +111,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeEach1_Be ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -119,7 +119,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase1_BeforeEach1_Be TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase1)), Name = "AssemblyBase1", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -186,7 +186,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeAll2_Bef ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -194,7 +194,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeAll2_Bef TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2)), Name = "AssemblyBase2", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -262,7 +262,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeEach2_Be ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -270,7 +270,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase2_BeforeEach2_Be TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase2)), Name = "AssemblyBase2", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -337,7 +337,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeAll3_Bef ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -345,7 +345,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeAll3_Bef TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3)), Name = "AssemblyBase3", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -413,7 +413,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeEach3_Be ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblyBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -421,7 +421,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblyBase3_BeforeEach3_Be TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblyBase3)), Name = "AssemblyBase3", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -488,7 +488,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -496,7 +496,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -573,7 +573,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -581,7 +581,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -649,7 +649,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -657,7 +657,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -741,7 +741,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.AssemblyHookContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -749,7 +749,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_BeforeAll TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -817,7 +817,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_Bef ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -825,7 +825,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup_Bef TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -901,7 +901,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup__Ca ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("Setup", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -909,7 +909,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_Setup__Ca TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -985,7 +985,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWith ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -993,7 +993,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWith TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1076,7 +1076,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWith ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests).GetMethod("SetupWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.AssemblySetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1084,7 +1084,7 @@ internal static class TUnit_TestProject_BeforeTests_AssemblySetupTests_SetupWith TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.AssemblySetupTests)), Name = "AssemblySetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet10_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet10_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet8_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet8_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet9_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.DotNet9_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 3e33e83805..f5b2d3d7d7 100644 --- a/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AssemblyLoaderTests.Test.Net4_7.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/AsyncMethodDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AsyncMethodDataSourceDrivenTests.Test.verified.txt index a3a6d48f59..a4e5d2b5ae 100644 --- a/TUnit.Core.SourceGenerator.Tests/AsyncMethodDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AsyncMethodDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "AsyncMethodDataSource_SingleValue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -67,7 +67,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("AsyncMethodDataSource_SingleValue", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -75,7 +75,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -89,15 +89,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.AsyncMethodDataSource_SingleValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.AsyncMethodDataSource_SingleValue(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -133,7 +139,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "AsyncMethodDataSource_Tuples", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -194,7 +200,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("AsyncMethodDataSource_Tuples", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -202,7 +208,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -216,15 +222,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.AsyncMethodDataSource_Tuples(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - await instance.AsyncMethodDataSource_Tuples(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -260,7 +272,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "AsyncMethodDataSource_Enumerable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -314,7 +326,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("AsyncMethodDataSource_Enumerable", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -322,7 +334,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -336,15 +348,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.AsyncMethodDataSource_Enumerable(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.AsyncMethodDataSource_Enumerable(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -380,7 +398,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "AsyncMethodDataSource_Func", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -434,7 +452,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("AsyncMethodDataSource_Func", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -442,7 +460,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -456,15 +474,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.AsyncMethodDataSource_Func(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.AsyncMethodDataSource_Func(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -500,7 +524,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "AsyncMethodDataSource_WithArguments", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -554,7 +578,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("AsyncMethodDataSource_WithArguments", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -562,7 +586,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -576,15 +600,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.AsyncMethodDataSource_WithArguments(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.AsyncMethodDataSource_WithArguments(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -620,7 +650,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "AsyncMethodDataSource_ExternalClass", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -674,7 +704,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("AsyncMethodDataSource_ExternalClass", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -682,7 +712,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -696,15 +726,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_AsyncMe }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.AsyncMethodDataSource_ExternalClass(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.AsyncMethodDataSource_ExternalClass(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -740,7 +776,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_ValueTa TestClassType = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests), TestMethodName = "ValueTaskMethodDataSource_SingleValue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -794,7 +830,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_ValueTa ReflectionInfo = typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests).GetMethod("ValueTaskMethodDataSource_SingleValue", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -802,7 +838,7 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_ValueTa TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests)), Name = "AsyncMethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -816,15 +852,21 @@ internal sealed class TUnit_TestProject_AsyncMethodDataSourceDrivenTests_ValueTa }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AsyncMethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.ValueTaskMethodDataSource_SingleValue(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.ValueTaskMethodDataSource_SingleValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/AttributeTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/AttributeTests.Test.verified.txt index 45128e1095..60f3ea71f7 100644 --- a/TUnit.Core.SourceGenerator.Tests/AttributeTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/AttributeTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AttributeTests_MyTest_TestSource : globa TestClassType = typeof(global::TUnit.TestProject.AttributeTests), TestMethodName = "MyTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.AttributeTests.MixedAttribute(), @@ -45,7 +45,7 @@ internal sealed class TUnit_TestProject_AttributeTests_MyTest_TestSource : globa ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AttributeTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AttributeTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -53,7 +53,7 @@ internal sealed class TUnit_TestProject_AttributeTests_MyTest_TestSource : globa TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AttributeTests)), Name = "AttributeTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -67,10 +67,17 @@ internal sealed class TUnit_TestProject_AttributeTests_MyTest_TestSource : globa }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AttributeTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.MyTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.MyTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet10_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet10_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet8_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet8_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet9_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.DotNet9_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 3e33e83805..f5b2d3d7d7 100644 --- a/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BasicTests.Test.Net4_7.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/BeforeAllTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/BeforeAllTests.Test.verified.txt index cbf97f2596..264ca836a8 100644 --- a/TUnit.Core.SourceGenerator.Tests/BeforeAllTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BeforeAllTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.BeforeTests.SetupTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.SetupTests)), Name = "SetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,9 +55,16 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BeforeTests.SetupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -92,7 +99,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource TestClassType = typeof(global::TUnit.TestProject.BeforeTests.SetupTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -112,7 +119,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -120,7 +127,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.SetupTests)), Name = "SetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -134,9 +141,16 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BeforeTests.SetupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/BeforeTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/BeforeTests.Test.verified.txt index cbf97f2596..264ca836a8 100644 --- a/TUnit.Core.SourceGenerator.Tests/BeforeTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/BeforeTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.BeforeTests.SetupTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.SetupTests)), Name = "SetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,9 +55,16 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BeforeTests.SetupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -92,7 +99,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource TestClassType = typeof(global::TUnit.TestProject.BeforeTests.SetupTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -112,7 +119,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.SetupTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -120,7 +127,7 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.SetupTests)), Name = "SetupTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -134,9 +141,16 @@ internal sealed class TUnit_TestProject_BeforeTests_SetupTests_Test2_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BeforeTests.SetupTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet10_0.verified.txt index 0b5067de2e..01c15f97fd 100644 --- a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet10_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.Bugs._2971.Tests), TestMethodName = "SimpleTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Bugs._2971.SomeAttribute(typeof(global::System.Nullable<>)) @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2971.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2971", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -56,10 +56,17 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2971.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SimpleTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SimpleTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet8_0.verified.txt index 0b5067de2e..01c15f97fd 100644 --- a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet8_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.Bugs._2971.Tests), TestMethodName = "SimpleTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Bugs._2971.SomeAttribute(typeof(global::System.Nullable<>)) @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2971.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2971", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -56,10 +56,17 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2971.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SimpleTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SimpleTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet9_0.verified.txt index 0b5067de2e..01c15f97fd 100644 --- a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.DotNet9_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.Bugs._2971.Tests), TestMethodName = "SimpleTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Bugs._2971.SomeAttribute(typeof(global::System.Nullable<>)) @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2971.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2971", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -56,10 +56,17 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2971.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SimpleTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SimpleTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 9a1527db38..342d08b675 100644 --- a/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Bugs2971NullableTypeTest.Test.Net4_7.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.Bugs._2971.Tests), TestMethodName = "SimpleTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Bugs._2971.SomeAttribute(typeof(global::System.Nullable<>)) @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2971.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2971.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2971", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -56,10 +56,17 @@ internal sealed class TUnit_TestProject_Bugs__2971_Tests_SimpleTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2971.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SimpleTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SimpleTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt index cd51a54583..9354f67153 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassAndMethodArgumentsTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_Simple_Test TestClassType = typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests), TestMethodName = "Simple", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute("1"), @@ -39,7 +39,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_Simple_Test ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassAndMethodArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassAndMethodArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -47,7 +47,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_Simple_Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests)), Name = "ClassAndMethodArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(string)) @@ -73,9 +73,16 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_Simple_Test { return new global::TUnit.TestProject.ClassAndMethodArgumentsTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Simple(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Simple()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -110,7 +117,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_WithMethodL TestClassType = typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests), TestMethodName = "WithMethodLevel", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute("1"), @@ -149,7 +156,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_WithMethodL ReflectionInfo = typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests).GetMethod("WithMethodLevel", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassAndMethodArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassAndMethodArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -157,7 +164,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_WithMethodL TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests)), Name = "ClassAndMethodArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(string)) @@ -183,15 +190,21 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_WithMethodL { return new global::TUnit.TestProject.ClassAndMethodArgumentsTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.WithMethodLevel(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.WithMethodLevel(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -227,7 +240,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_IgnoreParam TestClassType = typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests), TestMethodName = "IgnoreParameters", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute("1"), @@ -266,7 +279,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_IgnoreParam ReflectionInfo = typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests).GetMethod("IgnoreParameters", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassAndMethodArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassAndMethodArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -274,7 +287,7 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_IgnoreParam TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassAndMethodArgumentsTests)), Name = "ClassAndMethodArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(string)) @@ -300,15 +313,21 @@ internal sealed class TUnit_TestProject_ClassAndMethodArgumentsTests_IgnoreParam { return new global::TUnit.TestProject.ClassAndMethodArgumentsTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.IgnoreParameters(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.IgnoreParameters(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/ClassConstructorTest.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassConstructorTest.Test.verified.txt index 9e4553bb0c..74e8910822 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassConstructorTest.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassConstructorTest.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ClassConstructorTest_Test_TestSource : g TestClassType = typeof(global::TUnit.TestProject.ClassConstructorTest), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ClassConstructorAttribute() @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_ClassConstructorTest_Test_TestSource : g ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassConstructorTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassConstructorTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_ClassConstructorTest_Test_TestSource : g TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassConstructorTest)), Name = "ClassConstructorTest", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.DummyReferenceTypeClass)) @@ -82,10 +82,17 @@ internal sealed class TUnit_TestProject_ClassConstructorTest_Test_TestSource : g // ClassConstructor attribute is present - instance creation handled at runtime throw new global::System.NotSupportedException("Instance creation for classes with ClassConstructor attribute is handled at runtime"); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt index 3c6bd47d47..3187ccef56 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "DataSource_Class", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("DataSource_Class", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.Library.Models.SomeAsyncDisposableClass) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,17 +68,23 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSource_Class(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSource_Class(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -113,7 +119,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "DataSource_Class_Generic", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -146,7 +152,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("DataSource_Class_Generic", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.Library.Models.SomeAsyncDisposableClass) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -154,7 +160,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -168,17 +174,23 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_DataSource_Cl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.DataSource_Class_Generic(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.DataSource_Class_Generic(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -213,7 +225,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "IsInitialized_With_1_ClassDataSource", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -246,7 +258,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("IsInitialized_With_1_ClassDataSource", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(InitializableClass) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -254,7 +266,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -268,15 +280,21 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.IsInitialized_With_1_ClassDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_1_ClassDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -312,7 +330,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "IsInitialized_With_2_ClassDataSources", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -352,7 +370,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("IsInitialized_With_2_ClassDataSources", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(InitializableClass), typeof(InitializableClass) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -360,7 +378,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -374,15 +392,21 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_2_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - await instance.IsInitialized_With_2_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -418,7 +442,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "IsInitialized_With_3_ClassDataSources", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -465,7 +489,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("IsInitialized_With_3_ClassDataSources", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(InitializableClass), typeof(InitializableClass), typeof(InitializableClass) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -473,7 +497,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -487,15 +511,21 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - await instance.IsInitialized_With_3_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_3_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -531,7 +561,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "IsInitialized_With_4_ClassDataSources", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -585,7 +615,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("IsInitialized_With_4_ClassDataSources", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(InitializableClass), typeof(InitializableClass), typeof(InitializableClass), typeof(InitializableClass) }, null)!.GetParameters()[3] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -593,7 +623,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -607,15 +637,21 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 4: + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_4_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + default: + throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 4: - await instance.IsInitialized_With_4_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -651,7 +687,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests), TestMethodName = "IsInitialized_With_5_ClassDataSources", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -712,7 +748,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests).GetMethod("IsInitialized_With_5_ClassDataSources", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(InitializableClass), typeof(InitializableClass), typeof(InitializableClass), typeof(InitializableClass), typeof(InitializableClass) }, null)!.GetParameters()[4] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -720,7 +756,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests)), Name = "ClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -734,15 +770,21 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests_IsInitialized }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 5: + return new global::System.Threading.Tasks.ValueTask(instance.IsInitialized_With_5_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]))); + default: + throw new global::System.ArgumentException($"Expected exactly 5 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 5: - await instance.IsInitialized_With_5_ClassDataSources(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 5 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt index d1584db553..a199ccf933 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTests2.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests2), TestMethodName = "Base_Derived1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -40,7 +40,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests2)), Name = "ClassDataSourceDrivenTests2", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests2.Base)) @@ -74,10 +74,17 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived { return new global::TUnit.TestProject.ClassDataSourceDrivenTests2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Base_Derived1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Base_Derived1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -112,7 +119,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests2), TestMethodName = "Base_Derived2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -139,7 +146,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTests2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -147,7 +154,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests2)), Name = "ClassDataSourceDrivenTests2", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTests2.Base)) @@ -173,10 +180,17 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTests2_Base_Derived { return new global::TUnit.TestProject.ClassDataSourceDrivenTests2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Base_Derived2(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Base_Derived2(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt index 856f6f9418..23866673ce 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassDataSourceDrivenTestsSharedKeyed.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed), TestMethodName = "DataSource_Class", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -47,7 +47,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed).GetMethod("DataSource_Class", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(SomeAsyncDisposableClass) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -55,7 +55,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed)), Name = "ClassDataSourceDrivenTestsSharedKeyed", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -69,17 +69,23 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSource_Class(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSource_Class(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -114,7 +120,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da TestClassType = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed), TestMethodName = "DataSource_Class_Generic", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -148,7 +154,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da ReflectionInfo = typeof(global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed).GetMethod("DataSource_Class_Generic", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(SomeAsyncDisposableClass) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -156,7 +162,7 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed)), Name = "ClassDataSourceDrivenTestsSharedKeyed", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -170,17 +176,23 @@ internal sealed class TUnit_TestProject_ClassDataSourceDrivenTestsSharedKeyed_Da }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ClassDataSourceDrivenTestsSharedKeyed(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.DataSource_Class_Generic(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.DataSource_Class_Generic(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ClassTupleDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ClassTupleDataSourceDrivenTests.Test.verified.txt index 49453ba6a9..dd7c2f5de3 100644 --- a/TUnit.Core.SourceGenerator.Tests/ClassTupleDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ClassTupleDataSourceDrivenTests.Test.verified.txt @@ -23,7 +23,7 @@ internal sealed class TUnit_TestProject_ClassTupleDataSourceDrivenTests_DataSour TestClassType = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests), TestMethodName = "DataSource_TupleMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -257,7 +257,7 @@ internal sealed class TUnit_TestProject_ClassTupleDataSourceDrivenTests_DataSour ReflectionInfo = typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests).GetMethod("DataSource_TupleMethod", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassTupleDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ClassTupleDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -265,7 +265,7 @@ internal sealed class TUnit_TestProject_ClassTupleDataSourceDrivenTests_DataSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ClassTupleDataSourceDrivenTests)), Name = "ClassTupleDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -357,17 +357,23 @@ internal sealed class TUnit_TestProject_ClassTupleDataSourceDrivenTests_DataSour Property4 = default(global::System.ValueTuple), }; }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - instance.DataSource_TupleMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + instance.DataSource_TupleMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ConcreteClassTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConcreteClassTests.Test.verified.txt index e65f62d62c..fdd9b1edda 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConcreteClassTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConcreteClassTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2), TestMethodName = "SecondTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2)), Name = "ConcreteClass2", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass2(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SecondTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SecondTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -117,7 +124,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -125,7 +132,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2)), Name = "ConcreteClass2", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -139,9 +146,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass2(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -176,7 +190,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute() @@ -197,7 +211,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -205,7 +219,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1)), Name = "ConcreteClass1", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -219,9 +233,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass1(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt index 87c5254250..582a7cb6ec 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConstantArgumentsTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_String1__string_T TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "String1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_String1__string_T ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("String1", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_String1__string_T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,15 +68,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_String1__string_T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.String1(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.String1(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -112,7 +118,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Int__int_TestSour TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "Int", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -145,7 +151,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Int__int_TestSour ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("Int", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -153,7 +159,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Int__int_TestSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -167,15 +173,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Int__int_TestSour }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Int(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Int(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -211,7 +223,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Double__double_Te TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "Double", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -244,7 +256,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Double__double_Te ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("Double", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(double) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -252,7 +264,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Double__double_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -266,15 +278,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Double__double_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Double(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Double(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -310,7 +328,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Float__float_Test TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "Float", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -343,7 +361,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Float__float_Test ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("Float", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(float) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -351,7 +369,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Float__float_Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -365,15 +383,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Float__float_Test }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Float(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Float(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -409,7 +433,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Long__long_TestSo TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "Long", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -442,7 +466,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Long__long_TestSo ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("Long", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(long) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -450,7 +474,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Long__long_TestSo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -464,15 +488,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_Long__long_TestSo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Long(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Long(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -508,7 +538,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_UInt__uint_TestSo TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "UInt", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -541,7 +571,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_UInt__uint_TestSo ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("UInt", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(uint) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -549,7 +579,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_UInt__uint_TestSo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -563,15 +593,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_UInt__uint_TestSo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.UInt(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.UInt(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -607,7 +643,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_ULong__ulong_Test TestClassType = typeof(global::TUnit.TestProject.ConstantArgumentsTests), TestMethodName = "ULong", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -640,7 +676,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_ULong__ulong_Test ReflectionInfo = typeof(global::TUnit.TestProject.ConstantArgumentsTests).GetMethod("ULong", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(ulong) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ConstantArgumentsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -648,7 +684,7 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_ULong__ulong_Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConstantArgumentsTests)), Name = "ConstantArgumentsTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -662,15 +698,21 @@ internal sealed class TUnit_TestProject_ConstantArgumentsTests_ULong__ulong_Test }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConstantArgumentsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.ULong(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.ULong(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt index 19426acde8..33ca6c1b5e 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConstantInBaseClassTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantInBaseClassTests_Some TestClassType = typeof(global::TUnit.TestProject.Bugs._1432.ConstantInBaseClassTests), TestMethodName = "SomeTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantInBaseClassTests_Some ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1432.ConstantInBaseClassTests).GetMethod("SomeTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1432.ConstantInBaseClassTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1432.ConstantInBaseClassTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantInBaseClassTests_Some TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1432.ConstantInBaseClassTests)), Name = "ConstantInBaseClassTests", Namespace = "TUnit.TestProject.Bugs._1432", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,15 +68,21 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantInBaseClassTests_Some }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1432.ConstantInBaseClassTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.SomeTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.SomeTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt index fb4ed16f94..92048fa458 100644 --- a/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ConstantsInInterpolatedStringsTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantsInInterpolatedString TestClassType = typeof(global::TUnit.TestProject.Bugs._1432.ConstantsInInterpolatedStringsTests), TestMethodName = "SomeTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantsInInterpolatedString ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1432.ConstantsInInterpolatedStringsTests).GetMethod("SomeTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1432.ConstantsInInterpolatedStringsTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1432.ConstantsInInterpolatedStringsTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantsInInterpolatedString TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1432.ConstantsInInterpolatedStringsTests)), Name = "ConstantsInInterpolatedStringsTests", Namespace = "TUnit.TestProject.Bugs._1432", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,15 +68,21 @@ internal sealed class TUnit_TestProject_Bugs__1432_ConstantsInInterpolatedString }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1432.ConstantsInInterpolatedStringsTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.SomeTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.SomeTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt index bca40cc40e..f28457c175 100644 --- a/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/CustomDisplayNameTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test_TestSource : TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute("A super important test!"), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -70,9 +70,16 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -107,7 +114,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test2_TestSource TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute("Another super important test!"), @@ -129,7 +136,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test2_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -137,7 +144,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test2_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -164,9 +171,16 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test2_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -201,7 +215,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test3__string_int TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "Test3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute("Test with: $value1 $value2 $value3!"), @@ -250,7 +264,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test3__string_int ReflectionInfo = typeof(global::TUnit.TestProject.CustomDisplayNameTests).GetMethod("Test3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string), typeof(int), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -258,7 +272,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test3__string_int TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -285,15 +299,21 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_Test3__string_int }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 3: + return new global::System.Threading.Tasks.ValueTask(instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 3: - await instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -329,7 +349,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_MethodDataSourceT TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "MethodDataSourceTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute("Test using MethodDataSource"), @@ -374,7 +394,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_MethodDataSourceT ReflectionInfo = typeof(global::TUnit.TestProject.CustomDisplayNameTests).GetMethod("MethodDataSourceTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -382,7 +402,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_MethodDataSourceT TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -409,15 +429,21 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_MethodDataSourceT }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.MethodDataSourceTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.MethodDataSourceTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -453,7 +479,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_TestParameterName TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "TestParameterNamePrefixBug", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute("Test this($someValue, $someValueType)"), @@ -496,7 +522,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_TestParameterName ReflectionInfo = typeof(global::TUnit.TestProject.CustomDisplayNameTests).GetMethod("TestParameterNamePrefixBug", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -504,7 +530,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_TestParameterName TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -531,15 +557,21 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_TestParameterName }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.TestParameterNamePrefixBug(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - await instance.TestParameterNamePrefixBug(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -575,7 +607,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_PasswordTest__str TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "PasswordTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -608,7 +640,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_PasswordTest__str ReflectionInfo = typeof(global::TUnit.TestProject.CustomDisplayNameTests).GetMethod("PasswordTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -616,7 +648,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_PasswordTest__str TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -643,15 +675,21 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_PasswordTest__str }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.PasswordTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.PasswordTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -687,7 +725,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_SameClassConstant TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "SameClassConstantTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute($"My test {"My constant"}"), @@ -709,7 +747,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_SameClassConstant ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -717,7 +755,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_SameClassConstant TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -744,9 +782,16 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_SameClassConstant }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.SameClassConstantTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.SameClassConstantTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -781,7 +826,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_DifferentClassCon TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "DifferentClassConstantTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute($"My test {"My constant"}"), @@ -803,7 +848,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_DifferentClassCon ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -811,7 +856,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_DifferentClassCon TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -838,9 +883,16 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_DifferentClassCon }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.DifferentClassConstantTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.DifferentClassConstantTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -875,7 +927,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_NestedClassConsta TestClassType = typeof(global::TUnit.TestProject.CustomDisplayNameTests), TestMethodName = "NestedClassConstantTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.DisplayNameAttribute($"My test {"My constant"}"), @@ -897,7 +949,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_NestedClassConsta ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.CustomDisplayNameTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -905,7 +957,7 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_NestedClassConsta TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.CustomDisplayNameTests)), Name = "CustomDisplayNameTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -932,9 +984,16 @@ internal sealed class TUnit_TestProject_CustomDisplayNameTests_NestedClassConsta }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.CustomDisplayNameTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.NestedClassConstantTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.NestedClassConstantTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt index 6f20a523ee..c49443a6ac 100644 --- a/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DataDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_T TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "DataSource_Method", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_T ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("DataSource_Method", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -56,7 +56,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -70,17 +70,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -115,7 +121,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_s TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "DataSource_Method", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -157,7 +163,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_s ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("DataSource_Method", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -165,7 +171,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_s TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -179,17 +185,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_DataSource_Method__int_s }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -224,7 +236,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EnumValue__TestEnum_Test TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "EnumValue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -259,7 +271,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EnumValue__TestEnum_Test ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("EnumValue", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.TestEnum) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -267,7 +279,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EnumValue__TestEnum_Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -281,17 +293,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EnumValue__TestEnum_Test }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.EnumValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.EnumValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -326,7 +344,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NullValue__string__TestS TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "NullValue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -359,7 +377,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NullValue__string__TestS ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("NullValue", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -367,7 +385,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NullValue__string__TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -381,17 +399,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NullValue__string__TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.NullValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.NullValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -426,7 +450,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EmptyString__string__Tes TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "EmptyString", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -459,7 +483,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EmptyString__string__Tes ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("EmptyString", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -467,7 +491,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EmptyString__string__Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -481,17 +505,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_EmptyString__string__Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.EmptyString(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.EmptyString(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -526,7 +556,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NonEmptyString__string__ TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "NonEmptyString", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -559,7 +589,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NonEmptyString__string__ ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("NonEmptyString", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -567,7 +597,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NonEmptyString__string__ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -581,17 +611,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_NonEmptyString__string__ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.NonEmptyString(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.NonEmptyString(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -626,7 +662,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_BooleanString__bool__Tes TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "BooleanString", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -661,7 +697,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_BooleanString__bool__Tes ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("BooleanString", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool?) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -669,7 +705,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_BooleanString__bool__Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -683,17 +719,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_BooleanString__bool__Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.BooleanString(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.BooleanString(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -728,7 +770,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_Type__Type_TestSource : TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "Type", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -761,7 +803,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_Type__Type_TestSource : ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("Type", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Type) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -769,7 +811,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_Type__Type_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -783,17 +825,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_Type__Type_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Type(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Type(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -828,7 +876,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntegerArray__int___Test TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "IntegerArray", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -861,7 +909,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntegerArray__int___Test ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("IntegerArray", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int[]) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -869,7 +917,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntegerArray__int___Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -883,17 +931,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntegerArray__int___Test }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.IntegerArray(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.IntegerArray(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -928,7 +982,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntMaxValue__int_TestSou TestClassType = typeof(global::TUnit.TestProject.DataDrivenTests), TestMethodName = "IntMaxValue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -961,7 +1015,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntMaxValue__int_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.DataDrivenTests).GetMethod("IntMaxValue", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -969,7 +1023,7 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntMaxValue__int_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataDrivenTests)), Name = "DataDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -983,17 +1037,23 @@ internal sealed class TUnit_TestProject_DataDrivenTests_IntMaxValue__int_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DataDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.IntMaxValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.IntMaxValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/DataSourceClassCombinedWithDataSourceMethodTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/DataSourceClassCombinedWithDataSourceMethodTests.Test.verified.txt index 937b837c69..f3385cb194 100644 --- a/TUnit.Core.SourceGenerator.Tests/DataSourceClassCombinedWithDataSourceMethodTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DataSourceClassCombinedWithDataSourceMethodTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_DataSourceClassCombinedWithDataSourceMet TestClassType = typeof(global::TUnit.TestProject.DataSourceClassCombinedWithDataSourceMethod), TestMethodName = "DataSourceClassCombinedWithDataSourceMethodTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -122,7 +122,7 @@ internal sealed class TUnit_TestProject_DataSourceClassCombinedWithDataSourceMet ReflectionInfo = typeof(global::TUnit.TestProject.DataSourceClassCombinedWithDataSourceMethod).GetMethod("DataSourceClassCombinedWithDataSourceMethodTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceClassCombinedWithDataSourceMethod", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceClassCombinedWithDataSourceMethod", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -130,7 +130,7 @@ internal sealed class TUnit_TestProject_DataSourceClassCombinedWithDataSourceMet TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataSourceClassCombinedWithDataSourceMethod)), Name = "DataSourceClassCombinedWithDataSourceMethod", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -156,17 +156,23 @@ internal sealed class TUnit_TestProject_DataSourceClassCombinedWithDataSourceMet { return new global::TUnit.TestProject.DataSourceClassCombinedWithDataSourceMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSourceClassCombinedWithDataSourceMethodTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSourceClassCombinedWithDataSourceMethodTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt b/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt index f6d1df611d..9bd5b95edd 100644 --- a/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Typed.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M TestClassType = typeof(global::TUnit.TestProject.DataSourceGeneratorTests), TestMethodName = "GeneratedData_Method", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -52,7 +52,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M ReflectionInfo = typeof(global::TUnit.TestProject.DataSourceGeneratorTests).GetMethod("GeneratedData_Method", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceGeneratorTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceGeneratorTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -60,7 +60,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataSourceGeneratorTests)), Name = "DataSourceGeneratorTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -100,17 +100,23 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M { return new global::TUnit.TestProject.DataSourceGeneratorTests(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.GeneratedData_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.GeneratedData_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -145,7 +151,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M TestClassType = typeof(global::TUnit.TestProject.DataSourceGeneratorTests), TestMethodName = "GeneratedData_Method2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -198,7 +204,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M ReflectionInfo = typeof(global::TUnit.TestProject.DataSourceGeneratorTests).GetMethod("GeneratedData_Method2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceGeneratorTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceGeneratorTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -206,7 +212,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataSourceGeneratorTests)), Name = "DataSourceGeneratorTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -246,17 +252,23 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M { return new global::TUnit.TestProject.DataSourceGeneratorTests(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 3: + instance.GeneratedData_Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 3: - instance.GeneratedData_Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -291,7 +303,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M TestClassType = typeof(global::TUnit.TestProject.DataSourceGeneratorTests), TestMethodName = "GeneratedData_Method3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -344,7 +356,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M ReflectionInfo = typeof(global::TUnit.TestProject.DataSourceGeneratorTests).GetMethod("GeneratedData_Method3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceGeneratorTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DataSourceGeneratorTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -352,7 +364,7 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DataSourceGeneratorTests)), Name = "DataSourceGeneratorTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -392,17 +404,23 @@ internal sealed class TUnit_TestProject_DataSourceGeneratorTests_GeneratedData_M { return new global::TUnit.TestProject.DataSourceGeneratorTests(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 3: + instance.GeneratedData_Method3(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 3: - instance.GeneratedData_Method3(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Untyped.verified.txt b/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Untyped.verified.txt index 682194531f..bd26b22a7c 100644 --- a/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Untyped.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DataSourceGeneratorTests.Untyped.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AutoDataTests_Test1__string_int_double_b TestClassType = typeof(global::TUnit.TestProject.AutoDataTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -66,7 +66,7 @@ internal sealed class TUnit_TestProject_AutoDataTests_Test1__string_int_double_b ReflectionInfo = typeof(global::TUnit.TestProject.AutoDataTests).GetMethod("Test1", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string), typeof(int), typeof(double), typeof(bool) }, null)!.GetParameters()[3] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AutoDataTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AutoDataTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -74,7 +74,7 @@ internal sealed class TUnit_TestProject_AutoDataTests_Test1__string_int_double_b TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AutoDataTests)), Name = "AutoDataTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -88,15 +88,21 @@ internal sealed class TUnit_TestProject_AutoDataTests_Test1__string_int_double_b }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AutoDataTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 4: - await instance.Test1(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); + switch (args.Length) + { + case 4: + return new global::System.Threading.Tasks.ValueTask(instance.Test1(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + default: + throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt index bfb7118f4c..894195d62b 100644 --- a/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DecimalArgumentTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Transfer__decimal_d TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "Transfer", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -55,7 +55,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Transfer__decimal_d ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("Transfer", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal), typeof(decimal) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -63,7 +63,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Transfer__decimal_d TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -77,15 +77,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Transfer__decimal_d }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 2: - await instance.Transfer(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.Transfer(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -121,7 +127,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SimpleDecimal__deci TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "SimpleDecimal", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -154,7 +160,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SimpleDecimal__deci ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("SimpleDecimal", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -162,7 +168,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SimpleDecimal__deci TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -176,15 +182,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SimpleDecimal__deci }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.SimpleDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.SimpleDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -220,7 +232,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SmallDecimal__decim TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "SmallDecimal", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -253,7 +265,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SmallDecimal__decim ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("SmallDecimal", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -261,7 +273,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SmallDecimal__decim TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -275,15 +287,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_SmallDecimal__decim }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.SmallDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.SmallDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -319,7 +337,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MaxDecimal__decimal TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "MaxDecimal", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -352,7 +370,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MaxDecimal__decimal ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("MaxDecimal", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -360,7 +378,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MaxDecimal__decimal TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -374,15 +392,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MaxDecimal__decimal }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.MaxDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.MaxDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -418,7 +442,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MinDecimal__decimal TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "MinDecimal", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -451,7 +475,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MinDecimal__decimal ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("MinDecimal", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -459,7 +483,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MinDecimal__decimal TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -473,15 +497,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MinDecimal__decimal }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.MinDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.MinDecimal(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -517,7 +547,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_ExplicitDecimalValu TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "ExplicitDecimalValue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -550,7 +580,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_ExplicitDecimalValu ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("ExplicitDecimalValue", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -558,7 +588,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_ExplicitDecimalValu TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -572,15 +602,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_ExplicitDecimalValu }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.ExplicitDecimalValue(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.ExplicitDecimalValue(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -616,7 +652,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MultipleDecimals__d TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "MultipleDecimals", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -663,7 +699,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MultipleDecimals__d ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("MultipleDecimals", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal), typeof(decimal), typeof(decimal) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -671,7 +707,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MultipleDecimals__d TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -685,15 +721,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_MultipleDecimals__d }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - await instance.MultipleDecimals(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + return new global::System.Threading.Tasks.ValueTask(instance.MultipleDecimals(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -729,7 +771,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Test__decimal_TestS TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -764,7 +806,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Test__decimal_TestS ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -772,7 +814,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Test__decimal_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -786,17 +828,23 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Test__decimal_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -831,7 +879,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TransactionDiscount TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "TransactionDiscountCalculations", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -901,7 +949,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TransactionDiscount ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("TransactionDiscountCalculations", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal), typeof(decimal), typeof(decimal), typeof(decimal), typeof(decimal), typeof(bool) }, null)!.GetParameters()[5] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -909,7 +957,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TransactionDiscount TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -923,17 +971,23 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TransactionDiscount }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 6: + instance.TransactionDiscountCalculations(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 6 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 6: - instance.TransactionDiscountCalculations(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 6 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -968,7 +1022,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality3__decimal_ TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "Equality3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -1001,7 +1055,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality3__decimal_ ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("Equality3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1009,7 +1063,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality3__decimal_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1023,15 +1077,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality3__decimal_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Equality3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Equality3(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -1067,7 +1127,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality4__decimal_ TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "Equality4", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -1100,7 +1160,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality4__decimal_ ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("Equality4", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1108,7 +1168,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality4__decimal_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1122,15 +1182,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_Equality4__decimal_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Equality4(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Equality4(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -1166,7 +1232,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TestMethod__decimal TestClassType = typeof(global::TUnit.TestProject.DecimalArgumentTests), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -1199,7 +1265,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TestMethod__decimal ReflectionInfo = typeof(global::TUnit.TestProject.DecimalArgumentTests).GetMethod("TestMethod", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(decimal) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DecimalArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1207,7 +1273,7 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TestMethod__decimal TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DecimalArgumentTests)), Name = "DecimalArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1221,15 +1287,21 @@ internal sealed class TUnit_TestProject_DecimalArgumentTests_TestMethod__decimal }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.DecimalArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.TestMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.TestMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet10_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet10_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet8_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet8_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet9_0.verified.txt index 1e53215ffc..c8a67d8392 100644 --- a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.DotNet9_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 3e33e83805..f5b2d3d7d7 100644 --- a/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/DisableReflectionScannerTests.Test.Net4_7.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "SynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_BasicTests_SynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SynchronousTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SynchronousTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "AsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -113,7 +120,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -121,7 +128,7 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -135,9 +142,16 @@ internal sealed class TUnit_TestProject_BasicTests_AsynchronousTest_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AsynchronousTest(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AsynchronousTest()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -172,7 +186,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TestClassType = typeof(global::TUnit.TestProject.BasicTests), TestMethodName = "ValueTaskAsynchronousTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -192,7 +206,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes ReturnType = typeof(global::System.Threading.Tasks.ValueTask), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.ValueTask)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BasicTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -200,7 +214,7 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BasicTests)), Name = "BasicTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -214,9 +228,16 @@ internal sealed class TUnit_TestProject_BasicTests_ValueTaskAsynchronousTest_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.BasicTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.ValueTaskAsynchronousTest(); + try + { + return instance.ValueTaskAsynchronousTest(); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt index d4e8356aa1..7b793e1562 100644 --- a/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/EnumMemberNamesTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_EnumMemberNamesTests_SomeTest TestClassType = typeof(global::TUnit.TestProject.Bugs._1432.EnumMemberNamesTests), TestMethodName = "SomeTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_EnumMemberNamesTests_SomeTest ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1432.EnumMemberNamesTests).GetMethod("SomeTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1432.EnumMemberNamesTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1432.EnumMemberNamesTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -56,7 +56,7 @@ internal sealed class TUnit_TestProject_Bugs__1432_EnumMemberNamesTests_SomeTest TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1432.EnumMemberNamesTests)), Name = "EnumMemberNamesTests", Namespace = "TUnit.TestProject.Bugs._1432", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -70,17 +70,23 @@ internal sealed class TUnit_TestProject_Bugs__1432_EnumMemberNamesTests_SomeTest }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1432.EnumMemberNamesTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.SomeTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.SomeTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/EnumerableDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/EnumerableDataSourceDrivenTests.Test.verified.txt index d63eb8e5e0..6ba8139e62 100644 --- a/TUnit.Core.SourceGenerator.Tests/EnumerableDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/EnumerableDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour TestClassType = typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests), TestMethodName = "DataSource_Method", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -67,7 +67,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour ReflectionInfo = typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests).GetMethod("DataSource_Method", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -75,7 +75,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests)), Name = "EnumerableDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -89,15 +89,21 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.EnumerableDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -133,7 +139,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour TestClassType = typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests), TestMethodName = "DataSource_Method2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -187,7 +193,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour ReflectionInfo = typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests).GetMethod("DataSource_Method2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -195,7 +201,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests)), Name = "EnumerableDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -209,15 +215,21 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.EnumerableDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.DataSource_Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.DataSource_Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -253,7 +265,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour TestClassType = typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests), TestMethodName = "DataSource_WithBaseReturn", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -307,7 +319,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour ReflectionInfo = typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests).GetMethod("DataSource_WithBaseReturn", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests.BaseValue) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -315,7 +327,7 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.EnumerableDataSourceDrivenTests)), Name = "EnumerableDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -329,17 +341,23 @@ internal sealed class TUnit_TestProject_EnumerableDataSourceDrivenTests_DataSour }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.EnumerableDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.DataSource_WithBaseReturn(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.DataSource_WithBaseReturn(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/EnumerableTupleDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/EnumerableTupleDataSourceDrivenTests.Test.verified.txt index efe5088b6a..3a9a293f16 100644 --- a/TUnit.Core.SourceGenerator.Tests/EnumerableTupleDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/EnumerableTupleDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_EnumerableTupleDataSourceDrivenTests_Dat TestClassType = typeof(global::TUnit.TestProject.EnumerableTupleDataSourceDrivenTests), TestMethodName = "DataSource_TupleMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -103,7 +103,7 @@ internal sealed class TUnit_TestProject_EnumerableTupleDataSourceDrivenTests_Dat ReflectionInfo = typeof(global::TUnit.TestProject.EnumerableTupleDataSourceDrivenTests).GetMethod("DataSource_TupleMethod", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableTupleDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.EnumerableTupleDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -111,7 +111,7 @@ internal sealed class TUnit_TestProject_EnumerableTupleDataSourceDrivenTests_Dat TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.EnumerableTupleDataSourceDrivenTests)), Name = "EnumerableTupleDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -125,17 +125,23 @@ internal sealed class TUnit_TestProject_EnumerableTupleDataSourceDrivenTests_Dat }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.EnumerableTupleDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - instance.DataSource_TupleMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + instance.DataSource_TupleMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt index 3d728feea7..bda4e49e2b 100644 --- a/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/ExpectedArgumentTypeTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_TypedArguments TestClassType = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests), TestMethodName = "TypedArguments", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -65,7 +65,7 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_TypedArguments ReflectionInfo = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests).GetMethod("TypedArguments", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(object), typeof(global::System.Type) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ExpectedArgumentTypeTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ExpectedArgumentTypeTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -73,7 +73,7 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_TypedArguments TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests)), Name = "ExpectedArgumentTypeTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -87,15 +87,21 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_TypedArguments }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ExpectedArgumentTypeTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 2: - await instance.TypedArguments(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.TypedArguments(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -131,7 +137,7 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_EnumTypes__obj TestClassType = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests), TestMethodName = "EnumTypes", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -185,7 +191,7 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_EnumTypes__obj ReflectionInfo = typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests).GetMethod("EnumTypes", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(object), typeof(global::System.Type), typeof(global::System.Type) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ExpectedArgumentTypeTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.ExpectedArgumentTypeTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -193,7 +199,7 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_EnumTypes__obj TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ExpectedArgumentTypeTests)), Name = "ExpectedArgumentTypeTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -207,15 +213,21 @@ internal sealed class TUnit_TestProject_ExpectedArgumentTypeTests_EnumTypes__obj }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ExpectedArgumentTypeTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 3: + return new global::System.Threading.Tasks.ValueTask(instance.EnumTypes(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 3: - await instance.EnumTypes(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/GenericMethodTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericMethodTests.Test.verified.txt index 2c7b677305..27c24ace39 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericMethodTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericMethodTests.Test.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect TestClassType = typeof(global::TUnit.TestProject.GenericMethodTests), TestMethodName = "AggregateBy_HasExpectedOutput", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -79,7 +79,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.GenericMethodTests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "AggregateBy_HasExpectedOutput" && m.GetParameters().Length == 6)?.GetParameters()[5]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.GenericMethodTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.GenericMethodTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -87,7 +87,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.GenericMethodTests)), Name = "GenericMethodTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -100,7 +100,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.GenericMethodTests(); }, @@ -114,7 +114,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect TestMethodName = "AggregateBy_HasExpectedOutput", GenericMethodTypeArguments = new global::System.Type[] { typeof(int), typeof(int), typeof(int)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.MethodDataSourceAttribute("AggregateBy_Numeric_TestData"), @@ -228,7 +228,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.GenericMethodTests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "AggregateBy_HasExpectedOutput" && m.GetParameters().Length == 6)?.GetParameters()[5]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.GenericMethodTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.GenericMethodTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -236,7 +236,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.GenericMethodTests)), Name = "GenericMethodTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -249,14 +249,21 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.GenericMethodTests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.GenericMethodTests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.AggregateBy_HasExpectedOutput((global::System.Collections.Generic.IEnumerable)args[0]!, (global::System.Func)args[1]!, (global::System.Func)args[2]!, (global::System.Func)args[3]!, (global::System.Collections.Generic.IEqualityComparer)args[4]!, (global::System.Collections.Generic.IEnumerable>)args[5]!)); + try + { + var typedInstance = (global::TUnit.TestProject.GenericMethodTests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.AggregateBy_HasExpectedOutput((global::System.Collections.Generic.IEnumerable)args[0]!, (global::System.Func)args[1]!, (global::System.Func)args[2]!, (global::System.Func)args[3]!, (global::System.Collections.Generic.IEqualityComparer)args[4]!, (global::System.Collections.Generic.IEnumerable>)args[5]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -268,7 +275,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect TestMethodName = "AggregateBy_HasExpectedOutput", GenericMethodTypeArguments = new global::System.Type[] { typeof(string), typeof(string), typeof(string)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.MethodDataSourceAttribute("AggregateBy_Numeric_TestData"), @@ -382,7 +389,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.GenericMethodTests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "AggregateBy_HasExpectedOutput" && m.GetParameters().Length == 6)?.GetParameters()[5]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.GenericMethodTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.GenericMethodTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -390,7 +397,7 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.GenericMethodTests)), Name = "GenericMethodTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -403,14 +410,21 @@ internal sealed class TUnit_TestProject_GenericMethodTests_AggregateBy_HasExpect return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.GenericMethodTests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.GenericMethodTests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.AggregateBy_HasExpectedOutput((global::System.Collections.Generic.IEnumerable)args[0]!, (global::System.Func)args[1]!, (global::System.Func)args[2]!, (global::System.Func)args[3]!, (global::System.Collections.Generic.IEqualityComparer)args[4]!, (global::System.Collections.Generic.IEnumerable>)args[5]!)); + try + { + var typedInstance = (global::TUnit.TestProject.GenericMethodTests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.AggregateBy_HasExpectedOutput((global::System.Collections.Generic.IEnumerable)args[0]!, (global::System.Func)args[1]!, (global::System.Func)args[2]!, (global::System.Func)args[3]!, (global::System.Collections.Generic.IEqualityComparer)args[4]!, (global::System.Collections.Generic.IEnumerable>)args[5]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_EmptyGenericRegistry_WhenNoGenericsFound.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_EmptyGenericRegistry_WhenNoGenericsFound.verified.txt index f47d5cfbc7..2c1596bc85 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_EmptyGenericRegistry_WhenNoGenericsFound.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_EmptyGenericRegistry_WhenNoGenericsFound.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_SimpleTestClass_NonGenericTest_TestSourc TestClassType = typeof(global::TUnit.TestProject.SimpleTestClass), TestMethodName = "NonGenericTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_SimpleTestClass_NonGenericTest_TestSourc ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.SimpleTestClass", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.SimpleTestClass", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_SimpleTestClass_NonGenericTest_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.SimpleTestClass)), Name = "SimpleTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_SimpleTestClass_NonGenericTest_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.SimpleTestClass(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.NonGenericTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.NonGenericTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericConstraints_WithInstantiation.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericConstraints_WithInstantiation.verified.txt index 6af0b5f935..d4b07e0d6f 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericConstraints_WithInstantiation.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericConstraints_WithInstantiation.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod TestClassType = typeof(global::TUnit.TestProject.ConstrainedGenericTestClass<>), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), @@ -36,7 +36,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.ConstrainedGenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.ConstrainedGenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +44,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.ConstrainedGenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "ConstrainedGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { var genericType = typeof(global::TUnit.TestProject.ConstrainedGenericTestClass<>); if (typeArgs.Length > 0) @@ -76,7 +76,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod TestClassType = typeof(global::TUnit.TestProject.ConstrainedGenericTestClass), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), @@ -99,7 +99,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.ConstrainedGenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.ConstrainedGenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -107,7 +107,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.ConstrainedGenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "ConstrainedGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -120,14 +120,21 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.ConstrainedGenericTestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.ConstrainedGenericTestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.ConstrainedGenericTestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -138,7 +145,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod TestClassType = typeof(global::TUnit.TestProject.ConstrainedGenericTestClass), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), @@ -161,7 +168,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.ConstrainedGenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.ConstrainedGenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -169,7 +176,7 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.ConstrainedGenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "ConstrainedGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -182,14 +189,21 @@ internal sealed class TUnit_TestProject_ConstrainedGenericTestClass_T_TestMethod return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.ConstrainedGenericTestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.ConstrainedGenericTestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.ConstrainedGenericTestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestClass_WithExplicitInstantiation.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestClass_WithExplicitInstantiation.verified.txt index e410c5c297..d14b92862b 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestClass_WithExplicitInstantiation.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestClass_WithExplicitInstantiation.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource TestClassType = typeof(global::TUnit.TestProject.GenericTestClass<>), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), @@ -36,7 +36,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.GenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.GenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +44,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.GenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "GenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { var genericType = typeof(global::TUnit.TestProject.GenericTestClass<>); if (typeArgs.Length > 0) @@ -76,7 +76,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource TestClassType = typeof(global::TUnit.TestProject.GenericTestClass), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), @@ -99,7 +99,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.GenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.GenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -107,7 +107,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.GenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "GenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -120,14 +120,21 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.GenericTestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.GenericTestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.GenericTestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -138,7 +145,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource TestClassType = typeof(global::TUnit.TestProject.GenericTestClass), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), @@ -161,7 +168,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.GenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.GenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -169,7 +176,7 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.GenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "GenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -182,14 +189,21 @@ internal sealed class TUnit_TestProject_GenericTestClass_T_TestMethod_TestSource return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.GenericTestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.GenericTestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.GenericTestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestMethod_WithExplicitInstantiation.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestMethod_WithExplicitInstantiation.verified.txt index f8195e18fe..7651fbdfec 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestMethod_WithExplicitInstantiation.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_GenericTestMethod_WithExplicitInstantiation.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : TestClassType = typeof(global::TUnit.TestProject.TestClass), TestMethodName = "GenericTestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), @@ -36,7 +36,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.TestClass", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.TestClass", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +44,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TestClass)), Name = "TestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.TestClass(); }, @@ -71,7 +71,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : TestMethodName = "GenericTestMethod", GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), @@ -94,7 +94,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.TestClass", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.TestClass", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -102,7 +102,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TestClass)), Name = "TestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -115,14 +115,21 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.TestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.TestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericTestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.TestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericTestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -134,7 +141,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : TestMethodName = "GenericTestMethod", GenericMethodTypeArguments = new global::System.Type[] { typeof(string)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int)), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(string)), @@ -157,7 +164,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.TestClass", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.TestClass", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -165,7 +172,7 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TestClass)), Name = "TestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -178,14 +185,21 @@ internal sealed class TUnit_TestProject_TestClass_GenericTestMethod_TestSource : return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.TestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.TestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericTestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.TestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericTestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_MultipleGenericParameters.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_MultipleGenericParameters.verified.txt index d207458491..ecf6ff1e70 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_MultipleGenericParameters.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_MultipleGenericParameters.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T TestClassType = typeof(global::TUnit.TestProject.MultiGenericTestClass<,>), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int), typeof(string)), @@ -36,7 +36,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.MultiGenericTestClass<,>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.MultiGenericTestClass<,>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +44,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.MultiGenericTestClass<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), Name = "MultiGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { var genericType = typeof(global::TUnit.TestProject.MultiGenericTestClass<,>); if (typeArgs.Length > 0) @@ -76,7 +76,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T TestClassType = typeof(global::TUnit.TestProject.MultiGenericTestClass), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int), typeof(string)), @@ -99,7 +99,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.MultiGenericTestClass<,>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.MultiGenericTestClass<,>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -107,7 +107,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.MultiGenericTestClass<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), Name = "MultiGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -120,14 +120,21 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.MultiGenericTestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.MultiGenericTestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.MultiGenericTestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -138,7 +145,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T TestClassType = typeof(global::TUnit.TestProject.MultiGenericTestClass), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(int), typeof(string)), @@ -161,7 +168,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.MultiGenericTestClass<,>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.MultiGenericTestClass<,>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -169,7 +176,7 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.MultiGenericTestClass<,>), [new global::TUnit.Core.GenericParameter(0, false, "T1"), new global::TUnit.Core.GenericParameter(1, false, "T2")]), Name = "MultiGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -182,14 +189,21 @@ internal sealed class TUnit_TestProject_MultiGenericTestClass_T1_T2_TestMethod_T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.MultiGenericTestClass(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.MultiGenericTestClass)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.MultiGenericTestClass)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_NestedGenericTypes.verified.txt b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_NestedGenericTypes.verified.txt index 04734c2922..711d56824e 100644 --- a/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_NestedGenericTypes.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GenericTypeResolverTests.Test_NestedGenericTypes.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test TestClassType = typeof(global::TUnit.TestProject.NestedGenericTestClass<>), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::System.Collections.Generic.List)), @@ -36,7 +36,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.NestedGenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.NestedGenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +44,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.NestedGenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "NestedGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { var genericType = typeof(global::TUnit.TestProject.NestedGenericTestClass<>); if (typeArgs.Length > 0) @@ -76,7 +76,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test TestClassType = typeof(global::TUnit.TestProject.NestedGenericTestClass>), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::System.Collections.Generic.List)), @@ -99,7 +99,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.NestedGenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.NestedGenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -107,7 +107,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.NestedGenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "NestedGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -120,14 +120,21 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.NestedGenericTestClass>(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.NestedGenericTestClass>)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.NestedGenericTestClass>)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -138,7 +145,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test TestClassType = typeof(global::TUnit.TestProject.NestedGenericTestClass>), TestMethodName = "TestMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.GenerateGenericTestAttribute(typeof(global::System.Collections.Generic.List)), @@ -161,7 +168,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.NestedGenericTestClass<>", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("GenericTypeResolverTests:global::TUnit.TestProject.NestedGenericTestClass<>", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -169,7 +176,7 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test TypeInfo = new global::TUnit.Core.ConstructedGeneric(typeof(global::TUnit.TestProject.NestedGenericTestClass<>), [new global::TUnit.Core.GenericParameter(0, false, "T")]), Name = "NestedGenericTestClass", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("GenericTypeResolverTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "GenericTypeResolverTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -182,14 +189,21 @@ internal sealed class TUnit_TestProject_NestedGenericTestClass_T_TestMethod_Test return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.NestedGenericTestClass>(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.NestedGenericTestClass>)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + try + { + var typedInstance = (global::TUnit.TestProject.NestedGenericTestClass>)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.TestMethod()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt index 32a9f3edd1..dde41a56cf 100644 --- a/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GlobalStaticAfterEachTests.Test.verified.txt @@ -35,7 +35,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase1_AfterEach1_After_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase1_AfterEach1_After_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalBase1)), Name = "GlobalBase1", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -110,7 +110,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase2_AfterEach2_After_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -118,7 +118,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase2_AfterEach2_After_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalBase2)), Name = "GlobalBase2", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -185,7 +185,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase3_AfterEach3_After_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -193,7 +193,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase3_AfterEach3_After_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalBase3)), Name = "GlobalBase3", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -260,7 +260,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_Af ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -268,7 +268,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp_Af TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -344,7 +344,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp__C ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("CleanUp", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -352,7 +352,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUp__C TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -428,7 +428,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWit ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("CleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -436,7 +436,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWit TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -519,7 +519,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWit ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("CleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -527,7 +527,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_CleanUpWit TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -601,7 +601,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase1_AfterAll1__TestCo ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalBase1).GetMethod("AfterAll1", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -609,7 +609,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase1_AfterAll1__TestCo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalBase1)), Name = "GlobalBase1", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -684,7 +684,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase2_AfterAll2__TestCo ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalBase2).GetMethod("AfterAll2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -692,7 +692,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase2_AfterAll2__TestCo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalBase2)), Name = "GlobalBase2", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -767,7 +767,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase3_AfterAll3__TestCo ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalBase3).GetMethod("AfterAll3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -775,7 +775,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalBase3_AfterAll3__TestCo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalBase3)), Name = "GlobalBase3", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -850,7 +850,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("AfterAllCleanUp", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -858,7 +858,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -940,7 +940,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("AfterAllCleanUp", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -948,7 +948,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1023,7 +1023,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("AfterAllCleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1031,7 +1031,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1113,7 +1113,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl ReflectionInfo = typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests).GetMethod("AfterAllCleanUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AfterTests.GlobalCleanUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1121,7 +1121,7 @@ internal static class TUnit_TestProject_AfterTests_GlobalCleanUpTests_AfterAllCl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AfterTests.GlobalCleanUpTests)), Name = "GlobalCleanUpTests", Namespace = "TUnit.TestProject.AfterTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null diff --git a/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt index 1824176b45..945e9a3f3e 100644 --- a/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/GlobalStaticBeforeEachTests.Test.verified.txt @@ -35,7 +35,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase1_BeforeEach1_Befo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase1_BeforeEach1_Befo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1)), Name = "GlobalBase1", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -110,7 +110,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase2_BeforeEach2_Befo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -118,7 +118,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase2_BeforeEach2_Befo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2)), Name = "GlobalBase2", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -185,7 +185,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase3_BeforeEach3_Befo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -193,7 +193,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase3_BeforeEach3_Befo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3)), Name = "GlobalBase3", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -260,7 +260,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_Befor ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -268,7 +268,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp_Befor TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -344,7 +344,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp__Canc ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("SetUp", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -352,7 +352,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUp__Canc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -428,7 +428,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithCo ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("SetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -436,7 +436,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithCo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -519,7 +519,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithCo ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("SetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -527,7 +527,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_SetUpWithCo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -601,7 +601,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase1_BeforeAll1__Test ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1).GetMethod("BeforeAll1", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -609,7 +609,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase1_BeforeAll1__Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase1)), Name = "GlobalBase1", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -684,7 +684,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase2_BeforeAll2__Test ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2).GetMethod("BeforeAll2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -692,7 +692,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase2_BeforeAll2__Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase2)), Name = "GlobalBase2", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -767,7 +767,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase3_BeforeAll3__Test ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3).GetMethod("BeforeAll3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalBase3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -775,7 +775,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalBase3_BeforeAll3__Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalBase3)), Name = "GlobalBase3", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -850,7 +850,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("BeforeAllSetUp", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -858,7 +858,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -940,7 +940,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("BeforeAllSetUp", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -948,7 +948,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1023,7 +1023,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1031,7 +1031,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1113,7 +1113,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe ReflectionInfo = typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests).GetMethod("BeforeAllSetUpWithContext", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Static, null, new global::System.Type[] { typeof(global::TUnit.Core.TestContext), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.BeforeTests.GlobalSetUpTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1121,7 +1121,7 @@ internal static class TUnit_TestProject_BeforeTests_GlobalSetUpTests_BeforeAllSe TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.BeforeTests.GlobalSetUpTests)), Name = "GlobalSetUpTests", Namespace = "TUnit.TestProject.BeforeTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null diff --git a/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt index 30f345f65e..715c01f082 100644 --- a/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Hooks1589.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.Bugs._1589.MyTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -40,7 +40,7 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1589.MyTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1589.MyTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1589.MyTests)), Name = "MyTests", Namespace = "TUnit.TestProject.Bugs._1589", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._1589.MyFixture)) @@ -74,9 +74,16 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl { return new global::TUnit.TestProject.Bugs._1589.MyTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt index 6b791bb019..9d5d9f0ecd 100644 --- a/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Hooks1594.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.Bugs._1594.MyTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -40,7 +40,7 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1594.MyTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1594.MyTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1594.MyTests)), Name = "MyTests", Namespace = "TUnit.TestProject.Bugs._1594", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._1594.MyFixture)) @@ -74,10 +74,17 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl { return new global::TUnit.TestProject.Bugs._1594.MyTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt b/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt index fc1175e078..ed1c7c23dc 100644 --- a/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/HooksTests.DisposableFieldTests.verified.txt @@ -35,7 +35,7 @@ internal static class TUnit_TestProject_DisposableFieldTests_Setup_Before_TestIn ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DisposableFieldTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DisposableFieldTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal static class TUnit_TestProject_DisposableFieldTests_Setup_Before_TestIn TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DisposableFieldTests)), Name = "DisposableFieldTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -110,7 +110,7 @@ internal static class TUnit_TestProject_DisposableFieldTests_Blah_After_TestInit ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DisposableFieldTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.DisposableFieldTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -118,7 +118,7 @@ internal static class TUnit_TestProject_DisposableFieldTests_Blah_After_TestInit TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.DisposableFieldTests)), Name = "DisposableFieldTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null diff --git a/TUnit.Core.SourceGenerator.Tests/InheritedPropertySetterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/InheritedPropertySetterTests.Test.verified.txt index 2299f9c2ba..2612f8d4f3 100644 --- a/TUnit.Core.SourceGenerator.Tests/InheritedPropertySetterTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/InheritedPropertySetterTests.Test.verified.txt @@ -27,7 +27,7 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.PropertySetterTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -199,7 +199,7 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PropertySetterTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PropertySetterTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -207,7 +207,7 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PropertySetterTests)), Name = "PropertySetterTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -320,9 +320,16 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl Property6 = default!, Property7 = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -371,7 +378,7 @@ internal sealed class TUnit_TestProject_InheritedPropertySetterTests_Test_TestSo TestClassType = typeof(global::TUnit.TestProject.InheritedPropertySetterTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -533,7 +540,7 @@ internal sealed class TUnit_TestProject_InheritedPropertySetterTests_Test_TestSo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedPropertySetterTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedPropertySetterTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -541,7 +548,7 @@ internal sealed class TUnit_TestProject_InheritedPropertySetterTests_Test_TestSo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedPropertySetterTests)), Name = "InheritedPropertySetterTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -564,9 +571,16 @@ internal sealed class TUnit_TestProject_InheritedPropertySetterTests_Test_TestSo Property6 = default!, Property7 = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/InheritedTestsFromDifferentProjectTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/InheritedTestsFromDifferentProjectTests.Test.verified.txt index 705b0d2311..2994f8ddff 100644 --- a/TUnit.Core.SourceGenerator.Tests/InheritedTestsFromDifferentProjectTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/InheritedTestsFromDifferentProjectTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TestClassType = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(Pass), @@ -36,7 +36,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +44,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests)), Name = "InheritedTestsFromDifferentProjectTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -58,10 +58,17 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -96,7 +103,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TestClassType = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests), TestMethodName = "GenericMethodDataSource", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(Pass), @@ -131,7 +138,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ ReflectionInfo = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests).GetMethod("GenericMethodDataSource", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -139,7 +146,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests)), Name = "InheritedTestsFromDifferentProjectTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -153,17 +160,23 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.GenericMethodDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.GenericMethodDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -198,7 +211,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TestClassType = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests), TestMethodName = "NonGenericMethodDataSource", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(Pass), @@ -244,7 +257,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ ReflectionInfo = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests).GetMethod("NonGenericMethodDataSource", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -252,7 +265,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests)), Name = "InheritedTestsFromDifferentProjectTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -266,17 +279,23 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.NonGenericMethodDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.NonGenericMethodDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -311,7 +330,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TestClassType = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests), TestMethodName = "VerifyInheritedCategoriesAreAvailable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(Pass), @@ -334,7 +353,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -342,7 +361,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests)), Name = "InheritedTestsFromDifferentProjectTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -356,9 +375,16 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.VerifyInheritedCategoriesAreAvailable(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.VerifyInheritedCategoriesAreAvailable()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -393,7 +419,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TestClassType = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests), TestMethodName = "BaseTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.CategoryAttribute("BaseCategory"), @@ -417,7 +443,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -425,7 +451,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests)), Name = "InheritedTestsFromDifferentProjectTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -439,10 +465,17 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.BaseTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.BaseTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -477,7 +510,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TestClassType = typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests), TestMethodName = "BaseTestWithMultipleCategories", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.CategoryAttribute("AnotherBaseCategory"), @@ -502,7 +535,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -510,7 +543,7 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests)), Name = "InheritedTestsFromDifferentProjectTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -524,10 +557,17 @@ internal sealed class TUnit_TestProject_InheritedTestsFromDifferentProjectTests_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.InheritedTestsFromDifferentProjectTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.BaseTestWithMultipleCategories(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.BaseTestWithMultipleCategories(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/InheritsTestsAbstractTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/InheritsTestsAbstractTests.Test.verified.txt index e65f62d62c..fdd9b1edda 100644 --- a/TUnit.Core.SourceGenerator.Tests/InheritsTestsAbstractTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/InheritsTestsAbstractTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2), TestMethodName = "SecondTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2)), Name = "ConcreteClass2", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_SecondTest_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass2(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.SecondTest(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.SecondTest(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute(), @@ -117,7 +124,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -125,7 +132,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass2)), Name = "ConcreteClass2", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -139,9 +146,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass2_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass2(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -176,7 +190,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TestClassType = typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1), TestMethodName = "AssertClassName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.InheritsTestsAttribute() @@ -197,7 +211,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.AbstractTests.ConcreteClass1", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -205,7 +219,7 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AbstractTests.ConcreteClass1)), Name = "ConcreteClass1", Namespace = "TUnit.TestProject.AbstractTests", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -219,9 +233,16 @@ internal sealed class TUnit_TestProject_AbstractTests_ConcreteClass1_AssertClass }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AbstractTests.ConcreteClass1(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.AssertClassName(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.AssertClassName()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt index 01abfcc6ee..94339aecb1 100644 --- a/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/InheritsTestsTests.Test.verified.txt @@ -17,12 +17,13 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_BaseClass_Test__int_Test TestClassType = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.RepeatAttribute(10), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) ], + RepeatCount = 10, DataSources = new global::TUnit.Core.IDataSourceAttribute[] { new global::TUnit.Core.ArgumentsAttribute(1), @@ -79,7 +80,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_BaseClass_Test__int_Test ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.BaseClass", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.BaseClass", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -87,7 +88,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_BaseClass_Test__int_Test TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass)), Name = "BaseClass", Namespace = "TUnit.TestProject.Bugs._1924.None", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -117,15 +118,21 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_BaseClass_Test__int_Test { Data = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -165,13 +172,14 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests_Test__int_TestSour TestClassType = typeof(global::TUnit.TestProject.Bugs._1924.None.Tests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.RepeatAttribute(10), new global::TUnit.Core.InheritsTestsAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) ], + RepeatCount = 10, DataSources = new global::TUnit.Core.IDataSourceAttribute[] { new global::TUnit.Core.ArgumentsAttribute(1), @@ -228,7 +236,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests_Test__int_TestSour ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -236,7 +244,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests_Test__int_TestSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1924.None.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1924.None", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -253,15 +261,21 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests_Test__int_TestSour { Data = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -301,13 +315,14 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests2_Test__int_TestSou TestClassType = typeof(global::TUnit.TestProject.Bugs._1924.None.Tests2), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.RepeatAttribute(10), new global::TUnit.Core.InheritsTestsAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) ], + RepeatCount = 10, DataSources = new global::TUnit.Core.IDataSourceAttribute[] { new global::TUnit.Core.ArgumentsAttribute(1), @@ -364,7 +379,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests2_Test__int_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.Tests2", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.Tests2", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -372,7 +387,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests2_Test__int_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1924.None.Tests2)), Name = "Tests2", Namespace = "TUnit.TestProject.Bugs._1924.None", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -389,15 +404,21 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests2_Test__int_TestSou { Data = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -437,13 +458,14 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests3_Test__int_TestSou TestClassType = typeof(global::TUnit.TestProject.Bugs._1924.None.Tests3), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.RepeatAttribute(10), new global::TUnit.Core.InheritsTestsAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) ], + RepeatCount = 10, DataSources = new global::TUnit.Core.IDataSourceAttribute[] { new global::TUnit.Core.ArgumentsAttribute(1), @@ -500,7 +522,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests3_Test__int_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1924.None.BaseClass).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.Tests3", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1924.None.Tests3", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -508,7 +530,7 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests3_Test__int_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1924.None.Tests3)), Name = "Tests3", Namespace = "TUnit.TestProject.Bugs._1924.None", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -525,15 +547,21 @@ internal sealed class TUnit_TestProject_Bugs__1924_None_Tests3_Test__int_TestSou { Data = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/Issue2887Tests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Issue2887Tests.Test.verified.txt index e08e0e980c..716c20d744 100644 --- a/TUnit.Core.SourceGenerator.Tests/Issue2887Tests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Issue2887Tests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__Issue2887_ActualTestClass_Test1_Te TestClassType = typeof(global::TUnit.TestProject.Bugs._Issue2887.ActualTestClass), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ClassConstructorAttribute() @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_Bugs__Issue2887_ActualTestClass_Test1_Te ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._Issue2887.ActualTestClass", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._Issue2887.ActualTestClass", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_Bugs__Issue2887_ActualTestClass_Test1_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._Issue2887.ActualTestClass)), Name = "ActualTestClass", Namespace = "TUnit.TestProject.Bugs._Issue2887", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._Issue2887.IServiceProvider)) @@ -69,10 +69,17 @@ internal sealed class TUnit_TestProject_Bugs__Issue2887_ActualTestClass_Test1_Te // ClassConstructor attribute is present - instance creation handled at runtime throw new global::System.NotSupportedException("Instance creation for classes with ClassConstructor attribute is handled at runtime"); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt index 34625e2e3b..f3e953ed52 100644 --- a/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/MatrixTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_One__string_int_b TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "MatrixTest_One", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -60,7 +60,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_One__string_int_b ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("MatrixTest_One", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string), typeof(int), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -68,7 +68,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_One__string_int_b TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -82,15 +82,21 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_One__string_int_b }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - await instance.MatrixTest_One(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_One(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -126,7 +132,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Two__int_int_int_ TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "MatrixTest_Two", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -180,7 +186,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Two__int_int_int_ ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("MatrixTest_Two", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(int), typeof(int), typeof(bool) }, null)!.GetParameters()[3] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -188,7 +194,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Two__int_int_int_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -202,15 +208,21 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Two__int_int_int_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 4: + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Two(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]))); + default: + throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 4: - await instance.MatrixTest_Two(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 4 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -246,7 +258,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Enum__int_TestEnu TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "MatrixTest_Enum", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -293,7 +305,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Enum__int_TestEnu ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("MatrixTest_Enum", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(global::TUnit.TestProject.TestEnum), typeof(global::TUnit.TestProject.TestEnum?) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -301,7 +313,7 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Enum__int_TestEnu TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -315,15 +327,21 @@ internal sealed class TUnit_TestProject_MatrixTests_MatrixTest_Enum__int_TestEnu }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 3: + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest_Enum(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]))); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 3: - await instance.MatrixTest_Enum(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -359,7 +377,7 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools__string_bo TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "AutoGenerateBools", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -399,7 +417,7 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools__string_bo ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("AutoGenerateBools", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string), typeof(bool) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -407,7 +425,7 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools__string_bo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -421,15 +439,21 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools__string_bo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 2: - await instance.AutoGenerateBools(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -465,7 +489,7 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools2__string_b TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "AutoGenerateBools2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -505,7 +529,7 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools2__string_b ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("AutoGenerateBools2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string), typeof(bool?) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -513,7 +537,7 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools2__string_b TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -527,15 +551,21 @@ internal sealed class TUnit_TestProject_MatrixTests_AutoGenerateBools2__string_b }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.AutoGenerateBools2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - await instance.AutoGenerateBools2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -571,7 +601,7 @@ internal sealed class TUnit_TestProject_MatrixTests_ImplicitConversion__OneOf_Te TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "ImplicitConversion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -611,7 +641,7 @@ internal sealed class TUnit_TestProject_MatrixTests_ImplicitConversion__OneOf_Te ReflectionInfo = 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] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -619,7 +649,7 @@ internal sealed class TUnit_TestProject_MatrixTests_ImplicitConversion__OneOf_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -633,15 +663,21 @@ internal sealed class TUnit_TestProject_MatrixTests_ImplicitConversion__OneOf_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.ImplicitConversion(TUnit.Core.Helpers.CastHelper.Cast>(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - await instance.ImplicitConversion(TUnit.Core.Helpers.CastHelper.Cast>(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -677,7 +713,7 @@ internal sealed class TUnit_TestProject_MatrixTests_ExcludingAutoGeneratedMatrix TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "ExcludingAutoGeneratedMatrixValues", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -717,7 +753,7 @@ internal sealed class TUnit_TestProject_MatrixTests_ExcludingAutoGeneratedMatrix ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("ExcludingAutoGeneratedMatrixValues", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.MatrixTests.CountToTenEnum), typeof(bool) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -725,7 +761,7 @@ internal sealed class TUnit_TestProject_MatrixTests_ExcludingAutoGeneratedMatrix TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -739,15 +775,21 @@ internal sealed class TUnit_TestProject_MatrixTests_ExcludingAutoGeneratedMatrix }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 2: - await instance.ExcludingAutoGeneratedMatrixValues(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.ExcludingAutoGeneratedMatrixValues(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -783,7 +825,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method1__int_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "Method1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -816,7 +858,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method1__int_TestSource : gl ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("Method1", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -824,7 +866,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method1__int_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -838,15 +880,21 @@ internal sealed class TUnit_TestProject_MatrixTests_Method1__int_TestSource : gl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Method1(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Method1(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -882,7 +930,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method2__int_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "Method2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -915,7 +963,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method2__int_TestSource : gl ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("Method2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -923,7 +971,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method2__int_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -937,15 +985,21 @@ internal sealed class TUnit_TestProject_MatrixTests_Method2__int_TestSource : gl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -981,7 +1035,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method3__int_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "Method3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -1014,7 +1068,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method3__int_TestSource : gl ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("Method3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1022,7 +1076,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method3__int_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1036,15 +1090,21 @@ internal sealed class TUnit_TestProject_MatrixTests_Method3__int_TestSource : gl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Method3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Method3(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -1080,7 +1140,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method4__int_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "Method4", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -1113,7 +1173,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method4__int_TestSource : gl ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("Method4", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1121,7 +1181,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Method4__int_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1135,15 +1195,21 @@ internal sealed class TUnit_TestProject_MatrixTests_Method4__int_TestSource : gl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Method4(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Method4(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -1179,7 +1245,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Exclusion__int_int_TestSourc TestClassType = typeof(global::TUnit.TestProject.MatrixTests), TestMethodName = "Exclusion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.MatrixExclusionAttribute(1, 1), @@ -1222,7 +1288,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Exclusion__int_int_TestSourc ReflectionInfo = typeof(global::TUnit.TestProject.MatrixTests).GetMethod("Exclusion", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(int) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MatrixTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1230,7 +1296,7 @@ internal sealed class TUnit_TestProject_MatrixTests_Exclusion__int_int_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MatrixTests)), Name = "MatrixTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1244,15 +1310,21 @@ internal sealed class TUnit_TestProject_MatrixTests_Exclusion__int_int_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MatrixTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + return new global::System.Threading.Tasks.ValueTask(instance.Exclusion(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]))); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - await instance.Exclusion(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenTests.Test.verified.txt index c6a4096605..4ac45b08bb 100644 --- a/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "DataSource_Method", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("DataSource_Method", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -65,7 +65,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -79,17 +79,23 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSource_Method(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -124,7 +130,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "DataSource_Method2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -168,7 +174,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("DataSource_Method2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -176,7 +182,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -190,17 +196,23 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.DataSource_Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.DataSource_Method2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -235,7 +247,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "DataSource_Method_WithAction", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -279,7 +291,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("DataSource_Method_WithAction", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Action) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -287,7 +299,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -301,17 +313,23 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSource_Method_WithAction(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSource_Method_WithAction(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -346,7 +364,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "DataSource_Method3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -405,7 +423,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("DataSource_Method3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -413,7 +431,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -427,17 +445,23 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.DataSource_Method3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.DataSource_Method3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -472,7 +496,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "DataSource_Method4", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -558,7 +582,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("DataSource_Method4", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -566,7 +590,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -580,17 +604,23 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_M }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.DataSource_Method4(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.DataSource_Method4(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -625,7 +655,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_W TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "DataSource_WithBaseReturn", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -669,7 +699,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_W ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("DataSource_WithBaseReturn", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests.BaseValue) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -677,7 +707,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_W TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -691,17 +721,23 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_DataSource_W }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.DataSource_WithBaseReturn(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.DataSource_WithBaseReturn(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -736,7 +772,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_EnumerableFu TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests), TestMethodName = "EnumerableFuncArrayTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -790,7 +826,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_EnumerableFu ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests).GetMethod("EnumerableFuncArrayTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string[]) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -798,7 +834,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_EnumerableFu TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenTests)), Name = "MethodDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -812,15 +848,21 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenTests_EnumerableFu }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.EnumerableFuncArrayTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.EnumerableFuncArrayTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenWithCancellationTokenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenWithCancellationTokenTests.Test.verified.txt index 75524c29cb..91193caa00 100644 --- a/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenWithCancellationTokenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/MethodDataSourceDrivenWithCancellationTokenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenWithCancellationTo TestClassType = typeof(global::TUnit.TestProject.MethodDataSourceDrivenWithCancellationTokenTests), TestMethodName = "MyTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -165,7 +165,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenWithCancellationTo ReflectionInfo = typeof(global::TUnit.TestProject.MethodDataSourceDrivenWithCancellationTokenTests).GetMethod("MyTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenWithCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MethodDataSourceDrivenWithCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -173,7 +173,7 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenWithCancellationTo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MethodDataSourceDrivenWithCancellationTokenTests)), Name = "MethodDataSourceDrivenWithCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -187,18 +187,24 @@ internal sealed class TUnit_TestProject_MethodDataSourceDrivenWithCancellationTo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.MethodDataSourceDrivenWithCancellationTokenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var context = global::TUnit.Core.TestContext.Current; - switch (args.Length) + try { - case 1: - instance.MyTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + var context = global::TUnit.Core.TestContext.Current; + switch (args.Length) + { + case 1: + instance.MyTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt index 542f2f0347..e96980da8b 100644 --- a/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/MultipleClassDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test1 TestClassType = typeof(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -40,7 +40,7 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test1 ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MultipleClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MultipleClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test1 TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests)), Name = "MultipleClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject1)) @@ -102,10 +102,17 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test1 { return new global::TUnit.TestProject.MultipleClassDataSourceDrivenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -140,7 +147,7 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test2 TestClassType = typeof(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -167,7 +174,7 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test2 ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MultipleClassDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.MultipleClassDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -175,7 +182,7 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test2 TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests)), Name = "MultipleClassDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.MultipleClassDataSourceDrivenTests.Inject1)) @@ -229,10 +236,17 @@ internal sealed class TUnit_TestProject_MultipleClassDataSourceDrivenTests_Test2 { return new global::TUnit.TestProject.MultipleClassDataSourceDrivenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test2(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test2(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt index 0d56eb08f4..a89cf44b80 100644 --- a/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NameOfArgumentTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_NameOfArgumentTests_TestName__string_Tes TestClassType = typeof(global::TUnit.TestProject.NameOfArgumentTests), TestMethodName = "TestName", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_NameOfArgumentTests_TestName__string_Tes ReflectionInfo = typeof(global::TUnit.TestProject.NameOfArgumentTests).GetMethod("TestName", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NameOfArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NameOfArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_NameOfArgumentTests_TestName__string_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NameOfArgumentTests)), Name = "NameOfArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,15 +68,21 @@ internal sealed class TUnit_TestProject_NameOfArgumentTests_TestName__string_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NameOfArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.TestName(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.TestName(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt index 51c6bd9019..7683db8709 100644 --- a/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NullableByteArgumentTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test__byte__Te TestClassType = typeof(global::TUnit.TestProject.NullableByteArgumentTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -47,7 +47,7 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test__byte__Te ReflectionInfo = typeof(global::TUnit.TestProject.NullableByteArgumentTests).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(byte?) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NullableByteArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NullableByteArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -55,7 +55,7 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test__byte__Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NullableByteArgumentTests)), Name = "NullableByteArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -69,17 +69,23 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test__byte__Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NullableByteArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -114,7 +120,7 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test2__byte_by TestClassType = typeof(global::TUnit.TestProject.NullableByteArgumentTests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -155,7 +161,7 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test2__byte_by ReflectionInfo = typeof(global::TUnit.TestProject.NullableByteArgumentTests).GetMethod("Test2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(byte), typeof(byte?) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NullableByteArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NullableByteArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -163,7 +169,7 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test2__byte_by TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NullableByteArgumentTests)), Name = "NullableByteArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -177,17 +183,23 @@ internal sealed class TUnit_TestProject_NullableByteArgumentTests_Test2__byte_by }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NullableByteArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 2: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 2: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt index ff27d61028..f953755712 100644 --- a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Int", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Int", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,17 +68,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Int(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Int(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -113,7 +119,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Double", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -146,7 +152,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Double", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(double) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -154,7 +160,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -168,17 +174,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Double(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Double(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -213,7 +225,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Float", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -246,7 +258,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Float", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(float) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -254,7 +266,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -268,17 +280,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Float(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Float(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -313,7 +331,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Long", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -346,7 +364,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Long", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(long) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -354,7 +372,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -368,17 +386,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Long(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Long(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -413,7 +437,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "ULong", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -446,7 +470,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("ULong", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(ulong) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -454,7 +478,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -468,17 +492,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.ULong(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.ULong(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -513,7 +543,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "UInt", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -546,7 +576,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("UInt", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(uint) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -554,7 +584,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -568,17 +598,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.UInt(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.UInt(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt index ff27d61028..f953755712 100644 --- a/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/NumberArgumentTests.TestDE.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Int", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Int", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,17 +68,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Int__int_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Int(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Int(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -113,7 +119,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Double", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -146,7 +152,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Double", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(double) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -154,7 +160,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -168,17 +174,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Double__double_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Double(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Double(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -213,7 +225,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Float", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -246,7 +258,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Float", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(float) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -254,7 +266,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -268,17 +280,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Float__float_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Float(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Float(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -313,7 +331,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "Long", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -346,7 +364,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("Long", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(long) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -354,7 +372,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -368,17 +386,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_Long__long_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Long(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Long(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -413,7 +437,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "ULong", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -446,7 +470,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("ULong", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(ulong) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -454,7 +478,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -468,17 +492,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_ULong__ulong_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.ULong(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.ULong(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -513,7 +543,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc TestClassType = typeof(global::TUnit.TestProject.NumberArgumentTests), TestMethodName = "UInt", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -546,7 +576,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc ReflectionInfo = typeof(global::TUnit.TestProject.NumberArgumentTests).GetMethod("UInt", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(uint) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.NumberArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -554,7 +584,7 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.NumberArgumentTests)), Name = "NumberArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -568,17 +598,23 @@ internal sealed class TUnit_TestProject_NumberArgumentTests_UInt__uint_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.NumberArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.UInt(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.UInt(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/PriorityFilteringTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/PriorityFilteringTests.Test.verified.txt index 0b262595c3..90776b2e04 100644 --- a/TUnit.Core.SourceGenerator.Tests/PriorityFilteringTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/PriorityFilteringTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_1_TestSource TestClassType = typeof(global::TUnit.TestProject.PriorityFilteringTests), TestMethodName = "High_1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.PriorityAttribute(global::TUnit.TestProject.Enums.PriorityLevel.High) @@ -34,7 +34,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_1_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -42,7 +42,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PriorityFilteringTests)), Name = "PriorityFilteringTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -56,9 +56,16 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.PriorityFilteringTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.High_1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.High_1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -93,7 +100,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_2_TestSource TestClassType = typeof(global::TUnit.TestProject.PriorityFilteringTests), TestMethodName = "High_2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.PriorityAttribute(global::TUnit.TestProject.Enums.PriorityLevel.High) @@ -114,7 +121,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_2_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -122,7 +129,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_2_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PriorityFilteringTests)), Name = "PriorityFilteringTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -136,9 +143,16 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_2_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.PriorityFilteringTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.High_2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.High_2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -173,7 +187,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_3_TestSource TestClassType = typeof(global::TUnit.TestProject.PriorityFilteringTests), TestMethodName = "High_3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.PriorityAttribute(global::TUnit.TestProject.Enums.PriorityLevel.High) @@ -194,7 +208,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_3_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -202,7 +216,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_3_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PriorityFilteringTests)), Name = "PriorityFilteringTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -216,9 +230,16 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_High_3_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.PriorityFilteringTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.High_3(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.High_3()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -253,7 +274,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_1_TestSour TestClassType = typeof(global::TUnit.TestProject.PriorityFilteringTests), TestMethodName = "Medium_1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.PriorityAttribute(global::TUnit.TestProject.Enums.PriorityLevel.Medium) @@ -274,7 +295,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_1_TestSour ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -282,7 +303,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_1_TestSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PriorityFilteringTests)), Name = "PriorityFilteringTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -296,9 +317,16 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_1_TestSour }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.PriorityFilteringTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Medium_1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Medium_1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -333,7 +361,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_2_TestSour TestClassType = typeof(global::TUnit.TestProject.PriorityFilteringTests), TestMethodName = "Medium_2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.PriorityAttribute(global::TUnit.TestProject.Enums.PriorityLevel.Medium) @@ -354,7 +382,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_2_TestSour ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -362,7 +390,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_2_TestSour TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PriorityFilteringTests)), Name = "PriorityFilteringTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -376,9 +404,16 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Medium_2_TestSour }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.PriorityFilteringTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Medium_2(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Medium_2()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -413,7 +448,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Low_1_TestSource TestClassType = typeof(global::TUnit.TestProject.PriorityFilteringTests), TestMethodName = "Low_1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.PriorityAttribute(global::TUnit.TestProject.Enums.PriorityLevel.Low) @@ -434,7 +469,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Low_1_TestSource ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PriorityFilteringTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -442,7 +477,7 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Low_1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PriorityFilteringTests)), Name = "PriorityFilteringTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -456,9 +491,16 @@ internal sealed class TUnit_TestProject_PriorityFilteringTests_Low_1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.PriorityFilteringTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Low_1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Low_1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/PropertySetterTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/PropertySetterTests.Test.verified.txt index de23b46bef..6ca53de893 100644 --- a/TUnit.Core.SourceGenerator.Tests/PropertySetterTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/PropertySetterTests.Test.verified.txt @@ -27,7 +27,7 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.PropertySetterTests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -199,7 +199,7 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PropertySetterTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.PropertySetterTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -207,7 +207,7 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.PropertySetterTests)), Name = "PropertySetterTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = new global::TUnit.Core.PropertyMetadata[] { @@ -320,9 +320,16 @@ internal sealed class TUnit_TestProject_PropertySetterTests_Test_TestSource : gl Property6 = default!, Property7 = default!, }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/RepeatTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/RepeatTests.Test.verified.txt index c039f11e1a..c359cf4a4f 100644 --- a/TUnit.Core.SourceGenerator.Tests/RepeatTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/RepeatTests.Test.verified.txt @@ -13,13 +13,14 @@ internal sealed class TUnit_TestProject_RepeatTests_One_TestSource : global::TUn TestClassType = typeof(global::TUnit.TestProject.RepeatTests), TestMethodName = "One", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.RepeatAttribute(1), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), new global::TUnit.Core.RepeatAttribute(3) ], + RepeatCount = 1, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -36,7 +37,7 @@ internal sealed class TUnit_TestProject_RepeatTests_One_TestSource : global::TUn ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.RepeatTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.RepeatTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -44,7 +45,7 @@ internal sealed class TUnit_TestProject_RepeatTests_One_TestSource : global::TUn TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.RepeatTests)), Name = "RepeatTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -58,10 +59,17 @@ internal sealed class TUnit_TestProject_RepeatTests_One_TestSource : global::TUn }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.RepeatTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.One(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.One(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -96,13 +104,14 @@ internal sealed class TUnit_TestProject_RepeatTests_Two_TestSource : global::TUn TestClassType = typeof(global::TUnit.TestProject.RepeatTests), TestMethodName = "Two", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.RepeatAttribute(2), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), new global::TUnit.Core.RepeatAttribute(3) ], + RepeatCount = 2, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -119,7 +128,7 @@ internal sealed class TUnit_TestProject_RepeatTests_Two_TestSource : global::TUn ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.RepeatTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.RepeatTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -127,7 +136,7 @@ internal sealed class TUnit_TestProject_RepeatTests_Two_TestSource : global::TUn TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.RepeatTests)), Name = "RepeatTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -141,10 +150,17 @@ internal sealed class TUnit_TestProject_RepeatTests_Two_TestSource : global::TUn }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.RepeatTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Two(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Two(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -179,12 +195,13 @@ internal sealed class TUnit_TestProject_RepeatTests_Three_TestSource : global::T TestClassType = typeof(global::TUnit.TestProject.RepeatTests), TestMethodName = "Three", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), new global::TUnit.Core.RepeatAttribute(3) ], + RepeatCount = 3, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -201,7 +218,7 @@ internal sealed class TUnit_TestProject_RepeatTests_Three_TestSource : global::T ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.RepeatTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.RepeatTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -209,7 +226,7 @@ internal sealed class TUnit_TestProject_RepeatTests_Three_TestSource : global::T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.RepeatTests)), Name = "RepeatTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -223,10 +240,17 @@ internal sealed class TUnit_TestProject_RepeatTests_Three_TestSource : global::T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.RepeatTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Three(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Three(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet10_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet10_0.verified.txt index 7c83ebe681..6f2ad0396b 100644 --- a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet10_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "With_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -22,6 +22,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -38,7 +39,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -46,7 +47,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -60,9 +61,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.With_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.With_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -97,7 +105,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "Without_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -105,6 +113,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -121,7 +130,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -129,7 +138,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -143,9 +152,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Without_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Without_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -180,7 +196,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithSimpleAwait", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -189,6 +205,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -205,7 +222,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -213,7 +230,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -227,9 +244,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithSimpleAwait(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithSimpleAwait()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -264,7 +288,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskYield", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -273,6 +297,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -289,7 +314,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -297,7 +322,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -311,9 +336,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskYield(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskYield()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -348,7 +380,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithConfigureAwaitTrue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -357,6 +389,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -373,7 +406,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -381,7 +414,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -395,9 +428,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithConfigureAwaitTrue(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithConfigureAwaitTrue()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -432,7 +472,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithNestedAsyncCalls", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -441,6 +481,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -457,7 +498,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -465,7 +506,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -479,9 +520,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithNestedAsyncCalls(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithNestedAsyncCalls()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -516,7 +564,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskFromResult", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -525,6 +573,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -541,7 +590,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -549,7 +598,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -563,9 +612,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskFromResult(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskFromResult()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -600,7 +656,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithCompletedTask", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -609,6 +665,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -625,7 +682,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -633,7 +690,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -647,9 +704,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithCompletedTask(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithCompletedTask()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -684,7 +748,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskRun", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -693,6 +757,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -709,7 +774,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -717,7 +782,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -731,9 +796,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskRun(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskRun()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -768,7 +840,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithMultipleAwaits", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -777,6 +849,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -793,7 +866,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -801,7 +874,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -815,9 +888,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithMultipleAwaits(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithMultipleAwaits()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -852,7 +932,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithAsyncEnumerable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -861,6 +941,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -877,7 +958,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -885,7 +966,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -899,9 +980,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithAsyncEnumerable(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithAsyncEnumerable()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -936,7 +1024,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskWhenAll", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -945,6 +1033,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -961,7 +1050,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -969,7 +1058,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -983,9 +1072,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskWhenAll(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskWhenAll()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1020,7 +1116,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithExceptionHandling", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1029,6 +1125,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1045,7 +1142,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1053,7 +1150,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1067,9 +1164,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithExceptionHandling(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithExceptionHandling()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1104,7 +1208,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithThrowsNothingAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1113,6 +1217,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1129,7 +1234,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1137,7 +1242,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1151,9 +1256,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithThrowsNothingAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithThrowsNothingAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1188,7 +1300,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithFuncAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1197,6 +1309,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1213,7 +1326,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1221,7 +1334,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1235,9 +1348,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithFuncAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithFuncAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet8_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet8_0.verified.txt index 7c83ebe681..6f2ad0396b 100644 --- a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet8_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "With_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -22,6 +22,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -38,7 +39,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -46,7 +47,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -60,9 +61,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.With_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.With_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -97,7 +105,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "Without_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -105,6 +113,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -121,7 +130,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -129,7 +138,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -143,9 +152,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Without_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Without_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -180,7 +196,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithSimpleAwait", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -189,6 +205,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -205,7 +222,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -213,7 +230,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -227,9 +244,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithSimpleAwait(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithSimpleAwait()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -264,7 +288,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskYield", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -273,6 +297,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -289,7 +314,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -297,7 +322,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -311,9 +336,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskYield(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskYield()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -348,7 +380,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithConfigureAwaitTrue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -357,6 +389,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -373,7 +406,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -381,7 +414,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -395,9 +428,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithConfigureAwaitTrue(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithConfigureAwaitTrue()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -432,7 +472,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithNestedAsyncCalls", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -441,6 +481,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -457,7 +498,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -465,7 +506,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -479,9 +520,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithNestedAsyncCalls(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithNestedAsyncCalls()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -516,7 +564,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskFromResult", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -525,6 +573,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -541,7 +590,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -549,7 +598,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -563,9 +612,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskFromResult(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskFromResult()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -600,7 +656,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithCompletedTask", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -609,6 +665,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -625,7 +682,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -633,7 +690,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -647,9 +704,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithCompletedTask(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithCompletedTask()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -684,7 +748,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskRun", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -693,6 +757,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -709,7 +774,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -717,7 +782,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -731,9 +796,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskRun(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskRun()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -768,7 +840,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithMultipleAwaits", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -777,6 +849,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -793,7 +866,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -801,7 +874,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -815,9 +888,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithMultipleAwaits(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithMultipleAwaits()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -852,7 +932,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithAsyncEnumerable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -861,6 +941,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -877,7 +958,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -885,7 +966,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -899,9 +980,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithAsyncEnumerable(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithAsyncEnumerable()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -936,7 +1024,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskWhenAll", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -945,6 +1033,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -961,7 +1050,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -969,7 +1058,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -983,9 +1072,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskWhenAll(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskWhenAll()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1020,7 +1116,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithExceptionHandling", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1029,6 +1125,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1045,7 +1142,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1053,7 +1150,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1067,9 +1164,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithExceptionHandling(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithExceptionHandling()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1104,7 +1208,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithThrowsNothingAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1113,6 +1217,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1129,7 +1234,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1137,7 +1242,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1151,9 +1256,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithThrowsNothingAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithThrowsNothingAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1188,7 +1300,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithFuncAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1197,6 +1309,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1213,7 +1326,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1221,7 +1334,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1235,9 +1348,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithFuncAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithFuncAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet9_0.verified.txt b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet9_0.verified.txt index 7c83ebe681..6f2ad0396b 100644 --- a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.DotNet9_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "With_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -22,6 +22,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -38,7 +39,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -46,7 +47,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -60,9 +61,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.With_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.With_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -97,7 +105,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "Without_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -105,6 +113,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -121,7 +130,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -129,7 +138,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -143,9 +152,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Without_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Without_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -180,7 +196,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithSimpleAwait", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -189,6 +205,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -205,7 +222,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -213,7 +230,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -227,9 +244,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithSimpleAwait(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithSimpleAwait()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -264,7 +288,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskYield", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -273,6 +297,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -289,7 +314,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -297,7 +322,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -311,9 +336,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskYield(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskYield()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -348,7 +380,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithConfigureAwaitTrue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -357,6 +389,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -373,7 +406,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -381,7 +414,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -395,9 +428,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithConfigureAwaitTrue(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithConfigureAwaitTrue()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -432,7 +472,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithNestedAsyncCalls", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -441,6 +481,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -457,7 +498,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -465,7 +506,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -479,9 +520,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithNestedAsyncCalls(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithNestedAsyncCalls()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -516,7 +564,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskFromResult", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -525,6 +573,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -541,7 +590,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -549,7 +598,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -563,9 +612,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskFromResult(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskFromResult()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -600,7 +656,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithCompletedTask", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -609,6 +665,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -625,7 +682,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -633,7 +690,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -647,9 +704,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithCompletedTask(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithCompletedTask()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -684,7 +748,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskRun", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -693,6 +757,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -709,7 +774,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -717,7 +782,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -731,9 +796,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskRun(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskRun()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -768,7 +840,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithMultipleAwaits", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -777,6 +849,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -793,7 +866,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -801,7 +874,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -815,9 +888,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithMultipleAwaits(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithMultipleAwaits()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -852,7 +932,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithAsyncEnumerable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -861,6 +941,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -877,7 +958,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -885,7 +966,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -899,9 +980,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithAsyncEnumerable(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithAsyncEnumerable()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -936,7 +1024,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskWhenAll", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -945,6 +1033,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -961,7 +1050,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -969,7 +1058,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -983,9 +1072,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskWhenAll(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskWhenAll()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1020,7 +1116,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithExceptionHandling", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1029,6 +1125,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1045,7 +1142,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1053,7 +1150,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1067,9 +1164,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithExceptionHandling(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithExceptionHandling()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1104,7 +1208,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithThrowsNothingAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1113,6 +1217,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1129,7 +1234,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1137,7 +1242,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1151,9 +1256,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithThrowsNothingAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithThrowsNothingAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1188,7 +1300,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithFuncAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1197,6 +1309,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1213,7 +1326,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1221,7 +1334,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1235,9 +1348,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithFuncAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithFuncAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 1c8f0a235c..b31c36229f 100644 --- a/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.Net4_7.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "With_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -22,6 +22,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -38,7 +39,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -46,7 +47,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -60,9 +61,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_With_STA_TestSource : glo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.With_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.With_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -97,7 +105,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "Without_STA", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -105,6 +113,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -121,7 +130,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -129,7 +138,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -143,9 +152,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_Without_STA_TestSource : }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Without_STA(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Without_STA()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -180,7 +196,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithSimpleAwait", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -189,6 +205,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -205,7 +222,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -213,7 +230,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -227,9 +244,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithSimpleAwait_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithSimpleAwait(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithSimpleAwait()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -264,7 +288,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskYield", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -273,6 +297,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -289,7 +314,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -297,7 +322,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -311,9 +336,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskYield_TestSou }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskYield(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskYield()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -348,7 +380,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithConfigureAwaitTrue", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -357,6 +389,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -373,7 +406,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -381,7 +414,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -395,9 +428,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithConfigureAwaitTru }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithConfigureAwaitTrue(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithConfigureAwaitTrue()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -432,7 +472,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithNestedAsyncCalls", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -441,6 +481,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -457,7 +498,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -465,7 +506,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -479,9 +520,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithNestedAsyncCalls_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithNestedAsyncCalls(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithNestedAsyncCalls()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -516,7 +564,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskFromResult", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -525,6 +573,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -541,7 +590,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -549,7 +598,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -563,9 +612,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskFromResult_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskFromResult(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskFromResult()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -600,7 +656,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithCompletedTask", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -609,6 +665,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -625,7 +682,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -633,7 +690,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -647,9 +704,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithCompletedTask_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithCompletedTask(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithCompletedTask()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -684,7 +748,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskRun", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -693,6 +757,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -709,7 +774,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -717,7 +782,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -731,9 +796,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskRun_TestSourc }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskRun(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskRun()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -768,7 +840,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithMultipleAwaits", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -777,6 +849,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -793,7 +866,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -801,7 +874,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -815,9 +888,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithMultipleAwaits_Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithMultipleAwaits(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithMultipleAwaits()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -852,7 +932,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithAsyncEnumerable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -861,6 +941,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -877,7 +958,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -885,7 +966,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -899,9 +980,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithAsyncEnumerable_T }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithAsyncEnumerable(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithAsyncEnumerable()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -936,7 +1024,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithTaskWhenAll", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -945,6 +1033,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -961,7 +1050,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -969,7 +1058,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -983,9 +1072,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithTaskWhenAll_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithTaskWhenAll(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithTaskWhenAll()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1020,7 +1116,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithExceptionHandling", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1029,6 +1125,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1045,7 +1142,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1053,7 +1150,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1067,9 +1164,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithExceptionHandling }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithExceptionHandling(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithExceptionHandling()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1104,7 +1208,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithThrowsNothingAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1113,6 +1217,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1129,7 +1234,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1137,7 +1242,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1151,9 +1256,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithThrowsNothingAsse }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithThrowsNothingAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithThrowsNothingAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -1188,7 +1300,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TestClassType = typeof(global::TUnit.TestProject.STAThreadTests), TestMethodName = "STA_WithFuncAssertion", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.Executors.STAThreadExecutorAttribute(), @@ -1197,6 +1309,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes new global::TUnit.Core.RepeatAttribute(100), new global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessageAttribute("Interoperability", "CA1416:Validate platform compatibility") ], + RepeatCount = 100, DataSources = global::System.Array.Empty(), ClassDataSources = global::System.Array.Empty(), PropertyDataSources = global::System.Array.Empty(), @@ -1213,7 +1326,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.STAThreadTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -1221,7 +1334,7 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.STAThreadTests)), Name = "STAThreadTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -1235,9 +1348,16 @@ internal sealed class TUnit_TestProject_STAThreadTests_STA_WithFuncAssertion_Tes }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.STAThreadTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.STA_WithFuncAssertion(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.STA_WithFuncAssertion()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt index 8cac05bc97..ddf79f8751 100644 --- a/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/StringArgumentTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Normal__string_TestS TestClassType = typeof(global::TUnit.TestProject.StringArgumentTests), TestMethodName = "Normal", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Normal__string_TestS ReflectionInfo = typeof(global::TUnit.TestProject.StringArgumentTests).GetMethod("Normal", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.StringArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.StringArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -65,7 +65,7 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Normal__string_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.StringArgumentTests)), Name = "StringArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -79,17 +79,23 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Normal__string_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.StringArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Normal(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Normal(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -124,7 +130,7 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Nullable__string__Te TestClassType = typeof(global::TUnit.TestProject.StringArgumentTests), TestMethodName = "Nullable", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -164,7 +170,7 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Nullable__string__Te ReflectionInfo = typeof(global::TUnit.TestProject.StringArgumentTests).GetMethod("Nullable", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.StringArgumentTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.StringArgumentTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -172,7 +178,7 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Nullable__string__Te TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.StringArgumentTests)), Name = "StringArgumentTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -186,17 +192,23 @@ internal sealed class TUnit_TestProject_StringArgumentTests_Nullable__string__Te }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.StringArgumentTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Nullable(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Nullable(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt index 9dab7ad740..62c0396286 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_InvalidString_ TestClassType = typeof(global::TUnit.TestProject.Bugs._1304.Tests), TestMethodName = "TryParse_InvalidString_ReturnsFailure", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -57,7 +57,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_InvalidString_ ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1304.Tests).GetMethod("TryParse_InvalidString_ReturnsFailure", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1304.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1304.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -65,7 +65,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_InvalidString_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1304.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1304", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -79,16 +79,22 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_InvalidString_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1304.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var context = global::TUnit.Core.TestContext.Current; - switch (args.Length) + try { - case 1: - await instance.TryParse_InvalidString_ReturnsFailure(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + var context = global::TUnit.Core.TestContext.Current; + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.TryParse_InvalidString_ReturnsFailure(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None)); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -124,7 +130,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_Parse_InvalidString_Thr TestClassType = typeof(global::TUnit.TestProject.Bugs._1304.Tests), TestMethodName = "Parse_InvalidString_ThrowsException", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -161,7 +167,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_Parse_InvalidString_Thr ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1304.Tests).GetMethod("Parse_InvalidString_ThrowsException", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1304.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1304.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -169,7 +175,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_Parse_InvalidString_Thr TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1304.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1304", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -183,15 +189,21 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_Parse_InvalidString_Thr }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1304.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Parse_InvalidString_ThrowsException(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Parse_InvalidString_ThrowsException(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -227,7 +239,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_ValidString_Re TestClassType = typeof(global::TUnit.TestProject.Bugs._1304.Tests), TestMethodName = "TryParse_ValidString_ReturnsAccountId", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -261,7 +273,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_ValidString_Re ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1304.Tests).GetMethod("TryParse_ValidString_ReturnsAccountId", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1304.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1304.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -269,7 +281,7 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_ValidString_Re TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1304.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1304", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -283,15 +295,21 @@ internal sealed class TUnit_TestProject_Bugs__1304_Tests_TryParse_ValidString_Re }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1304.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.TryParse_ValidString_ReturnsAccountId(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.TryParse_ValidString_ReturnsAccountId(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1538.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1538.Test.verified.txt index f1db0eb3a4..f58a3c0aac 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1538.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1538.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_Eight_Args__bool_string TestClassType = typeof(global::TUnit.TestProject.Bugs._1538.Tests), TestMethodName = "Eight_Args", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -116,7 +116,7 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_Eight_Args__bool_string ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1538.Tests).GetMethod("Eight_Args", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) }, null)!.GetParameters()[7] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1538.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1538.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -124,7 +124,7 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_Eight_Args__bool_string TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1538.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1538", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -138,17 +138,23 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_Eight_Args__bool_string }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1538.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 8: - instance.Eight_Args(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]), TUnit.Core.Helpers.CastHelper.Cast(args[7])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 8 arguments, but got {args.Length}"); + switch (args.Length) + { + case 8: + instance.Eight_Args(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]), TUnit.Core.Helpers.CastHelper.Cast(args[7])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 8 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -183,7 +189,7 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_SixteenArgs__bool_strin TestClassType = typeof(global::TUnit.TestProject.Bugs._1538.Tests), TestMethodName = "SixteenArgs", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -342,7 +348,7 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_SixteenArgs__bool_strin ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1538.Tests).GetMethod("SixteenArgs", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string), typeof(string) }, null)!.GetParameters()[15] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1538.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1538.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -350,7 +356,7 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_SixteenArgs__bool_strin TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1538.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1538", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -364,17 +370,23 @@ internal sealed class TUnit_TestProject_Bugs__1538_Tests_SixteenArgs__bool_strin }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1538.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 16: + instance.SixteenArgs(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]), TUnit.Core.Helpers.CastHelper.Cast(args[7]), TUnit.Core.Helpers.CastHelper.Cast(args[8]), TUnit.Core.Helpers.CastHelper.Cast(args[9]), TUnit.Core.Helpers.CastHelper.Cast(args[10]), TUnit.Core.Helpers.CastHelper.Cast(args[11]), TUnit.Core.Helpers.CastHelper.Cast(args[12]), TUnit.Core.Helpers.CastHelper.Cast(args[13]), TUnit.Core.Helpers.CastHelper.Cast(args[14]), TUnit.Core.Helpers.CastHelper.Cast(args[15])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 16 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 16: - instance.SixteenArgs(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]), TUnit.Core.Helpers.CastHelper.Cast(args[7]), TUnit.Core.Helpers.CastHelper.Cast(args[8]), TUnit.Core.Helpers.CastHelper.Cast(args[9]), TUnit.Core.Helpers.CastHelper.Cast(args[10]), TUnit.Core.Helpers.CastHelper.Cast(args[11]), TUnit.Core.Helpers.CastHelper.Cast(args[12]), TUnit.Core.Helpers.CastHelper.Cast(args[13]), TUnit.Core.Helpers.CastHelper.Cast(args[14]), TUnit.Core.Helpers.CastHelper.Cast(args[15])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 16 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1539.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1539.Test.verified.txt index 6215e8e5ca..a80ac7803f 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1539.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1539.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1539_Tests_Test_TestSource : globa TestClassType = typeof(global::TUnit.TestProject.Bugs._1539.Tests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Bugs._1539.Tests.AttributeWithPositionalArgs(), @@ -38,7 +38,7 @@ internal sealed class TUnit_TestProject_Bugs__1539_Tests_Test_TestSource : globa ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1539.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1539.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_Bugs__1539_Tests_Test_TestSource : globa TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1539.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1539", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -60,10 +60,17 @@ internal sealed class TUnit_TestProject_Bugs__1539_Tests_Test_TestSource : globa }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1539.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt index 30f345f65e..715c01f082 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1589.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.Bugs._1589.MyTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -40,7 +40,7 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl ReturnType = typeof(global::System.Threading.Tasks.Task), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::System.Threading.Tasks.Task)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1589.MyTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1589.MyTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1589.MyTests)), Name = "MyTests", Namespace = "TUnit.TestProject.Bugs._1589", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._1589.MyFixture)) @@ -74,9 +74,16 @@ internal sealed class TUnit_TestProject_Bugs__1589_MyTests_Test1_TestSource : gl { return new global::TUnit.TestProject.Bugs._1589.MyTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.Test1(); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.Test1()); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt index 6b791bb019..9d5d9f0ecd 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1594.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl TestClassType = typeof(global::TUnit.TestProject.Bugs._1594.MyTests), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -40,7 +40,7 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1594.MyTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1594.MyTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -48,7 +48,7 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1594.MyTests)), Name = "MyTests", Namespace = "TUnit.TestProject.Bugs._1594", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._1594.MyFixture)) @@ -74,10 +74,17 @@ internal sealed class TUnit_TestProject_Bugs__1594_MyTests_Test1_TestSource : gl { return new global::TUnit.TestProject.Bugs._1594.MyTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt index 4d5c81e221..3a4cae1c70 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1603.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Casted_Integer_To_Short TestClassType = typeof(global::TUnit.TestProject.Bugs._1603.Tests), TestMethodName = "Casted_Integer_To_Short_Converts", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Casted_Integer_To_Short ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1603.Tests).GetMethod("Casted_Integer_To_Short_Converts", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(short) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1603.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1603.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Casted_Integer_To_Short TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1603.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1603", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,15 +68,21 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Casted_Integer_To_Short }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1603.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Casted_Integer_To_Short_Converts(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Casted_Integer_To_Short_Converts(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -112,7 +118,7 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Integer_To_Short_Conver TestClassType = typeof(global::TUnit.TestProject.Bugs._1603.Tests), TestMethodName = "Integer_To_Short_Converts", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -145,7 +151,7 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Integer_To_Short_Conver ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1603.Tests).GetMethod("Integer_To_Short_Converts", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(short) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1603.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1603.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -153,7 +159,7 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Integer_To_Short_Conver TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1603.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1603", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -167,15 +173,21 @@ internal sealed class TUnit_TestProject_Bugs__1603_Tests_Integer_To_Short_Conver }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1603.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Integer_To_Short_Converts(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Integer_To_Short_Converts(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1692.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1692.Test.verified.txt index 1869a5dcd3..dc434877b6 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1692.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1692.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1692_Tests_NullTest__string__TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1692.Tests), TestMethodName = "NullTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -47,7 +47,7 @@ internal sealed class TUnit_TestProject_Bugs__1692_Tests_NullTest__string__TestS ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1692.Tests).GetMethod("NullTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1692.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1692.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -55,7 +55,7 @@ internal sealed class TUnit_TestProject_Bugs__1692_Tests_NullTest__string__TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1692.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1692", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -69,15 +69,21 @@ internal sealed class TUnit_TestProject_Bugs__1692_Tests_NullTest__string__TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1692.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.NullTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.NullTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt index de387cc342..13a93df557 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1821.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MethodDataSource__strin TestClassType = typeof(global::TUnit.TestProject.Bugs._1821.Tests), TestMethodName = "MethodDataSource", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -50,7 +50,7 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MethodDataSource__strin ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1821.Tests).GetMethod("MethodDataSource", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1821.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1821.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -58,7 +58,7 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MethodDataSource__strin TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1821.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1821", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._1821.MyData)) @@ -84,15 +84,21 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MethodDataSource__strin { return new global::TUnit.TestProject.Bugs._1821.Tests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.MethodDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.MethodDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -128,7 +134,7 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MatrixDataSource__strin TestClassType = typeof(global::TUnit.TestProject.Bugs._1821.Tests), TestMethodName = "MatrixDataSource", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -165,7 +171,7 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MatrixDataSource__strin ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._1821.Tests).GetMethod("MatrixDataSource", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(string) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1821.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1821.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -173,7 +179,7 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MatrixDataSource__strin TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1821.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._1821", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(global::TUnit.TestProject.Bugs._1821.MyData)) @@ -199,15 +205,21 @@ internal sealed class TUnit_TestProject_Bugs__1821_Tests_MatrixDataSource__strin { return new global::TUnit.TestProject.Bugs._1821.Tests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.MatrixDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.MatrixDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; 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 03e16a9367..65d6193dd3 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet10_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet10_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -129,7 +136,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -137,7 +144,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -151,17 +158,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -196,7 +209,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -231,7 +244,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -239,7 +252,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -253,17 +266,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 03e16a9367..65d6193dd3 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet8_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet8_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -129,7 +136,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -137,7 +144,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -151,17 +158,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -196,7 +209,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -231,7 +244,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -239,7 +252,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -253,17 +266,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 03e16a9367..65d6193dd3 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet9_0.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.DotNet9_0.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -129,7 +136,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -137,7 +144,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -151,17 +158,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -196,7 +209,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -231,7 +244,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -239,7 +252,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -253,17 +266,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); 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 cdf2ab0fb0..aabb7073ca 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.Net4_7.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1889.Test.Net4_7.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -95,7 +102,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -129,7 +136,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -137,7 +144,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -151,17 +158,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test2__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -196,7 +209,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest), TestMethodName = "Test3", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -231,7 +244,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS ReflectionInfo = typeof(global::TUnit.TestProject.Library.Bugs._1889.BaseTest).GetMethod("Test3", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(bool) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1889.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -239,7 +252,7 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1889.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1889", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -253,17 +266,23 @@ internal sealed class TUnit_TestProject_Bugs__1889_DerivedTest_Test3__bool_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1889.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test3(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests1899.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests1899.Test.verified.txt index 20ec87e37c..ac8a778372 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests1899.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests1899.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__1899_DerivedTest_Test1_TestSource TestClassType = typeof(global::TUnit.TestProject.Bugs._1899.DerivedTest), TestMethodName = "Test1", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -35,7 +35,7 @@ internal sealed class TUnit_TestProject_Bugs__1899_DerivedTest_Test1_TestSource ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1899.DerivedTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._1899.DerivedTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -43,7 +43,7 @@ internal sealed class TUnit_TestProject_Bugs__1899_DerivedTest_Test1_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._1899.DerivedTest)), Name = "DerivedTest", Namespace = "TUnit.TestProject.Bugs._1899", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -57,10 +57,17 @@ internal sealed class TUnit_TestProject_Bugs__1899_DerivedTest_Test1_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._1899.DerivedTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.Test1(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.Test1(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt index 4171f69920..7106ee7e81 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2083.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2083_Tests_MyTest__long_TestSource TestClassType = typeof(global::TUnit.TestProject.Bugs._2083.Tests), TestMethodName = "MyTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -51,7 +51,7 @@ internal sealed class TUnit_TestProject_Bugs__2083_Tests_MyTest__long_TestSource ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._2083.Tests).GetMethod("MyTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(long) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2083.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2083.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -59,7 +59,7 @@ internal sealed class TUnit_TestProject_Bugs__2083_Tests_MyTest__long_TestSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2083.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2083", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -73,17 +73,23 @@ internal sealed class TUnit_TestProject_Bugs__2083_Tests_MyTest__long_TestSource }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2083.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.MyTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.MyTest(TUnit.Core.Helpers.CastHelper.Cast(args[0])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt index 498bc3908a..aa612dac45 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2085.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Double_SpecialConsts__d TestClassType = typeof(global::TUnit.TestProject.Bugs._2085.Tests), TestMethodName = "Double_SpecialConsts", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -46,7 +46,7 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Double_SpecialConsts__d ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._2085.Tests).GetMethod("Double_SpecialConsts", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(double) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2085.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2085.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Double_SpecialConsts__d TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2085.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2085", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -68,15 +68,21 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Double_SpecialConsts__d }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2085.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - await instance.Double_SpecialConsts(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Double_SpecialConsts(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -112,7 +118,7 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Float_SpecialConsts__fl TestClassType = typeof(global::TUnit.TestProject.Bugs._2085.Tests), TestMethodName = "Float_SpecialConsts", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -145,7 +151,7 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Float_SpecialConsts__fl ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._2085.Tests).GetMethod("Float_SpecialConsts", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(float) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2085.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2085.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -153,7 +159,7 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Float_SpecialConsts__fl TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2085.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2085", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -167,15 +173,21 @@ internal sealed class TUnit_TestProject_Bugs__2085_Tests_Float_SpecialConsts__fl }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2085.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.Float_SpecialConsts(TUnit.Core.Helpers.CastHelper.Cast(args[0]))); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.Float_SpecialConsts(TUnit.Core.Helpers.CastHelper.Cast(args[0])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt index db77f85491..8d2e037a83 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2112.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test__int_long___TestSo TestClassType = typeof(global::TUnit.TestProject.Bugs._2112.Tests), TestMethodName = "Test", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -54,7 +54,7 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test__int_long___TestSo ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._2112.Tests).GetMethod("Test", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(long[]) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2112.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2112.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -62,7 +62,7 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test__int_long___TestSo TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2112.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2112", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -76,35 +76,41 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test__int_long___TestSo }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2112.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 1: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[0]); - break; - case 2: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]) })); - break; - case 3: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); - break; - case 4: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); - break; - case 5: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); - break; - case 6: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); - break; - case 7: - instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]) }); - break; - default: - throw new global::System.ArgumentException($"Expected between 1 and 2 arguments, but got {args.Length}"); + switch (args.Length) + { + case 1: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[0]); + return default(global::System.Threading.Tasks.ValueTask); + case 2: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]) })); + return default(global::System.Threading.Tasks.ValueTask); + case 3: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 4: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 5: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 6: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 7: + instance.Test(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]) }); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected between 1 and 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -139,7 +145,7 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test2__int_long___TestS TestClassType = typeof(global::TUnit.TestProject.Bugs._2112.Tests), TestMethodName = "Test2", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -180,7 +186,7 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test2__int_long___TestS ReflectionInfo = typeof(global::TUnit.TestProject.Bugs._2112.Tests).GetMethod("Test2", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(long[]) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2112.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2112.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -188,7 +194,7 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test2__int_long___TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2112.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2112", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -202,35 +208,41 @@ internal sealed class TUnit_TestProject_Bugs__2112_Tests_Test2__int_long___TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.Bugs._2112.Tests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try + { + switch (args.Length) + { + case 1: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[0]); + return default(global::System.Threading.Tasks.ValueTask); + case 2: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]) })); + return default(global::System.Threading.Tasks.ValueTask); + case 3: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 4: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 5: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 6: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); + return default(global::System.Threading.Tasks.ValueTask); + case 7: + instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]) }); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected between 1 and 2 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[0]); - break; - case 2: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), (args[1] is null ? null : args[1] is long[] arr ? arr : new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]) })); - break; - case 3: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]) }); - break; - case 4: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]) }); - break; - case 5: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]) }); - break; - case 6: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]) }); - break; - case 7: - instance.Test2(TUnit.Core.Helpers.CastHelper.Cast(args[0]), new long[] { TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2]), TUnit.Core.Helpers.CastHelper.Cast(args[3]), TUnit.Core.Helpers.CastHelper.Cast(args[4]), TUnit.Core.Helpers.CastHelper.Cast(args[5]), TUnit.Core.Helpers.CastHelper.Cast(args[6]) }); - break; - default: - throw new global::System.ArgumentException($"Expected between 1 and 2 arguments, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt index 4669d3af79..bc3a3320ab 100644 --- a/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/Tests2136.Test.verified.txt @@ -14,7 +14,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TestClassType = typeof(global::TUnit.TestProject.Bugs._2136.Tests), TestMethodName = "GenericArgumentsTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -51,7 +51,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -59,7 +59,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2136.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2136", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -72,7 +72,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.Bugs._2136.Tests(); }, @@ -86,7 +86,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TestMethodName = "GenericArgumentsTest", GenericMethodTypeArguments = new global::System.Type[] { typeof(bool)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute(true, "True"), @@ -128,7 +128,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -136,7 +136,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2136.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2136", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -149,14 +149,21 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.Bugs._2136.Tests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((bool)args[0]!, (string)args[1]!)); + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((bool)args[0]!, (string)args[1]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -168,7 +175,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TestMethodName = "GenericArgumentsTest", GenericMethodTypeArguments = new global::System.Type[] { typeof(int)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute(1, "1"), @@ -210,7 +217,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -218,7 +225,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2136.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2136", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -231,14 +238,21 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.Bugs._2136.Tests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((int)args[0]!, (string)args[1]!)); + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((int)args[0]!, (string)args[1]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -250,7 +264,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TestMethodName = "GenericArgumentsTest", GenericMethodTypeArguments = new global::System.Type[] { typeof(double)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute(1.1, "1.1"), @@ -292,7 +306,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -300,7 +314,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2136.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2136", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -313,14 +327,21 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.Bugs._2136.Tests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((double)args[0]!, (string)args[1]!)); + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((double)args[0]!, (string)args[1]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -332,7 +353,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TestMethodName = "GenericArgumentsTest", GenericMethodTypeArguments = new global::System.Type[] { typeof(string)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute("hello", "hello"), @@ -374,7 +395,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -382,7 +403,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2136.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2136", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -395,14 +416,21 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.Bugs._2136.Tests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((string)args[0]!, (string)args[1]!)); + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((string)args[0]!, (string)args[1]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , @@ -414,7 +442,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TestMethodName = "GenericArgumentsTest", GenericMethodTypeArguments = new global::System.Type[] { typeof(global::TUnit.TestProject.Bugs._2136.MyEnum)}, Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.ArgumentsAttribute(global::TUnit.TestProject.Bugs._2136.MyEnum.Item, "Item"), @@ -456,7 +484,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T ReflectionInfo = global::System.Linq.Enumerable.FirstOrDefault(typeof(global::TUnit.TestProject.Bugs._2136.Tests).GetMethods(global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance | global::System.Reflection.BindingFlags.Static), m => m.Name == "GenericArgumentsTest" && m.GetParameters().Length == 2)?.GetParameters()[1]! } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.Bugs._2136.Tests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -464,7 +492,7 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.Bugs._2136.Tests)), Name = "Tests", Namespace = "TUnit.TestProject.Bugs._2136", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -477,14 +505,21 @@ internal sealed class TUnit_TestProject_Bugs__2136_Tests_GenericArgumentsTest__T return classMetadata; }) }, - InstanceFactory = (typeArgs, args) => + InstanceFactory = static (typeArgs, args) => { return new global::TUnit.TestProject.Bugs._2136.Tests(); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; - await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((global::TUnit.TestProject.Bugs._2136.MyEnum)args[0]!, (string)args[1]!)); + try + { + var typedInstance = (global::TUnit.TestProject.Bugs._2136.Tests)instance; + return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.GenericArgumentsTest((global::TUnit.TestProject.Bugs._2136.MyEnum)args[0]!, (string)args[1]!)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } } } , diff --git a/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt index 000f6132da..180fa355b9 100644 --- a/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/TimeoutCancellationTokenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DefaultTes TestClassType = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests), TestMethodName = "DefaultTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass), @@ -69,7 +69,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DefaultTes ReflectionInfo = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests).GetMethod("DefaultTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -77,7 +77,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DefaultTes TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests)), Name = "TimeoutCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -103,9 +103,16 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DefaultTes { return new global::TUnit.TestProject.TimeoutCancellationTokenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.DefaultTest(cancellationToken); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.DefaultTest(cancellationToken)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -140,7 +147,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_BasicTest_ TestClassType = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests), TestMethodName = "BasicTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.TimeoutAttribute(5_000), @@ -198,7 +205,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_BasicTest_ ReflectionInfo = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests).GetMethod("BasicTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -206,7 +213,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_BasicTest_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests)), Name = "TimeoutCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -232,9 +239,16 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_BasicTest_ { return new global::TUnit.TestProject.TimeoutCancellationTokenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.BasicTest(cancellationToken); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.BasicTest(cancellationToken)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -269,7 +283,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_InheritedT TestClassType = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests), TestMethodName = "InheritedTimeoutAttribute", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.TimeoutCancellationTokenTests.FiveSecondTimeout(), @@ -326,7 +340,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_InheritedT ReflectionInfo = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests).GetMethod("InheritedTimeoutAttribute", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[0] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -334,7 +348,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_InheritedT TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests)), Name = "TimeoutCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -360,9 +374,16 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_InheritedT { return new global::TUnit.TestProject.TimeoutCancellationTokenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - await instance.InheritedTimeoutAttribute(cancellationToken); + try + { + return new global::System.Threading.Tasks.ValueTask(instance.InheritedTimeoutAttribute(cancellationToken)); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); @@ -397,7 +418,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataTest__ TestClassType = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests), TestMethodName = "DataTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.TimeoutAttribute(5_000), @@ -464,7 +485,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataTest__ ReflectionInfo = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests).GetMethod("DataTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -472,7 +493,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataTest__ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests)), Name = "TimeoutCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -498,16 +519,22 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataTest__ { return new global::TUnit.TestProject.TimeoutCancellationTokenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var context = global::TUnit.Core.TestContext.Current; - switch (args.Length) + try { - case 1: - await instance.DataTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + var context = global::TUnit.Core.TestContext.Current; + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.DataTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None)); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -543,7 +570,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataSource TestClassType = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests), TestMethodName = "DataSourceTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TimeoutAttribute(5_000), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Failure), @@ -631,7 +658,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataSource ReflectionInfo = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests).GetMethod("DataSourceTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -639,7 +666,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataSource TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests)), Name = "TimeoutCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -665,16 +692,22 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_DataSource { return new global::TUnit.TestProject.TimeoutCancellationTokenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var context = global::TUnit.Core.TestContext.Current; - switch (args.Length) + try + { + var context = global::TUnit.Core.TestContext.Current; + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.DataSourceTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None)); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.DataSourceTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; @@ -710,7 +743,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_MatrixTest TestClassType = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests), TestMethodName = "MatrixTest", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.Core.TimeoutAttribute(5_000), @@ -778,7 +811,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_MatrixTest ReflectionInfo = typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests).GetMethod("MatrixTest", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(global::System.Threading.CancellationToken) }, null)!.GetParameters()[1] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TimeoutCancellationTokenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -786,7 +819,7 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_MatrixTest TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TimeoutCancellationTokenTests)), Name = "TimeoutCancellationTokenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = new global::TUnit.Core.ParameterMetadata[] { new global::TUnit.Core.ParameterMetadata(typeof(int)) @@ -812,16 +845,22 @@ internal sealed class TUnit_TestProject_TimeoutCancellationTokenTests_MatrixTest { return new global::TUnit.TestProject.TimeoutCancellationTokenTests(TUnit.Core.Helpers.CastHelper.Cast(args[0])); }, - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - var context = global::TUnit.Core.TestContext.Current; - switch (args.Length) + try + { + var context = global::TUnit.Core.TestContext.Current; + switch (args.Length) + { + case 1: + return new global::System.Threading.Tasks.ValueTask(instance.MatrixTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None)); + default: + throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + } + } + catch (global::System.Exception ex) { - case 1: - await instance.MatrixTest(TUnit.Core.Helpers.CastHelper.Cast(args[0]), context?.CancellationToken ?? System.Threading.CancellationToken.None); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 1 argument, but got {args.Length}"); + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } }, }; diff --git a/TUnit.Core.SourceGenerator.Tests/TupleDataSourceDrivenTests.Test.verified.txt b/TUnit.Core.SourceGenerator.Tests/TupleDataSourceDrivenTests.Test.verified.txt index ae03807fe2..11251b1886 100644 --- a/TUnit.Core.SourceGenerator.Tests/TupleDataSourceDrivenTests.Test.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/TupleDataSourceDrivenTests.Test.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_TupleDataSourceDrivenTests_DataSource_Tu TestClassType = typeof(global::TUnit.TestProject.TupleDataSourceDrivenTests), TestMethodName = "DataSource_TupleMethod", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute(), new global::TUnit.TestProject.Attributes.EngineTest(global::TUnit.TestProject.Attributes.ExpectedResult.Pass) @@ -71,7 +71,7 @@ internal sealed class TUnit_TestProject_TupleDataSourceDrivenTests_DataSource_Tu ReflectionInfo = typeof(global::TUnit.TestProject.TupleDataSourceDrivenTests).GetMethod("DataSource_TupleMethod", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(string), typeof(bool) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TupleDataSourceDrivenTests", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("TestsBase`1:global::TUnit.TestProject.TupleDataSourceDrivenTests", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -79,7 +79,7 @@ internal sealed class TUnit_TestProject_TupleDataSourceDrivenTests_DataSource_Tu TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TupleDataSourceDrivenTests)), Name = "TupleDataSourceDrivenTests", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("TestsBase`1", static () => new global::TUnit.Core.AssemblyMetadata { Name = "TestsBase`1" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -93,17 +93,23 @@ internal sealed class TUnit_TestProject_TupleDataSourceDrivenTests_DataSource_Tu }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.TupleDataSourceDrivenTests(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - instance.DataSource_TupleMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + instance.DataSource_TupleMethod(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt index d31973547c..c8205e4f6e 100644 --- a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_AotSafeDataSourceFactories.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_AotDataSourceTest_TestWithDataSource__in TestClassType = typeof(global::TUnit.TestProject.AotDataSourceTest), TestMethodName = "TestWithDataSource", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -60,7 +60,7 @@ internal sealed class TUnit_TestProject_AotDataSourceTest_TestWithDataSource__in ReflectionInfo = typeof(global::TUnit.TestProject.AotDataSourceTest).GetMethod("TestWithDataSource", global::System.Reflection.BindingFlags.Public | global::System.Reflection.BindingFlags.NonPublic | global::System.Reflection.BindingFlags.Instance, null, new global::System.Type[] { typeof(int), typeof(int), typeof(int) }, null)!.GetParameters()[2] } }, - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.AotDataSourceTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.AotDataSourceTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -68,7 +68,7 @@ internal sealed class TUnit_TestProject_AotDataSourceTest_TestWithDataSource__in TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.AotDataSourceTest)), Name = "AotDataSourceTest", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -82,17 +82,23 @@ internal sealed class TUnit_TestProject_AotDataSourceTest_TestWithDataSource__in }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.AotDataSourceTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - switch (args.Length) + try { - case 3: - instance.TestWithDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); - break; - default: - throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + switch (args.Length) + { + case 3: + instance.TestWithDataSource(TUnit.Core.Helpers.CastHelper.Cast(args[0]), TUnit.Core.Helpers.CastHelper.Cast(args[1]), TUnit.Core.Helpers.CastHelper.Cast(args[2])); + return default(global::System.Threading.Tasks.ValueTask); + default: + throw new global::System.ArgumentException($"Expected exactly 3 arguments, but got {args.Length}"); + } + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); } - await global::System.Threading.Tasks.Task.CompletedTask; }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ConfigurationSupport.verified.txt b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ConfigurationSupport.verified.txt index 1b555edc1b..323116974b 100644 --- a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ConfigurationSupport.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ConfigurationSupport.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ConfigurationTest_TestWithConfiguration_ TestClassType = typeof(global::TUnit.TestProject.ConfigurationTest), TestMethodName = "TestWithConfiguration", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_ConfigurationTest_TestWithConfiguration_ ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.ConfigurationTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.ConfigurationTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_ConfigurationTest_TestWithConfiguration_ TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ConfigurationTest)), Name = "ConfigurationTest", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_ConfigurationTest_TestWithConfiguration_ }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ConfigurationTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.TestWithConfiguration(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.TestWithConfiguration(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ModuleInitializer_Generation.verified.txt b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ModuleInitializer_Generation.verified.txt index cada425949..c545f3a741 100644 --- a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ModuleInitializer_Generation.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_ModuleInitializer_Generation.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_ModuleInitializerTest_TestWithModuleInit TestClassType = typeof(global::TUnit.TestProject.ModuleInitializerTest), TestMethodName = "TestWithModuleInit", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_ModuleInitializerTest_TestWithModuleInit ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.ModuleInitializerTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.ModuleInitializerTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_ModuleInitializerTest_TestWithModuleInit TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.ModuleInitializerTest)), Name = "ModuleInitializerTest", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_ModuleInitializerTest_TestWithModuleInit }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.ModuleInitializerTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.TestWithModuleInit(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.TestWithModuleInit(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_StronglyTypedDelegates_Generation.verified.txt b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_StronglyTypedDelegates_Generation.verified.txt index 14ad21f01b..5754b8bd4e 100644 --- a/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_StronglyTypedDelegates_Generation.verified.txt +++ b/TUnit.Core.SourceGenerator.Tests/UnifiedReflectionFreeTests.Test_StronglyTypedDelegates_Generation.verified.txt @@ -13,7 +13,7 @@ internal sealed class TUnit_TestProject_TypedDelegateTest_TestWithDelegate_TestS TestClassType = typeof(global::TUnit.TestProject.TypedDelegateTest), TestMethodName = "TestWithDelegate", Dependencies = global::System.Array.Empty(), - AttributeFactory = () => + AttributeFactory = static () => [ new global::TUnit.Core.TestAttribute() ], @@ -33,7 +33,7 @@ internal sealed class TUnit_TestProject_TypedDelegateTest_TestWithDelegate_TestS ReturnType = typeof(void), ReturnTypeInfo = new global::TUnit.Core.ConcreteType(typeof(void)), Parameters = global::System.Array.Empty(), - Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.TypedDelegateTest", () => + Class = global::TUnit.Core.ClassMetadata.GetOrAdd("UnifiedReflectionFreeTests:global::TUnit.TestProject.TypedDelegateTest", static () => { var classMetadata = new global::TUnit.Core.ClassMetadata { @@ -41,7 +41,7 @@ internal sealed class TUnit_TestProject_TypedDelegateTest_TestWithDelegate_TestS TypeInfo = new global::TUnit.Core.ConcreteType(typeof(global::TUnit.TestProject.TypedDelegateTest)), Name = "TypedDelegateTest", Namespace = "TUnit.TestProject", - Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), + Assembly = global::TUnit.Core.AssemblyMetadata.GetOrAdd("UnifiedReflectionFreeTests", static () => new global::TUnit.Core.AssemblyMetadata { Name = "UnifiedReflectionFreeTests" }), Parameters = global::System.Array.Empty(), Properties = global::System.Array.Empty(), Parent = null @@ -55,10 +55,17 @@ internal sealed class TUnit_TestProject_TypedDelegateTest_TestWithDelegate_TestS }) }, InstanceFactory = (typeArgs, args) => new global::TUnit.TestProject.TypedDelegateTest(), - InvokeTypedTest = async (instance, args, cancellationToken) => + InvokeTypedTest = static (instance, args, cancellationToken) => { - instance.TestWithDelegate(); - await global::System.Threading.Tasks.Task.CompletedTask; + try + { + instance.TestWithDelegate(); + return default(global::System.Threading.Tasks.ValueTask); + } + catch (global::System.Exception ex) + { + return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex)); + } }, }; metadata.UseRuntimeDataGeneration(testSessionId); diff --git a/TUnit.Core.SourceGenerator/Extensions/AttributeDataExtensions.cs b/TUnit.Core.SourceGenerator/Extensions/AttributeDataExtensions.cs index e13ab939d7..23edbd23f4 100644 --- a/TUnit.Core.SourceGenerator/Extensions/AttributeDataExtensions.cs +++ b/TUnit.Core.SourceGenerator/Extensions/AttributeDataExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.CodeAnalysis; +using TUnit.Core.SourceGenerator.Helpers; namespace TUnit.Core.SourceGenerator.Extensions; @@ -16,19 +17,28 @@ public static bool IsTestAttribute(this AttributeData? attributeData) public static bool IsDataSourceAttribute(this AttributeData? attributeData) { - return attributeData?.AttributeClass?.AllInterfaces.Any(x => - x.GloballyQualified() == WellKnownFullyQualifiedClassNames.IDataSourceAttribute.WithGlobalPrefix) - == true; + if (attributeData?.AttributeClass == null) + { + return false; + } + + // Use InterfaceCache instead of AllInterfaces.Any() for better performance + return InterfaceCache.ImplementsInterface(attributeData.AttributeClass, + WellKnownFullyQualifiedClassNames.IDataSourceAttribute.WithGlobalPrefix); } - + public static bool IsTypedDataSourceAttribute(this AttributeData? attributeData) { - return attributeData?.AttributeClass?.AllInterfaces.Any(x => - x.IsGenericType && - x.ConstructedFrom.GloballyQualified() == WellKnownFullyQualifiedClassNames.ITypedDataSourceAttribute.WithGlobalPrefix + "`1") - == true; + if (attributeData?.AttributeClass == null) + { + return false; + } + + // Use InterfaceCache instead of AllInterfaces.Any() for better performance + return InterfaceCache.ImplementsGenericInterface(attributeData.AttributeClass, + WellKnownFullyQualifiedClassNames.ITypedDataSourceAttribute.WithGlobalPrefix + "`1"); } - + public static ITypeSymbol? GetTypedDataSourceType(this AttributeData? attributeData) { if (attributeData?.AttributeClass == null) @@ -36,10 +46,10 @@ public static bool IsTypedDataSourceAttribute(this AttributeData? attributeData) return null; } - var typedInterface = attributeData.AttributeClass.AllInterfaces - .FirstOrDefault(x => x.IsGenericType && - x.ConstructedFrom.GloballyQualified() == WellKnownFullyQualifiedClassNames.ITypedDataSourceAttribute.WithGlobalPrefix + "`1"); - + // Use InterfaceCache instead of AllInterfaces.FirstOrDefault() for better performance + var typedInterface = InterfaceCache.GetGenericInterface(attributeData.AttributeClass, + WellKnownFullyQualifiedClassNames.ITypedDataSourceAttribute.WithGlobalPrefix + "`1"); + return typedInterface?.TypeArguments.FirstOrDefault(); } diff --git a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs index 35ffe284ac..4a65b807c1 100644 --- a/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs +++ b/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs @@ -394,7 +394,7 @@ private static void GenerateAotFriendlyInvokers( p.Type.Name == "CancellationToken" && p.Type.ContainingNamespace?.ToString() == "System.Threading"); - writer.AppendLine("InstanceFactory = (typeArgs, args) =>"); + writer.AppendLine("InstanceFactory = static (typeArgs, args) =>"); writer.AppendLine("{"); writer.Indent(); @@ -403,7 +403,12 @@ private static void GenerateAotFriendlyInvokers( writer.Unindent(); writer.AppendLine("},"); - writer.AppendLine("InvokeTypedTest = async (instance, args, cancellationToken) =>"); + writer.AppendLine("InvokeTypedTest = static (instance, args, cancellationToken) =>"); + writer.AppendLine("{"); + writer.Indent(); + + // Wrap entire lambda body in try-catch to handle synchronous exceptions + writer.AppendLine("try"); writer.AppendLine("{"); writer.Indent(); @@ -433,7 +438,16 @@ private static void GenerateAotFriendlyInvokers( } } - writer.AppendLine($"await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.{methodName}<{typeArgsString}>({string.Join(", ", parameterCasts)}));"); + writer.AppendLine($"return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.{methodName}<{typeArgsString}>({string.Join(", ", parameterCasts)}));"); + + writer.Unindent(); + writer.AppendLine("}"); + writer.AppendLine("catch (global::System.Exception ex)"); + writer.AppendLine("{"); + writer.Indent(); + writer.AppendLine("return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex));"); + writer.Unindent(); + writer.AppendLine("}"); writer.Unindent(); writer.AppendLine("},"); @@ -538,7 +552,7 @@ private static void GenerateMetadata(CodeWriter writer, TestMethodMetadata testM GenerateDependencies(writer, compilation, methodSymbol); - writer.AppendLine("AttributeFactory = () =>"); + writer.AppendLine("AttributeFactory = static () =>"); writer.AppendLine("["); writer.Indent(); @@ -553,6 +567,13 @@ private static void GenerateMetadata(CodeWriter writer, TestMethodMetadata testM writer.Unindent(); writer.AppendLine("],"); + // Extract and emit RepeatCount if present + var repeatCount = ExtractRepeatCount(methodSymbol, testMethod.TypeSymbol); + if (repeatCount.HasValue) + { + writer.AppendLine($"RepeatCount = {repeatCount.Value},"); + } + GenerateDataSources(writer, testMethod); GeneratePropertyInjections(writer, testMethod.TypeSymbol, testMethod.TypeSymbol.GloballyQualified()); @@ -577,7 +598,7 @@ private static void GenerateMetadataForConcreteInstantiation(CodeWriter writer, GenerateDependencies(writer, compilation, methodSymbol); - writer.AppendLine("AttributeFactory = () =>"); + writer.AppendLine("AttributeFactory = static () =>"); writer.AppendLine("["); writer.Indent(); @@ -593,6 +614,13 @@ private static void GenerateMetadataForConcreteInstantiation(CodeWriter writer, writer.Unindent(); writer.AppendLine("],"); + // Extract and emit RepeatCount if present + var repeatCount = ExtractRepeatCount(methodSymbol, testMethod.TypeSymbol); + if (repeatCount.HasValue) + { + writer.AppendLine($"RepeatCount = {repeatCount.Value},"); + } + // No data sources for concrete instantiations writer.AppendLine("DataSources = global::System.Array.Empty(),"); writer.AppendLine("ClassDataSources = global::System.Array.Empty(),"); @@ -1824,17 +1852,23 @@ private static void GenerateTypedInvokers(CodeWriter writer, TestMethodMetadata // Generate InvokeTypedTest for non-generic tests var isAsync = IsAsyncMethod(testMethod.MethodSymbol); + var returnsValueTask = ReturnsValueTask(testMethod.MethodSymbol); if (testMethod is { IsGenericType: false, IsGenericMethod: false }) { - GenerateConcreteTestInvoker(writer, testMethod, className, methodName, isAsync, hasCancellationToken, parametersFromArgs); + GenerateConcreteTestInvoker(writer, testMethod, className, methodName, isAsync, returnsValueTask, hasCancellationToken, parametersFromArgs); } } - private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMetadata testMethod, string className, string methodName, bool isAsync, bool hasCancellationToken, IParameterSymbol[] parametersFromArgs) + private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMetadata testMethod, string className, string methodName, bool isAsync, bool returnsValueTask, bool hasCancellationToken, IParameterSymbol[] parametersFromArgs) { // Generate InvokeTypedTest which is required by CreateExecutableTestFactory - writer.AppendLine("InvokeTypedTest = async (instance, args, cancellationToken) =>"); + writer.AppendLine("InvokeTypedTest = static (instance, args, cancellationToken) =>"); + writer.AppendLine("{"); + writer.Indent(); + + // Wrap entire lambda body in try-catch to handle synchronous exceptions + writer.AppendLine("try"); writer.AppendLine("{"); writer.Indent(); @@ -1868,11 +1902,19 @@ private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMet : $"instance.{methodName}({tupleConstruction})"; if (isAsync) { - writer.AppendLine($"await {methodCallReconstructed};"); + if (returnsValueTask) + { + writer.AppendLine($"return {methodCallReconstructed};"); + } + else + { + writer.AppendLine($"return new global::System.Threading.Tasks.ValueTask({methodCallReconstructed});"); + } } else { writer.AppendLine($"{methodCallReconstructed};"); + writer.AppendLine("return default(global::System.Threading.Tasks.ValueTask);"); } writer.Unindent(); writer.AppendLine("}"); @@ -1885,11 +1927,19 @@ private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMet : $"instance.{methodName}(TUnit.Core.Helpers.CastHelper.Cast<{singleTupleParam.GloballyQualified()}>(args[0]))"; if (isAsync) { - writer.AppendLine($"await {methodCallDirect};"); + if (returnsValueTask) + { + writer.AppendLine($"return {methodCallDirect};"); + } + else + { + writer.AppendLine($"return new global::System.Threading.Tasks.ValueTask({methodCallDirect});"); + } } else { writer.AppendLine($"{methodCallDirect};"); + writer.AppendLine("return default(global::System.Threading.Tasks.ValueTask);"); } writer.Unindent(); writer.AppendLine("}"); @@ -1907,12 +1957,19 @@ private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMet : $"instance.{methodName}()"; if (isAsync) { - writer.AppendLine($"await {typedMethodCall};"); + if (returnsValueTask) + { + writer.AppendLine($"return {typedMethodCall};"); + } + else + { + writer.AppendLine($"return new global::System.Threading.Tasks.ValueTask({typedMethodCall});"); + } } else { writer.AppendLine($"{typedMethodCall};"); - writer.AppendLine("await global::System.Threading.Tasks.Task.CompletedTask;"); + writer.AppendLine("return default(global::System.Threading.Tasks.ValueTask);"); } } else @@ -1952,13 +2009,20 @@ private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMet if (isAsync) { - writer.AppendLine($"await {typedMethodCall};"); + if (returnsValueTask) + { + writer.AppendLine($"return {typedMethodCall};"); + } + else + { + writer.AppendLine($"return new global::System.Threading.Tasks.ValueTask({typedMethodCall});"); + } } else { writer.AppendLine($"{typedMethodCall};"); + writer.AppendLine("return default(global::System.Threading.Tasks.ValueTask);"); } - writer.AppendLine("break;"); writer.Unindent(); } @@ -1976,13 +2040,17 @@ private static void GenerateConcreteTestInvoker(CodeWriter writer, TestMethodMet writer.Unindent(); writer.AppendLine("}"); - - if (!isAsync) - { - writer.AppendLine("await global::System.Threading.Tasks.Task.CompletedTask;"); - } } + writer.Unindent(); + writer.AppendLine("}"); + writer.AppendLine("catch (global::System.Exception ex)"); + writer.AppendLine("{"); + writer.Indent(); + writer.AppendLine("return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex));"); + writer.Unindent(); + writer.AppendLine("}"); + writer.Unindent(); writer.AppendLine("},"); } @@ -2016,6 +2084,12 @@ private static bool IsAsyncMethod(IMethodSymbol method) returnTypeName.StartsWith("ValueTask<"); } + private static bool ReturnsValueTask(IMethodSymbol method) + { + var returnTypeName = method.ReturnType.ToDisplayString(); + return returnTypeName.StartsWith("System.Threading.Tasks.ValueTask"); + } + private static void GenerateDependencies(CodeWriter writer, Compilation compilation, IMethodSymbol methodSymbol) { var dependsOnAttributes = methodSymbol.GetAttributes() @@ -2638,7 +2712,7 @@ private static void GenerateGenericTestWithConcreteTypes( GenerateMetadataForConcreteInstantiation(writer, testMethod); // Generate instance factory that works with generic types - writer.AppendLine("InstanceFactory = (typeArgs, args) =>"); + writer.AppendLine("InstanceFactory = static (typeArgs, args) =>"); writer.AppendLine("{"); writer.Indent(); @@ -4144,7 +4218,7 @@ private static void GenerateConcreteTestMetadata( GenerateConcreteMetadataWithFilteredDataSources(writer, testMethod, specificArgumentsAttribute, typeArguments); // Generate instance factory - writer.AppendLine("InstanceFactory = (typeArgs, args) =>"); + writer.AppendLine("InstanceFactory = static (typeArgs, args) =>"); writer.AppendLine("{"); writer.Indent(); @@ -4193,7 +4267,12 @@ private static void GenerateConcreteTestMetadata( writer.AppendLine("},"); // Generate strongly-typed test invoker - writer.AppendLine("InvokeTypedTest = async (instance, args, cancellationToken) =>"); + writer.AppendLine("InvokeTypedTest = static (instance, args, cancellationToken) =>"); + writer.AppendLine("{"); + writer.Indent(); + + // Wrap entire lambda body in try-catch to handle synchronous exceptions + writer.AppendLine("try"); writer.AppendLine("{"); writer.Indent(); @@ -4224,13 +4303,22 @@ private static void GenerateConcreteTestMetadata( if (methodTypeArgs.Length > 0) { var methodTypeArgsString = string.Join(", ", methodTypeArgs.Select(t => t.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat))); - writer.AppendLine($"await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.{methodName}<{methodTypeArgsString}>({string.Join(", ", parameterCasts)}));"); + writer.AppendLine($"return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.{methodName}<{methodTypeArgsString}>({string.Join(", ", parameterCasts)}));"); } else { - writer.AppendLine($"await global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.{methodName}({string.Join(", ", parameterCasts)}));"); + writer.AppendLine($"return global::TUnit.Core.AsyncConvert.Convert(() => typedInstance.{methodName}({string.Join(", ", parameterCasts)}));"); } + writer.Unindent(); + writer.AppendLine("}"); + writer.AppendLine("catch (global::System.Exception ex)"); + writer.AppendLine("{"); + writer.Indent(); + writer.AppendLine("return new global::System.Threading.Tasks.ValueTask(global::System.Threading.Tasks.Task.FromException(ex));"); + writer.Unindent(); + writer.AppendLine("}"); + writer.Unindent(); writer.AppendLine("}"); @@ -4328,13 +4416,20 @@ private static void GenerateConcreteMetadataWithFilteredDataSources( filteredAttributes.AddRange(testMethod.TypeSymbol.GetAttributesIncludingBaseTypes()); filteredAttributes.AddRange(testMethod.TypeSymbol.ContainingAssembly.GetAttributes()); - writer.AppendLine("AttributeFactory = () =>"); + writer.AppendLine("AttributeFactory = static () =>"); writer.AppendLine("["); writer.Indent(); AttributeWriter.WriteAttributes(writer, compilation, filteredAttributes.ToImmutableArray()); writer.Unindent(); writer.AppendLine("],"); + // Extract and emit RepeatCount if present + var repeatCount = ExtractRepeatCount(methodSymbol, typeSymbol); + if (repeatCount.HasValue) + { + writer.AppendLine($"RepeatCount = {repeatCount.Value},"); + } + // Filter data sources based on the specific attribute List methodDataSources; List classDataSources; @@ -4643,7 +4738,7 @@ private static void GenerateConcreteTestMetadataForNonGeneric( GenerateDependencies(writer, compilation, testMethod.MethodSymbol); // Generate attribute factory - writer.AppendLine("AttributeFactory = () =>"); + writer.AppendLine("AttributeFactory = static () =>"); writer.AppendLine("["); writer.Indent(); @@ -4657,6 +4752,13 @@ private static void GenerateConcreteTestMetadataForNonGeneric( writer.Unindent(); writer.AppendLine("],"); + // Extract and emit RepeatCount if present + var repeatCount = ExtractRepeatCount(testMethod.MethodSymbol, testMethod.TypeSymbol); + if (repeatCount.HasValue) + { + writer.AppendLine($"RepeatCount = {repeatCount.Value},"); + } + if (methodDataSourceAttribute == null) { writer.AppendLine("DataSources = global::System.Array.Empty(),"); @@ -4696,7 +4798,7 @@ private static void GenerateConcreteTestMetadataForNonGeneric( SourceInformationWriter.GenerateMethodInformation(writer, compilation, testMethod.TypeSymbol, testMethod.MethodSymbol, null, ','); // Generate instance factory - writer.AppendLine("InstanceFactory = (typeArgs, args) =>"); + writer.AppendLine("InstanceFactory = static (typeArgs, args) =>"); writer.AppendLine("{"); writer.Indent(); @@ -4761,6 +4863,32 @@ private static void GenerateConcreteTestMetadataForNonGeneric( writer.AppendLine("yield return metadata;"); } + + private static int? ExtractRepeatCount(IMethodSymbol methodSymbol, INamedTypeSymbol typeSymbol) + { + // Check method-level RepeatAttribute first + var repeatAttribute = methodSymbol.GetAttributes() + .FirstOrDefault(a => a.AttributeClass?.Name == "RepeatAttribute"); + + if (repeatAttribute?.ConstructorArguments.Length > 0 + && repeatAttribute.ConstructorArguments[0].Value is int methodCount) + { + return methodCount; + } + + // Check class-level RepeatAttribute (can be inherited) + var classRepeatAttr = typeSymbol.GetAttributesIncludingBaseTypes() + .FirstOrDefault(a => a.AttributeClass?.Name == "RepeatAttribute"); + + if (classRepeatAttr?.ConstructorArguments.Length > 0 + && classRepeatAttr.ConstructorArguments[0].Value is int classCount) + { + return classCount; + } + + // No repeat attribute found + return null; + } } public class InheritsTestsClassMetadata diff --git a/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs b/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs index 61683d4d07..18542df551 100644 --- a/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs +++ b/TUnit.Core.SourceGenerator/Models/TestDefinitionContext.cs @@ -39,7 +39,13 @@ public static IEnumerable CreateContexts(TestMetadataGene var testIndex = 0; - if (!classDataAttrs.Any() && !methodDataAttrs.Any()) + // Convert to arrays once upfront for better performance (avoid repeated .Any() calls and enumeration) + var classDataArray = classDataAttrs.Count > 0 ? classDataAttrs.ToArray() : []; + var methodDataArray = methodDataAttrs.Count > 0 ? methodDataAttrs.ToArray() : []; + var hasClassData = classDataArray.Length > 0; + var hasMethodData = methodDataArray.Length > 0; + + if (!hasClassData && !hasMethodData) { for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++) { @@ -55,16 +61,17 @@ public static IEnumerable CreateContexts(TestMetadataGene yield break; } - if (classDataAttrs.Any() && !methodDataAttrs.Any()) + if (hasClassData && !hasMethodData) { - foreach (var classAttr in classDataAttrs) + // Use array indexing instead of foreach for slightly better performance + for (var i = 0; i < classDataArray.Length; i++) { for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++) { yield return new TestDefinitionContext { GenerationContext = generationContext, - ClassDataAttribute = classAttr, + ClassDataAttribute = classDataArray[i], MethodDataAttribute = null, TestIndex = testIndex++, RepeatIndex = repeatIndex @@ -72,9 +79,10 @@ public static IEnumerable CreateContexts(TestMetadataGene } } } - else if (!classDataAttrs.Any() && methodDataAttrs.Any()) + else if (!hasClassData && hasMethodData) { - foreach (var methodAttr in methodDataAttrs) + // Use array indexing instead of foreach for slightly better performance + for (var i = 0; i < methodDataArray.Length; i++) { for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++) { @@ -82,27 +90,28 @@ public static IEnumerable CreateContexts(TestMetadataGene { GenerationContext = generationContext, ClassDataAttribute = null, - MethodDataAttribute = methodAttr, + MethodDataAttribute = methodDataArray[i], TestIndex = testIndex++, RepeatIndex = repeatIndex }; } } } - // If we have both class and method data - create cartesian product + // If we have both class and method data - create cartesian product with array indexing else { - foreach (var classAttr in classDataAttrs) + // Use array indexing for cartesian product for better performance + for (var i = 0; i < classDataArray.Length; i++) { - foreach (var methodAttr in methodDataAttrs) + for (var j = 0; j < methodDataArray.Length; j++) { for (var repeatIndex = 0; repeatIndex < repeatCount; repeatIndex++) { yield return new TestDefinitionContext { GenerationContext = generationContext, - ClassDataAttribute = classAttr, - MethodDataAttribute = methodAttr, + ClassDataAttribute = classDataArray[i], + MethodDataAttribute = methodDataArray[j], TestIndex = testIndex++, RepeatIndex = repeatIndex }; diff --git a/TUnit.Core.SourceGenerator/Utilities/MetadataGenerationHelper.cs b/TUnit.Core.SourceGenerator/Utilities/MetadataGenerationHelper.cs index e55fdb5a26..786d91f382 100644 --- a/TUnit.Core.SourceGenerator/Utilities/MetadataGenerationHelper.cs +++ b/TUnit.Core.SourceGenerator/Utilities/MetadataGenerationHelper.cs @@ -126,7 +126,7 @@ public static string GenerateMethodMetadata(IMethodSymbol methodSymbol, string c private static void WriteClassMetadataGetOrAdd(ICodeWriter writer, INamedTypeSymbol typeSymbol, string? parentExpression = null) { var qualifiedName = $"{typeSymbol.ContainingAssembly.Name}:{typeSymbol.GloballyQualified()}"; - writer.AppendLine($"global::TUnit.Core.ClassMetadata.GetOrAdd(\"{qualifiedName}\", () => "); + writer.AppendLine($"global::TUnit.Core.ClassMetadata.GetOrAdd(\"{qualifiedName}\", static () => "); writer.AppendLine("{"); // Manually increment indent level without calling EnsureNewLine @@ -199,7 +199,7 @@ public static string GenerateClassMetadataGetOrAdd(INamedTypeSymbol typeSymbol, { var qualifiedName = $"{typeSymbol.ContainingAssembly.Name}:{typeSymbol.GloballyQualified()}"; var writer = new CodeWriter("", includeHeader: false).SetIndentLevel(currentIndentLevel); - writer.AppendLine($"global::TUnit.Core.ClassMetadata.GetOrAdd(\"{qualifiedName}\", () => "); + writer.AppendLine($"global::TUnit.Core.ClassMetadata.GetOrAdd(\"{qualifiedName}\", static () => "); writer.AppendLine("{"); writer.Indent(); @@ -257,7 +257,7 @@ public static string GenerateClassMetadataGetOrAdd(INamedTypeSymbol typeSymbol, /// public static string GenerateAssemblyMetadataGetOrAdd(IAssemblySymbol assembly) { - return $"global::TUnit.Core.AssemblyMetadata.GetOrAdd(\"{assembly.Name}\", () => new global::TUnit.Core.AssemblyMetadata {{ Name = \"{assembly.Name}\" }})"; + return $"global::TUnit.Core.AssemblyMetadata.GetOrAdd(\"{assembly.Name}\", static () => new global::TUnit.Core.AssemblyMetadata {{ Name = \"{assembly.Name}\" }})"; } /// diff --git a/TUnit.Core/AbstractExecutableTest.cs b/TUnit.Core/AbstractExecutableTest.cs index 7a81eb40fb..a668961b3a 100644 --- a/TUnit.Core/AbstractExecutableTest.cs +++ b/TUnit.Core/AbstractExecutableTest.cs @@ -18,6 +18,11 @@ public abstract class AbstractExecutableTest public abstract Task InvokeTestAsync(object instance, CancellationToken cancellationToken); + // Cache fields for filtering performance + internal string? CachedFilterPath { get; set; } + // Using object to avoid type dependency on Microsoft.Testing.Platform.Extensions.Messages.PropertyBag + internal object? CachedPropertyBag { get; set; } + public required TestContext Context { get; diff --git a/TUnit.Core/AsyncConvert.cs b/TUnit.Core/AsyncConvert.cs index bb660a847b..4f63c36718 100644 --- a/TUnit.Core/AsyncConvert.cs +++ b/TUnit.Core/AsyncConvert.cs @@ -124,7 +124,7 @@ private static ValueTask StartAsFSharpTask(object invoke, Type type) { var startAsTaskOpenGenericMethod = (_fSharpAsyncType ??= type.Assembly.GetType("Microsoft.FSharp.Control.FSharpAsync"))! .GetRuntimeMethods() - .FirstOrDefault(m => m.Name == "StartAsTask"); + .FirstOrDefault(static m => m.Name == "StartAsTask"); if (startAsTaskOpenGenericMethod is null) { diff --git a/TUnit.Core/Attributes/TestData/MatrixDataSourceAttribute.cs b/TUnit.Core/Attributes/TestData/MatrixDataSourceAttribute.cs index 1d975a8dbc..d47e351941 100644 --- a/TUnit.Core/Attributes/TestData/MatrixDataSourceAttribute.cs +++ b/TUnit.Core/Attributes/TestData/MatrixDataSourceAttribute.cs @@ -36,18 +36,19 @@ public sealed class MatrixDataSourceAttribute : UntypedDataSourceGeneratorAttrib foreach (var row in GetMatrixValues(parameterInformation.Select(p => GetAllArguments(dataGeneratorMetadata, p)))) { - if (exclusions.Any(e => IsExcluded(e, row))) + var rowArray = row.ToArray(); + + if (exclusions.Any(e => IsExcluded(e, rowArray))) { continue; } - yield return () => row.ToArray(); + yield return () => rowArray; } } - private bool IsExcluded(object?[] exclusion, IEnumerable row) + private bool IsExcluded(object?[] exclusion, object?[] rowArray) { - var rowArray = row.ToArray(); if (exclusion.Length != rowArray.Length) { return false; diff --git a/TUnit.Core/Data/ThreadSafeDictionary.cs b/TUnit.Core/Data/ThreadSafeDictionary.cs index 96ea003d88..66e2aaa494 100644 --- a/TUnit.Core/Data/ThreadSafeDictionary.cs +++ b/TUnit.Core/Data/ThreadSafeDictionary.cs @@ -14,7 +14,7 @@ public class ThreadSafeDictionary Keys => _innerDictionary.Keys; - public IEnumerable Values => _innerDictionary.Values.Select(lazy => lazy.Value); + public IEnumerable Values => _innerDictionary.Values.Select(static lazy => lazy.Value); public TValue GetOrAdd(TKey key, Func func) { diff --git a/TUnit.Core/Helpers/ArgumentFormatter.cs b/TUnit.Core/Helpers/ArgumentFormatter.cs index a3629757ad..a0d8ac4ba0 100644 --- a/TUnit.Core/Helpers/ArgumentFormatter.cs +++ b/TUnit.Core/Helpers/ArgumentFormatter.cs @@ -25,16 +25,26 @@ public static string GetConstantValue(TestContext testContext, object? o) public static string FormatArguments(IEnumerable arguments) { - var list = arguments as IList ?? arguments.ToList(); - if (list.Count == 0) - return string.Empty; - - var formatted = new string[list.Count]; - for (int i = 0; i < list.Count; i++) + if (arguments is IList list) { - formatted[i] = FormatDefault(list[i]); + if (list.Count == 0) + return string.Empty; + + var formatted = new string[list.Count]; + for (int i = 0; i < list.Count; i++) + { + formatted[i] = FormatDefault(list[i]); + } + return string.Join(", ", formatted); } - return string.Join(", ", formatted); + + var elements = new List(); + foreach (var arg in arguments) + { + elements.Add(FormatDefault(arg)); + } + + return elements.Count == 0 ? string.Empty : string.Join(", ", elements); } private static string FormatDefault(object? o) diff --git a/TUnit.Core/Helpers/StringBuilderPool.cs b/TUnit.Core/Helpers/StringBuilderPool.cs new file mode 100644 index 0000000000..5974ba198a --- /dev/null +++ b/TUnit.Core/Helpers/StringBuilderPool.cs @@ -0,0 +1,40 @@ +using System.Collections.Concurrent; +using System.Text; + +namespace TUnit.Core.Helpers; + +/// +/// Provides a pool of StringBuilder instances to reduce allocations in hot paths. +/// +internal static class StringBuilderPool +{ + private const int MaxCapacity = 1024; + private static readonly ConcurrentBag Pool = []; + + /// + /// Gets a StringBuilder from the pool or creates a new one. + /// + public static StringBuilder Get() + { + if (Pool.TryTake(out var builder)) + { + return builder; + } + + return new StringBuilder(); + } + + /// + /// Returns a StringBuilder to the pool after clearing its contents. + /// + public static void Return(StringBuilder builder) + { + if (builder.Capacity > MaxCapacity) + { + return; + } + + builder.Clear(); + Pool.Add(builder); + } +} diff --git a/TUnit.Core/TestContext.cs b/TUnit.Core/TestContext.cs index 2ecf39146a..4259e7d077 100644 --- a/TUnit.Core/TestContext.cs +++ b/TUnit.Core/TestContext.cs @@ -37,9 +37,9 @@ public TestContext(string testName, IServiceProvider serviceProvider, ClassHookC internal static readonly Dictionary> InternalParametersDictionary = new(); - private readonly StringWriter _outputWriter = new(); + private StringWriter? _outputWriter; - private readonly StringWriter _errorWriter = new(); + private StringWriter? _errorWriter; public static new TestContext? Current { @@ -168,17 +168,19 @@ internal IServiceProvider ServiceProvider public void WriteLine(string message) { + _outputWriter ??= new StringWriter(); _outputWriter.WriteLine(message); } public void WriteError(string message) { + _errorWriter ??= new StringWriter(); _errorWriter.WriteLine(message); } - public string GetOutput() => _outputWriter.ToString(); + public string GetOutput() => _outputWriter?.ToString() ?? string.Empty; - public new string GetErrorOutput() => _errorWriter.ToString(); + public new string GetErrorOutput() => _errorWriter?.ToString() ?? string.Empty; public T? GetService() where T : class { @@ -200,6 +202,8 @@ internal override void SetAsyncLocalContext() internal IClassConstructor? ClassConstructor => _testBuilderContext.ClassConstructor; + internal object[]? CachedEligibleEventObjects { get; set; } + public string GetDisplayName() { if(!string.IsNullOrEmpty(CustomDisplayName)) @@ -218,21 +222,30 @@ public string GetDisplayName() return TestName; } - var formattedArgs = new string[TestDetails.TestMethodArguments.Length]; - for (var i = 0; i < TestDetails.TestMethodArguments.Length; i++) + var argsLength = TestDetails.TestMethodArguments.Length; + var sb = StringBuilderPool.Get(); + try { - formattedArgs[i] = ArgumentFormatter.Format(TestDetails.TestMethodArguments[i], ArgumentDisplayFormatters); - } - var arguments = string.Join(", ", formattedArgs); + sb.Append(TestName); + sb.Append('('); + + for (var i = 0; i < argsLength; i++) + { + if (i > 0) + { + sb.Append(", "); + } + sb.Append(ArgumentFormatter.Format(TestDetails.TestMethodArguments[i], ArgumentDisplayFormatters)); + } - if (string.IsNullOrEmpty(arguments)) + sb.Append(')'); + _cachedDisplayName = sb.ToString(); + return _cachedDisplayName; + } + finally { - _cachedDisplayName = TestName; - return TestName; + StringBuilderPool.Return(sb); } - - _cachedDisplayName = $"{TestName}({arguments})"; - return _cachedDisplayName; } /// diff --git a/TUnit.Core/TestDetails.cs b/TUnit.Core/TestDetails.cs index e39b16704e..e1dbed6705 100644 --- a/TUnit.Core/TestDetails.cs +++ b/TUnit.Core/TestDetails.cs @@ -62,7 +62,7 @@ public bool HasAttribute() where T : Attribute public IEnumerable GetAttributes() where T : Attribute => AttributesByType.TryGetValue(typeof(T), out var attrs) ? attrs.OfType() - : Enumerable.Empty(); + : []; /// /// Gets all attributes as a flattened collection. diff --git a/TUnit.Core/TestMetadata.cs b/TUnit.Core/TestMetadata.cs index 9757ae0fb9..49cb6279ed 100644 --- a/TUnit.Core/TestMetadata.cs +++ b/TUnit.Core/TestMetadata.cs @@ -49,6 +49,13 @@ public abstract class TestMetadata public required Func AttributeFactory { get; init; } + /// + /// Pre-extracted repeat count from RepeatAttribute. + /// Null if no repeat attribute is present (defaults to 0 at usage site). + /// Pre-extracting this avoids instantiating all attributes just to read the repeat count. + /// + public int? RepeatCount { get; init; } + public PropertyInjectionData[] PropertyInjections { get; init; } = []; /// diff --git a/TUnit.Core/TestMetadata`1.cs b/TUnit.Core/TestMetadata`1.cs index e62943aaa0..c29cc86c20 100644 --- a/TUnit.Core/TestMetadata`1.cs +++ b/TUnit.Core/TestMetadata`1.cs @@ -52,7 +52,7 @@ public class TestMetadata< /// Strongly typed test invoker with CancellationToken support. /// Used by source generation mode. /// - public Func? InvokeTypedTest { get; init; } + public Func? InvokeTypedTest { get; init; } @@ -97,7 +97,7 @@ public override Func invokeTest = async (instance, args, testContext, cancellationToken) => { - await typedMetadata.InvokeTypedTest!((T)instance, args, cancellationToken); + await typedMetadata.InvokeTypedTest!((T)instance, args, cancellationToken).ConfigureAwait(false); }; return new ExecutableTest(createInstance, invokeTest) diff --git a/TUnit.Engine.Tests/DynamicTests.cs b/TUnit.Engine.Tests/DynamicTests.cs index 669372faa5..2260ea9a3d 100644 --- a/TUnit.Engine.Tests/DynamicTests.cs +++ b/TUnit.Engine.Tests/DynamicTests.cs @@ -12,8 +12,8 @@ await RunTestsWithFilter( "/*/*DynamicTests/*/*", [ result => result.ResultSummary.Outcome.ShouldBe("Completed"), - result => result.ResultSummary.Counters.Total.ShouldBeGreaterThanOrEqualTo(48), - result => result.ResultSummary.Counters.Passed.ShouldBeGreaterThanOrEqualTo(48), + result => result.ResultSummary.Counters.Total.ShouldBeGreaterThanOrEqualTo(13), + result => result.ResultSummary.Counters.Passed.ShouldBeGreaterThanOrEqualTo(13), result => result.ResultSummary.Counters.Failed.ShouldBe(0), result => result.ResultSummary.Counters.NotExecuted.ShouldBe(0) ]); diff --git a/TUnit.Engine/Building/TestBuilder.cs b/TUnit.Engine/Building/TestBuilder.cs index fa69e3c536..f5594e870d 100644 --- a/TUnit.Engine/Building/TestBuilder.cs +++ b/TUnit.Engine/Building/TestBuilder.cs @@ -124,7 +124,7 @@ public async Task> BuildTestsFromMetadataAsy if (!CouldTestMatchFilter(buildingContext.Filter, metadata)) { // This test class cannot match the filter - skip all expensive work! - return Array.Empty(); + return []; } } @@ -145,11 +145,11 @@ public async Task> BuildTestsFromMetadataAsy } + // Use pre-extracted repeat count from metadata (avoids instantiating attributes) + var repeatCount = metadata.RepeatCount ?? 0; + // Create and initialize attributes ONCE var attributes = await InitializeAttributesAsync(metadata.AttributeFactory.Invoke()); - var filteredAttributes = ScopedAttributeFilter.FilterScopedAttributes(attributes); - var repeatAttr = filteredAttributes.OfType().FirstOrDefault(); - var repeatCount = repeatAttr?.Times ?? 0; if (metadata.ClassDataSources.Any(ds => ds is IAccessesInstanceData)) { @@ -1277,11 +1277,11 @@ public async IAsyncEnumerable BuildTestsStreamingAsync( yield break; } - // Extract repeat count from attributes + // Use pre-extracted repeat count from metadata (avoids instantiating attributes) + var repeatCount = metadata.RepeatCount ?? 0; + + // Initialize attributes var attributes = await InitializeAttributesAsync(metadata.AttributeFactory.Invoke()); - var filteredAttributes = ScopedAttributeFilter.FilterScopedAttributes(attributes); - var repeatAttr = filteredAttributes.OfType().FirstOrDefault(); - var repeatCount = repeatAttr?.Times ?? 0; // Create base context with ClassConstructor if present var baseContext = new TestBuilderContext @@ -1517,7 +1517,7 @@ public async IAsyncEnumerable BuildTestsStreamingAsync( } // Create instance factory - var attributes = contextAccessor.Current.InitializedAttributes ?? Array.Empty(); + var attributes = contextAccessor.Current.InitializedAttributes ?? []; var basicSkipReason = GetBasicSkipReason(metadata, attributes); Func> instanceFactory; @@ -1664,7 +1664,7 @@ private static TreeNodeFilter CreateTreeNodeFilterViaReflection(string filterStr var constructor = typeof(TreeNodeFilter).GetConstructors( System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)[0]; - return (TreeNodeFilter)constructor.Invoke(new object[] { filterString }); + return (TreeNodeFilter)constructor.Invoke([filterString]); } #pragma warning restore TPEXP diff --git a/TUnit.Engine/Building/TestBuilderPipeline.cs b/TUnit.Engine/Building/TestBuilderPipeline.cs index 35bc732c91..021e0357e5 100644 --- a/TUnit.Engine/Building/TestBuilderPipeline.cs +++ b/TUnit.Engine/Building/TestBuilderPipeline.cs @@ -124,13 +124,8 @@ public async Task> BuildTestsFromMetadataAsy private async Task GenerateDynamicTests(TestMetadata metadata) { - // Get attributes first - var attributes = metadata.AttributeFactory() ?? []; - - // Extract repeat count from attributes - var filteredAttributes = ScopedAttributeFilter.FilterScopedAttributes(attributes); - var repeatAttr = filteredAttributes.OfType().FirstOrDefault(); - var repeatCount = repeatAttr?.Times ?? 0; + // Use pre-extracted repeat count from metadata (avoids instantiating attributes) + var repeatCount = metadata.RepeatCount ?? 0; return await Enumerable.Range(0, repeatCount + 1) .SelectAsync(async repeatIndex => @@ -247,13 +242,11 @@ private async IAsyncEnumerable BuildTestsFromSingleMetad [ ]; - // Get attributes first - var attributes = resolvedMetadata.AttributeFactory?.Invoke() ?? []; + // Use pre-extracted repeat count from metadata (avoids instantiating attributes) + var repeatCount = resolvedMetadata.RepeatCount ?? 0; - // Extract repeat count from attributes - var filteredAttributes = ScopedAttributeFilter.FilterScopedAttributes(attributes); - var repeatAttr = filteredAttributes.OfType().FirstOrDefault(); - var repeatCount = repeatAttr?.Times ?? 0; + // Get attributes for test details + var attributes = resolvedMetadata.AttributeFactory?.Invoke() ?? []; // Dynamic tests need to honor attributes like RepeatCount, RetryCount, etc. // We'll create multiple test instances based on RepeatCount diff --git a/TUnit.Engine/Discovery/ReflectionHookDiscoveryService.cs b/TUnit.Engine/Discovery/ReflectionHookDiscoveryService.cs index 2048aa8187..cc3954b121 100644 --- a/TUnit.Engine/Discovery/ReflectionHookDiscoveryService.cs +++ b/TUnit.Engine/Discovery/ReflectionHookDiscoveryService.cs @@ -21,6 +21,8 @@ internal sealed class ReflectionHookDiscoveryService private static readonly ConcurrentDictionary _scannedAssemblies = new(); private static readonly ConcurrentDictionary _registeredMethods = new(); private static readonly ConcurrentDictionary _methodKeyCache = new(); + // Cache attribute lookups to avoid repeated reflection calls in hot paths + private static readonly ConcurrentDictionary _attributeCache = new(); private static int _registrationIndex = 0; private static int _discoveryRunCount = 0; @@ -44,6 +46,21 @@ private static string GetMethodKey(MethodInfo method) }); } + /// + /// Get cached hook attributes for a method to avoid repeated GetCustomAttribute calls + /// + private static (BeforeAttribute?, AfterAttribute?, BeforeEveryAttribute?, AfterEveryAttribute?) GetCachedAttributes(MethodInfo method) + { + return _attributeCache.GetOrAdd(method, m => + { + var beforeAttr = m.GetCustomAttribute(); + var afterAttr = m.GetCustomAttribute(); + var beforeEveryAttr = m.GetCustomAttribute(); + var afterEveryAttr = m.GetCustomAttribute(); + return (beforeAttr, afterAttr, beforeEveryAttr, afterEveryAttr); + }); + } + private static void ClearSourceGeneratedHooks() { // Clear all hook collections to avoid duplicates when both @@ -94,9 +111,10 @@ public static void DiscoverInstanceHooksForType(Type closedGenericType) var current = closedGenericType; while (current != null && current != typeof(object)) { - inheritanceChain.Insert(0, current); // Insert at front to get base-to-derived order + inheritanceChain.Add(current); // Add to end current = current.BaseType; } + inheritanceChain.Reverse(); // Reverse once to get base-to-derived order (O(n) vs O(n²)) // Discover hooks in each type in the inheritance chain, from base to derived foreach (var typeInChain in inheritanceChain) @@ -104,11 +122,8 @@ public static void DiscoverInstanceHooksForType(Type closedGenericType) var methods = typeInChain.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly) .OrderBy(m => { - // Get the minimum order from all hook attributes on this method - var beforeAttr = m.GetCustomAttribute(); - var afterAttr = m.GetCustomAttribute(); - var beforeEveryAttr = m.GetCustomAttribute(); - var afterEveryAttr = m.GetCustomAttribute(); + // Get the minimum order from cached hook attributes + var (beforeAttr, afterAttr, beforeEveryAttr, afterEveryAttr) = GetCachedAttributes(m); var orders = new List(); if (beforeAttr != null) orders.Add(beforeAttr.Order); @@ -278,9 +293,10 @@ private static void DiscoverHooksInType([DynamicallyAccessedMembers(DynamicallyA Type? current = type; while (current != null && current != typeof(object)) { - inheritanceChain.Insert(0, current); // Insert at front to get base-to-derived order + inheritanceChain.Add(current); // Add to end current = current.BaseType; } + inheritanceChain.Reverse(); // Reverse once to get base-to-derived order (O(n) vs O(n²)) // Discover hooks in each type in the inheritance chain, from base to derived foreach (var typeInChain in inheritanceChain) @@ -289,11 +305,8 @@ private static void DiscoverHooksInType([DynamicallyAccessedMembers(DynamicallyA var methods = typeInChain.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly) .OrderBy(m => { - // Get the minimum order from all hook attributes on this method - var beforeAttr = m.GetCustomAttribute(); - var afterAttr = m.GetCustomAttribute(); - var beforeEveryAttr = m.GetCustomAttribute(); - var afterEveryAttr = m.GetCustomAttribute(); + // Get the minimum order from cached hook attributes + var (beforeAttr, afterAttr, beforeEveryAttr, afterEveryAttr) = GetCachedAttributes(m); var orders = new List(); if (beforeAttr != null) orders.Add(beforeAttr.Order); @@ -692,7 +705,7 @@ private static void RegisterInstanceBeforeHook( return; } - var bag = Sources.BeforeTestHooks.GetOrAdd(type, static _ => new ConcurrentBag()); + var bag = Sources.BeforeTestHooks.GetOrAdd(type, static _ => []); var hook = new InstanceHookMethod { InitClassType = type, @@ -717,7 +730,7 @@ private static void RegisterInstanceAfterHook( return; } - var bag = Sources.AfterTestHooks.GetOrAdd(type, static _ => new ConcurrentBag()); + var bag = Sources.AfterTestHooks.GetOrAdd(type, static _ => []); var hook = new InstanceHookMethod { InitClassType = type, @@ -736,7 +749,7 @@ private static void RegisterBeforeClassHook( MethodInfo method, int order) { - var bag = Sources.BeforeClassHooks.GetOrAdd(type, static _ => new ConcurrentBag()); + var bag = Sources.BeforeClassHooks.GetOrAdd(type, static _ => []); var hook = new BeforeClassHookMethod { MethodInfo = CreateMethodMetadata(type, method), @@ -756,7 +769,7 @@ private static void RegisterAfterClassHook( MethodInfo method, int order) { - var bag = Sources.AfterClassHooks.GetOrAdd(type, static _ => new ConcurrentBag()); + var bag = Sources.AfterClassHooks.GetOrAdd(type, static _ => []); var hook = new AfterClassHookMethod { MethodInfo = CreateMethodMetadata(type, method), @@ -777,7 +790,7 @@ private static void RegisterBeforeAssemblyHook( MethodInfo method, int order) { - var bag = Sources.BeforeAssemblyHooks.GetOrAdd(assembly, static _ => new ConcurrentBag()); + var bag = Sources.BeforeAssemblyHooks.GetOrAdd(assembly, static _ => []); var hook = new BeforeAssemblyHookMethod { MethodInfo = CreateMethodMetadata(type, method), @@ -798,7 +811,7 @@ private static void RegisterAfterAssemblyHook( MethodInfo method, int order) { - var bag = Sources.AfterAssemblyHooks.GetOrAdd(assembly, static _ => new ConcurrentBag()); + var bag = Sources.AfterAssemblyHooks.GetOrAdd(assembly, static _ => []); var hook = new AfterAssemblyHookMethod { MethodInfo = CreateMethodMetadata(type, method), diff --git a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs index dce151c07d..e0e541f163 100644 --- a/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs +++ b/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs @@ -345,7 +345,7 @@ private static async Task> DiscoverTestsInAssembly(Assembly a } catch (ReflectionTypeLoadException reflectionTypeLoadException) { - return reflectionTypeLoadException.Types.Where(x => x != null).ToArray()!; + return reflectionTypeLoadException.Types.Where(static x => x != null).ToArray()!; } catch (Exception) { @@ -358,7 +358,7 @@ private static async Task> DiscoverTestsInAssembly(Assembly a return discoveredTests; } - var filteredTypes = types.Where(t => t.IsClass && !IsCompilerGenerated(t)); + var filteredTypes = types.Where(static t => t.IsClass && !IsCompilerGenerated(t)); foreach (var type in filteredTypes) { @@ -487,7 +487,7 @@ private static async IAsyncEnumerable DiscoverTestsInAssemblyStrea yield break; } - var filteredTypes = types.Where(t => t.IsClass && !IsCompilerGenerated(t)); + var filteredTypes = types.Where(static t => t.IsClass && !IsCompilerGenerated(t)); foreach (var type in filteredTypes) { @@ -519,14 +519,14 @@ private static async IAsyncEnumerable DiscoverTestsInAssemblyStrea { // Get all test methods including inherited ones testMethods = GetAllTestMethods(type) - .Where(m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract) + .Where(static m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract) .ToArray(); } else { // Only get declared test methods testMethods = type.GetMethods(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly) - .Where(m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract) + .Where(static m => m.IsDefined(typeof(TestAttribute), inherit: false) && !m.IsAbstract) .ToArray(); } } @@ -753,7 +753,7 @@ private static async IAsyncEnumerable DiscoverGenericTestsStreamin $"Failed to create concrete type for {genericTypeDefinition.FullName ?? genericTypeDefinition.Name}. " + $"Error: {ex.Message}. " + $"Generic parameter count: {genericTypeDefinition.GetGenericArguments().Length}, " + - $"Type arguments: {string.Join(", ", typeArguments?.Select(t => t.Name) ?? [ + $"Type arguments: {string.Join(", ", typeArguments?.Select(static t => t.Name) ?? [ ])}", ex), $"[GENERIC TYPE CREATION FAILED] {genericTypeDefinition.Name}") { @@ -896,6 +896,8 @@ private static Task BuildTestMetadata( GenericMethodInfo = ReflectionGenericTypeResolver.ExtractGenericMethodInfo(testMethod), GenericMethodTypeArguments = testMethod.IsGenericMethodDefinition ? null : testMethod.GetGenericArguments(), AttributeFactory = () => ReflectionAttributeExtractor.GetAllAttributes(testClass, testMethod), + RepeatCount = testMethod.GetCustomAttribute()?.Times + ?? testClass.GetCustomAttribute()?.Times, PropertyInjections = PropertySourceRegistry.DiscoverInjectableProperties(testClass), InheritanceDepth = inheritanceDepth }); @@ -971,7 +973,7 @@ private static string GenerateTestName(Type testClass, MethodInfo testMethod) return (_, _) => Activator.CreateInstance(testClass)!; } - var constructedTypeCtor = constructedTypeConstructors.FirstOrDefault(c => c.GetParameters().Length == 0) ?? constructedTypeConstructors.First(); + var constructedTypeCtor = constructedTypeConstructors.FirstOrDefault(static c => c.GetParameters().Length == 0) ?? constructedTypeConstructors.First(); var constructedTypeFactory = CreateReflectionInstanceFactory(constructedTypeCtor); // Return a factory that ignores type arguments since the type is already closed @@ -985,7 +987,7 @@ private static string GenerateTestName(Type testClass, MethodInfo testMethod) return (_, _) => Activator.CreateInstance(testClass)!; } - var ctor = constructors.FirstOrDefault(c => c.GetParameters().Length == 0) ?? constructors.First(); + var ctor = constructors.FirstOrDefault(static c => c.GetParameters().Length == 0) ?? constructors.First(); var factory = CreateReflectionInstanceFactory(ctor); return (_, args) => factory(args); @@ -1056,7 +1058,7 @@ private static TestMetadata CreateFailedTestMetadataForAssembly(Assembly assembl LineNumber = 0, MethodMetadata = CreateDummyMethodMetadata(testClass, "AssemblyScanFailed"), - AttributeFactory = () => + AttributeFactory = static () => [ ], DataSources = @@ -1839,7 +1841,7 @@ private async IAsyncEnumerable ExecuteDynamicTestBuilderStreamingA builderMethod.Invoke(instance, [context]); // Retrieve the discovered tests - foreach (var discoveryResult in context.Tests.SelectMany(t => t.GetTests())) + foreach (var discoveryResult in context.Tests.SelectMany(static t => t.GetTests())) { cancellationToken.ThrowIfCancellationRequested(); @@ -1924,7 +1926,7 @@ private Task CreateMetadataFromDynamicDiscoveryResult(DynamicDisco TestName = testName, TestClassType = result.TestClassType, TestMethodName = methodInfo.Name, - Dependencies = result.Attributes.OfType().Select(a => a.ToTestDependency()).ToArray(), + Dependencies = result.Attributes.OfType().Select(static a => a.ToTestDependency()).ToArray(), DataSources = [], // Dynamic tests don't use data sources in the same way ClassDataSources = [], PropertyDataSources = [], @@ -2037,7 +2039,7 @@ private static TestMetadata CreateFailedTestMetadataForDynamicSource(IDynamicTes FilePath = "Unknown", LineNumber = 0, MethodMetadata = CreateDummyMethodMetadata(source.GetType(), "CollectDynamicTests"), - AttributeFactory = () => [], + AttributeFactory = static () => [], DataSources = [], ClassDataSources = [], PropertyDataSources = [] diff --git a/TUnit.Engine/Events/EventReceiverCache.cs b/TUnit.Engine/Events/EventReceiverCache.cs index 5b3bce2c4c..c8ff1ccac0 100644 --- a/TUnit.Engine/Events/EventReceiverCache.cs +++ b/TUnit.Engine/Events/EventReceiverCache.cs @@ -12,14 +12,14 @@ internal sealed class EventReceiverCache { public Type ReceiverType { get; init; } public Type TestClassType { get; init; } - + public bool Equals(CacheKey other) => - ReceiverType == other.ReceiverType && + ReceiverType == other.ReceiverType && TestClassType == other.TestClassType; - + public override bool Equals(object? obj) => obj is CacheKey other && Equals(other); - + public override int GetHashCode() { #if NETSTANDARD2_0 @@ -35,9 +35,10 @@ public override int GetHashCode() #endif } } - - private readonly ConcurrentDictionary _cache = new(); - + + // Use object to store typed caches (avoids boxing on retrieval) + private readonly ConcurrentDictionary _typedCaches = new(); + /// /// Get cached receivers or compute and cache them /// @@ -45,31 +46,13 @@ public T[] GetApplicableReceivers( Type testClassType, Func factory) where T : class, IEventReceiver { - var key = new CacheKey - { - ReceiverType = typeof(T), - TestClassType = testClassType - }; - - var cached = _cache.GetOrAdd(key, _ => - { - var receivers = factory(testClassType); - // Pre-size array and avoid LINQ Cast + ToArray - var array = new object[receivers.Length]; - for (var i = 0; i < receivers.Length; i++) - { - array[i] = receivers[i]; - } - return array; - }); - - // Cast back to specific type - var result = new T[cached.Length]; - for (var i = 0; i < cached.Length; i++) - { - result[i] = (T)cached[i]; - } - return result; + // Get or create typed cache for this receiver type + var typedCache = (ConcurrentDictionary)_typedCaches.GetOrAdd( + typeof(T), + static _ => new ConcurrentDictionary()); + + // Use typed cache - no boxing/unboxing needed + return typedCache.GetOrAdd(testClassType, factory); } /// @@ -77,22 +60,25 @@ public T[] GetApplicableReceivers( /// public void Clear() { - _cache.Clear(); + _typedCaches.Clear(); } - + /// /// Get cache statistics /// public (int EntryCount, long EstimatedSize) GetStatistics() { - var entryCount = _cache.Count; - var estimatedSize = entryCount * (16 + 8); // Rough estimate: key size + reference - - foreach (var kvp in _cache) + var entryCount = _typedCaches.Values.Sum(cache => { - estimatedSize += kvp.Value.Length * 8; // References - } - + if (cache is System.Collections.ICollection collection) + { + return collection.Count; + } + return 0; + }); + + var estimatedSize = entryCount * (16 + 8); // Rough estimate: key size + reference + return (entryCount, estimatedSize); } } \ No newline at end of file diff --git a/TUnit.Engine/Extensions/TestContextExtensions.cs b/TUnit.Engine/Extensions/TestContextExtensions.cs index 2f5812b8b3..c7fe2d3dcb 100644 --- a/TUnit.Engine/Extensions/TestContextExtensions.cs +++ b/TUnit.Engine/Extensions/TestContextExtensions.cs @@ -17,6 +17,15 @@ internal static class TestContextExtensions public static IEnumerable GetEligibleEventObjects(this TestContext testContext) { - return GetInternal(testContext).OfType(); + // Return cached result if available + if (testContext.CachedEligibleEventObjects != null) + { + return testContext.CachedEligibleEventObjects; + } + + // Materialize and cache the result + var result = GetInternal(testContext).OfType().ToArray(); + testContext.CachedEligibleEventObjects = result; + return result; } } diff --git a/TUnit.Engine/Framework/TUnitServiceProvider.cs b/TUnit.Engine/Framework/TUnitServiceProvider.cs index 11e0547cab..9aa33afb52 100644 --- a/TUnit.Engine/Framework/TUnitServiceProvider.cs +++ b/TUnit.Engine/Framework/TUnitServiceProvider.cs @@ -149,6 +149,7 @@ public TUnitServiceProvider(IExtension extension, var testStateManager = Register(new TestStateManager()); var testContextRestorer = Register(new TestContextRestorer()); var testMethodInvoker = Register(new TestMethodInvoker()); + var hashSetPool = Register(new HashSetPool()); // Use the mode already determined earlier ITestDataCollector dataCollector; @@ -193,7 +194,8 @@ public TUnitServiceProvider(IExtension extension, testInitializer, objectTracker, Logger, - EventReceiverOrchestrator)); + EventReceiverOrchestrator, + hashSetPool)); // Create the HookOrchestratingTestExecutorAdapter // Note: We'll need to update this to handle dynamic dependencies properly diff --git a/TUnit.Engine/Helpers/AssemblyReferenceCache.cs b/TUnit.Engine/Helpers/AssemblyReferenceCache.cs index b03b944abb..9241c6d890 100644 --- a/TUnit.Engine/Helpers/AssemblyReferenceCache.cs +++ b/TUnit.Engine/Helpers/AssemblyReferenceCache.cs @@ -14,7 +14,7 @@ internal static class AssemblyReferenceCache #endif public static AssemblyName[] GetReferencedAssemblies(Assembly assembly) { - return _assemblyCache.GetOrAdd(assembly, a => a.GetReferencedAssemblies()); + return _assemblyCache.GetOrAdd(assembly, static a => a.GetReferencedAssemblies()); } #if NET6_0_OR_GREATER @@ -22,6 +22,6 @@ public static AssemblyName[] GetReferencedAssemblies(Assembly assembly) #endif public static Type[] GetInterfaces(Type type) { - return _interfaceCache.GetOrAdd(type, t => t.GetInterfaces()); + return _interfaceCache.GetOrAdd(type, static t => t.GetInterfaces()); } } diff --git a/TUnit.Engine/Services/EventReceiverOrchestrator.cs b/TUnit.Engine/Services/EventReceiverOrchestrator.cs index 37354a5252..c09da0b98a 100644 --- a/TUnit.Engine/Services/EventReceiverOrchestrator.cs +++ b/TUnit.Engine/Services/EventReceiverOrchestrator.cs @@ -422,23 +422,13 @@ public void InitializeTestCounts(IEnumerable allTestContexts) foreach (var group in contexts.GroupBy(c => c.ClassContext.AssemblyContext.Assembly.GetName().FullName)) { var counter = _assemblyTestCounts.GetOrAdd(group.Key, static _ => new Counter()); - var groupCount = group.Count(); - - for (var i = 0; i < groupCount; i++) - { - counter.Increment(); - } + counter.Add(group.Count()); } foreach (var group in contexts.GroupBy(c => c.ClassContext.ClassType)) { var counter = _classTestCounts.GetOrAdd(group.Key, static _ => new Counter()); - var groupCount = group.Count(); - - for (var i = 0; i < groupCount; i++) - { - counter.Increment(); - } + counter.Add(group.Count()); } } diff --git a/TUnit.Engine/Services/HookCollectionService.cs b/TUnit.Engine/Services/HookCollectionService.cs index 539f110929..eec9d45b23 100644 --- a/TUnit.Engine/Services/HookCollectionService.cs +++ b/TUnit.Engine/Services/HookCollectionService.cs @@ -17,6 +17,9 @@ internal sealed class HookCollectionService : IHookCollectionService private readonly ConcurrentDictionary>> _beforeAssemblyHooksCache = new(); private readonly ConcurrentDictionary>> _afterAssemblyHooksCache = new(); + // Cache for GetGenericTypeDefinition() calls to avoid repeated reflection + private static readonly ConcurrentDictionary _genericTypeDefinitionCache = new(); + // Pre-computed global hooks (computed once at initialization) private IReadOnlyList>? _beforeEveryTestHooks; private IReadOnlyList>? _afterEveryTestHooks; @@ -37,6 +40,11 @@ public HookCollectionService(EventReceiverOrchestrator eventReceiverOrchestrator _eventReceiverOrchestrator = eventReceiverOrchestrator; } + private static Type GetCachedGenericTypeDefinition(Type type) + { + return _genericTypeDefinitionCache.GetOrAdd(type, t => t.GetGenericTypeDefinition()); + } + public async ValueTask InitializeAsync() { // Pre-compute all global hooks that don't depend on specific types/assemblies @@ -305,7 +313,7 @@ private async Task>> Bu // Also check the open generic type definition for generic types if (currentType is { IsGenericType: true, IsGenericTypeDefinition: false }) { - var openGenericType = currentType.GetGenericTypeDefinition(); + var openGenericType = GetCachedGenericTypeDefinition(currentType); if (Sources.BeforeTestHooks.TryGetValue(openGenericType, out var openTypeHooks)) { foreach (var hook in openTypeHooks) @@ -372,7 +380,7 @@ private async Task>> Bu // Also check the open generic type definition for generic types if (currentType is { IsGenericType: true, IsGenericTypeDefinition: false }) { - var openGenericType = currentType.GetGenericTypeDefinition(); + var openGenericType = GetCachedGenericTypeDefinition(currentType); if (Sources.AfterTestHooks.TryGetValue(openGenericType, out var openTypeHooks)) { foreach (var hook in openTypeHooks) @@ -438,7 +446,7 @@ public ValueTask>> // Also check the open generic type definition for generic types if (currentType is { IsGenericType: true, IsGenericTypeDefinition: false }) { - var openGenericType = currentType.GetGenericTypeDefinition(); + var openGenericType = GetCachedGenericTypeDefinition(currentType); if (Sources.BeforeClassHooks.TryGetValue(openGenericType, out var openTypeHooks)) { foreach (var hook in openTypeHooks) @@ -495,7 +503,7 @@ public ValueTask>> // Also check the open generic type definition for generic types if (currentType is { IsGenericType: true, IsGenericTypeDefinition: false }) { - var openGenericType = currentType.GetGenericTypeDefinition(); + var openGenericType = GetCachedGenericTypeDefinition(currentType); if (Sources.AfterClassHooks.TryGetValue(openGenericType, out var openTypeHooks)) { foreach (var hook in openTypeHooks) diff --git a/TUnit.Engine/Services/PropertyInitializationPipeline.cs b/TUnit.Engine/Services/PropertyInitializationPipeline.cs index f301f3ed05..3c56e7e56c 100644 --- a/TUnit.Engine/Services/PropertyInitializationPipeline.cs +++ b/TUnit.Engine/Services/PropertyInitializationPipeline.cs @@ -17,15 +17,15 @@ internal sealed class PropertyInitializationPipeline public PropertyInitializationPipeline(DataSourceInitializer dataSourceInitializer, ObjectRegistrationService objectRegistrationService) { _dataSourceInitializer = dataSourceInitializer ?? throw new ArgumentNullException(nameof(dataSourceInitializer)); - _strategies = new List - { + _strategies = + [ new SourceGeneratedPropertyStrategy(dataSourceInitializer, objectRegistrationService), new ReflectionPropertyStrategy(dataSourceInitializer, objectRegistrationService), new NestedPropertyStrategy(dataSourceInitializer, objectRegistrationService) - }; + ]; - _beforeSteps = new List>(); - _afterSteps = new List>(); + _beforeSteps = []; + _afterSteps = []; } /// diff --git a/TUnit.Engine/Services/TestExecution/HashSetPool.cs b/TUnit.Engine/Services/TestExecution/HashSetPool.cs new file mode 100644 index 0000000000..dba17daaf6 --- /dev/null +++ b/TUnit.Engine/Services/TestExecution/HashSetPool.cs @@ -0,0 +1,55 @@ +namespace TUnit.Engine.Services.TestExecution; + +/// +/// Thread-safe object pool for HashSet instances used during test execution. +/// Single Responsibility: Managing pooled HashSet objects to reduce allocations. +/// +internal sealed class HashSetPool +{ + private readonly Dictionary _pools = new(); + private readonly object _lock = new(); + + public HashSet Rent() + { + var type = typeof(T); + + lock (_lock) + { + if (!_pools.TryGetValue(type, out var poolObj)) + { + poolObj = new Stack>(); + _pools[type] = poolObj; + } + + var pool = (Stack>)poolObj; + + if (pool.Count > 0) + { + var set = pool.Pop(); + set.Clear(); + return set; + } + } + + return []; + } + + public void Return(HashSet set) + { + var type = typeof(T); + + lock (_lock) + { + set.Clear(); + + if (!_pools.TryGetValue(type, out var poolObj)) + { + poolObj = new Stack>(); + _pools[type] = poolObj; + } + + var pool = (Stack>)poolObj; + pool.Push(set); + } + } +} diff --git a/TUnit.Engine/Services/TestExecution/TestCoordinator.cs b/TUnit.Engine/Services/TestExecution/TestCoordinator.cs index 308c91be75..928649a003 100644 --- a/TUnit.Engine/Services/TestExecution/TestCoordinator.cs +++ b/TUnit.Engine/Services/TestExecution/TestCoordinator.cs @@ -23,6 +23,7 @@ internal sealed class TestCoordinator : ITestCoordinator private readonly ObjectTracker _objectTracker; private readonly TUnitFrameworkLogger _logger; private readonly EventReceiverOrchestrator _eventReceiverOrchestrator; + private readonly HashSetPool _hashSetPool; public TestCoordinator( TestExecutionGuard executionGuard, @@ -33,7 +34,8 @@ public TestCoordinator( TestInitializer testInitializer, ObjectTracker objectTracker, TUnitFrameworkLogger logger, - EventReceiverOrchestrator eventReceiverOrchestrator) + EventReceiverOrchestrator eventReceiverOrchestrator, + HashSetPool hashSetPool) { _executionGuard = executionGuard; _stateManager = stateManager; @@ -44,6 +46,7 @@ public TestCoordinator( _objectTracker = objectTracker; _logger = logger; _eventReceiverOrchestrator = eventReceiverOrchestrator; + _hashSetPool = hashSetPool; } public async Task ExecuteTestAsync(AbstractExecutableTest test, CancellationToken cancellationToken) @@ -68,12 +71,21 @@ private async Task ExecuteTestInternalAsync(AbstractExecutableTest test, Cancell TestContext.Current = test.Context; - var allDependencies = new HashSet(); - CollectAllDependencies(test, allDependencies, new HashSet()); + var allDependencies = _hashSetPool.Rent(); + var visited = _hashSetPool.Rent(); + try + { + CollectAllDependencies(test, allDependencies, visited); - foreach (var dependency in allDependencies) + foreach (var dependency in allDependencies) + { + test.Context.Dependencies.Add(dependency); + } + } + finally { - test.Context.Dependencies.Add(dependency); + _hashSetPool.Return(allDependencies); + _hashSetPool.Return(visited); } // Ensure TestSession hooks run before creating test instances @@ -84,6 +96,9 @@ await RetryHelper.ExecuteWithRetry(test.Context, async () => { test.Context.TestDetails.ClassInstance = await test.CreateInstanceAsync(); + // Invalidate cached eligible event objects since ClassInstance changed + test.Context.CachedEligibleEventObjects = null; + // Check if this test should be skipped (after creating instance) if (test.Context.TestDetails.ClassInstance is SkippedTestInstance || !string.IsNullOrEmpty(test.Context.SkipReason)) diff --git a/TUnit.Engine/Services/TestExecution/TestStateManager.cs b/TUnit.Engine/Services/TestExecution/TestStateManager.cs index 3cf458ef3e..31ad555a33 100644 --- a/TUnit.Engine/Services/TestExecution/TestStateManager.cs +++ b/TUnit.Engine/Services/TestExecution/TestStateManager.cs @@ -18,18 +18,20 @@ public Task MarkRunningAsync(AbstractExecutableTest test) public Task MarkCompletedAsync(AbstractExecutableTest test) { + var now = DateTimeOffset.UtcNow; + test.Result ??= new TestResult { State = TestState.Passed, Start = test.StartTime, - End = DateTimeOffset.UtcNow, - Duration = DateTimeOffset.UtcNow - test.StartTime.GetValueOrDefault(), + End = now, + Duration = now - test.StartTime.GetValueOrDefault(), Exception = null, ComputerName = Environment.MachineName }; test.State = test.Result.State; - test.EndTime = DateTimeOffset.UtcNow; + test.EndTime = now; return Task.CompletedTask; } @@ -63,14 +65,15 @@ public Task MarkFailedAsync(AbstractExecutableTest test, Exception exception) public Task MarkSkippedAsync(AbstractExecutableTest test, string reason) { test.State = TestState.Skipped; + var now = DateTimeOffset.UtcNow; // Ensure StartTime is set if it wasn't already if (!test.StartTime.HasValue) { - test.StartTime = DateTimeOffset.UtcNow; + test.StartTime = now; } - test.EndTime = DateTimeOffset.UtcNow; + test.EndTime = now; test.Result = new TestResult { State = TestState.Skipped, diff --git a/TUnit.Engine/Services/TestFilterService.cs b/TUnit.Engine/Services/TestFilterService.cs index d73cb5c86e..af261cd7e9 100644 --- a/TUnit.Engine/Services/TestFilterService.cs +++ b/TUnit.Engine/Services/TestFilterService.cs @@ -23,8 +23,10 @@ public IReadOnlyCollection FilterTests(ITestExecutionFil logger.LogTrace($"Test filter is: {testExecutionFilter.GetType().Name}"); - var filteredTests = new List(); - var filteredExplicitTests = new List(); + // Pre-allocate capacity to avoid resizing during filtering + var capacity = testNodes is ICollection col ? col.Count : 16; + var filteredTests = new List(capacity); + var filteredExplicitTests = new List(capacity / 4); // Estimate ~25% explicit tests foreach (var test in testNodes) { @@ -124,6 +126,12 @@ public bool MatchesTest(ITestExecutionFilter? testExecutionFilter, AbstractExecu private string BuildPath(AbstractExecutableTest test) { + // Return cached path if available + if (test.CachedFilterPath != null) + { + return test.CachedFilterPath; + } + var metadata = test.Metadata; var classMetadata = test.Context.TestDetails.MethodMetadata.Class; @@ -133,6 +141,8 @@ private string BuildPath(AbstractExecutableTest test) var path = $"/{assemblyName}/{namespaceName}/{classTypeName}/{metadata.TestMethodName}"; + // Cache the path for future calls + test.CachedFilterPath = path; return path; } @@ -165,7 +175,16 @@ private bool UnhandledFilter(ITestExecutionFilter testExecutionFilter) private PropertyBag BuildPropertyBag(AbstractExecutableTest test) { - var properties = new List(); + // Return cached PropertyBag if available + if (test.CachedPropertyBag is PropertyBag cachedBag) + { + return cachedBag; + } + + // Pre-calculate capacity: 2 properties per category + custom properties + var categoryCount = test.Context.TestDetails.Categories.Count; + var customPropCount = test.Context.TestDetails.CustomProperties.Sum(p => p.Value.Count); + var properties = new List(categoryCount * 2 + customPropCount); foreach (var category in test.Context.TestDetails.Categories) { @@ -173,12 +192,21 @@ private PropertyBag BuildPropertyBag(AbstractExecutableTest test) properties.Add(new TestMetadataProperty("Category", category)); } + // Replace LINQ with manual loop for better performance in hot path foreach (var propertyEntry in test.Context.TestDetails.CustomProperties) { - properties.AddRange(propertyEntry.Value.Select(value => new TestMetadataProperty(propertyEntry.Key, value))); + foreach (var value in propertyEntry.Value) + { + properties.Add(new TestMetadataProperty(propertyEntry.Key, value)); + } } - return new PropertyBag(properties); + var propertyBag = new PropertyBag(properties); + + // Cache the PropertyBag for future calls + test.CachedPropertyBag = propertyBag; + + return propertyBag; } private bool IsExplicitTest(AbstractExecutableTest test) @@ -194,7 +222,9 @@ private bool IsExplicitTest(AbstractExecutableTest test) private IReadOnlyCollection FilterOutExplicitTests(IReadOnlyCollection testNodes) { - var filteredTests = new List(); + // Pre-allocate assuming most tests are not explicit + var capacity = testNodes is ICollection col ? col.Count : testNodes.Count; + var filteredTests = new List(capacity); foreach (var test in testNodes) { diff --git a/TUnit.Engine/Services/TestFinder.cs b/TUnit.Engine/Services/TestFinder.cs index 8d88c87949..74a1690e14 100644 --- a/TUnit.Engine/Services/TestFinder.cs +++ b/TUnit.Engine/Services/TestFinder.cs @@ -9,6 +9,8 @@ namespace TUnit.Engine.Services; internal class TestFinder : ITestFinder { private readonly TestDiscoveryService _discoveryService; + private Dictionary>? _testsByType; + private Dictionary<(Type ClassType, string TestName), List>? _testsByTypeAndName; public TestFinder(TestDiscoveryService discoveryService) { @@ -16,18 +18,64 @@ public TestFinder(TestDiscoveryService discoveryService) } /// - /// Gets all test contexts for the specified class type + /// Builds index dictionaries from cached tests for O(1) lookups /// - public IEnumerable GetTests(Type classType) + private void EnsureIndexesBuilt() { + if (_testsByType != null) + { + return; // Already built + } + var allTests = _discoveryService.GetCachedTestContexts(); + var testsByType = new Dictionary>(); + var testsByTypeAndName = new Dictionary<(Type, string), List>(); + foreach (var test in allTests) { - if (test.TestDetails?.ClassType == classType) + if (test.TestDetails?.ClassType == null) { - yield return test; + continue; } + + var classType = test.TestDetails.ClassType; + var testName = test.TestName; + + // Index by type + if (!testsByType.TryGetValue(classType, out var testsForType)) + { + testsForType = []; + testsByType[classType] = testsForType; + } + testsForType.Add(test); + + // Index by (type, name) + var key = (classType, testName); + if (!testsByTypeAndName.TryGetValue(key, out var testsForKey)) + { + testsForKey = []; + testsByTypeAndName[key] = testsForKey; + } + testsForKey.Add(test); } + + _testsByType = testsByType; + _testsByTypeAndName = testsByTypeAndName; + } + + /// + /// Gets all test contexts for the specified class type + /// + public IEnumerable GetTests(Type classType) + { + EnsureIndexesBuilt(); + + if (_testsByType!.TryGetValue(classType, out var tests)) + { + return tests; + } + + return []; } /// @@ -36,34 +84,29 @@ public IEnumerable GetTests(Type classType) public TestContext[] GetTestsByNameAndParameters(string testName, IEnumerable? methodParameterTypes, Type classType, IEnumerable? classParameterTypes, IEnumerable? classArguments) { + EnsureIndexesBuilt(); + var paramTypes = methodParameterTypes as Type[] ?? methodParameterTypes?.ToArray() ?? []; var classParamTypes = classParameterTypes as Type[] ?? classParameterTypes?.ToArray() ?? []; - var allTests = _discoveryService.GetCachedTestContexts(); - var results = new List(); + // Use the (type, name) index for O(1) lookup instead of O(n) scan + var key = (classType, testName); + if (!_testsByTypeAndName!.TryGetValue(key, out var candidateTests)) + { + return []; + } - // If no parameter types are specified, match by name and class type only + // If no parameter types are specified, return all matches if (paramTypes.Length == 0 && classParamTypes.Length == 0) { - foreach (var test in allTests) - { - if (test.TestName == testName && test.TestDetails?.ClassType == classType) - { - results.Add(test); - } - } - return results.ToArray(); + return candidateTests.ToArray(); } - // Match with parameter types - foreach (var test in allTests) + // Filter by parameter types + var results = new List(candidateTests.Count); + foreach (var test in candidateTests) { - if (test.TestName != testName || test.TestDetails?.ClassType != classType) - { - continue; - } - - var testParams = test.TestDetails.MethodMetadata.Parameters; + var testParams = test.TestDetails!.MethodMetadata.Parameters; var testParamTypes = new Type[testParams.Length]; for (int i = 0; i < testParams.Length; i++) { diff --git a/TUnit.Engine/Services/TestGroupingService.cs b/TUnit.Engine/Services/TestGroupingService.cs index a72db5bfe9..21eb1c045a 100644 --- a/TUnit.Engine/Services/TestGroupingService.cs +++ b/TUnit.Engine/Services/TestGroupingService.cs @@ -260,7 +260,7 @@ private static void ProcessCombinedConstraints( { if (!constrainedGroups.TryGetValue(parallelGroup.Group, out var group)) { - group = (new List(), new List<(AbstractExecutableTest, string, IReadOnlyList, TestPriority)>()); + group = ([], []); constrainedGroups[parallelGroup.Group] = group; } diff --git a/TUnit.Pipeline/Modules/Abstract/TestBaseModule.cs b/TUnit.Pipeline/Modules/Abstract/TestBaseModule.cs index 772662e9b8..0943197e35 100644 --- a/TUnit.Pipeline/Modules/Abstract/TestBaseModule.cs +++ b/TUnit.Pipeline/Modules/Abstract/TestBaseModule.cs @@ -45,8 +45,6 @@ protected virtual IEnumerable TestableFrameworks private DotNetRunOptions SetDefaults(DotNetRunOptions testOptions) { - // Removed --fail-fast to allow all tests to run even if some fail - if (testOptions.EnvironmentVariables?.Any(x => x.Key == "NET_VERSION") != true) { testOptions = testOptions with diff --git a/TUnit.Pipeline/Modules/RunEngineTestsModule.cs b/TUnit.Pipeline/Modules/RunEngineTestsModule.cs index b21eb0f597..162ccaf06e 100644 --- a/TUnit.Pipeline/Modules/RunEngineTestsModule.cs +++ b/TUnit.Pipeline/Modules/RunEngineTestsModule.cs @@ -38,7 +38,6 @@ public class RunEngineTestsModule : Module Arguments = [ "--hangdump", "--hangdump-filename", $"hangdump.{Environment.OSVersion.Platform}.engine-tests.dmp", "--hangdump-timeout", "30m", "--timeout", "35m", - "--fail-fast" ], EnvironmentVariables = new Dictionary { diff --git a/TUnit.Pipeline/Modules/RunPublicAPITestsModule.cs b/TUnit.Pipeline/Modules/RunPublicAPITestsModule.cs index 2e07663e63..683be1a71c 100644 --- a/TUnit.Pipeline/Modules/RunPublicAPITestsModule.cs +++ b/TUnit.Pipeline/Modules/RunPublicAPITestsModule.cs @@ -25,7 +25,6 @@ protected override Task GetTestOptions(IPipelineContext contex ["DISABLE_GITHUB_REPORTER"] = "true", ["GITHUB_ACTIONS"] = "false", }, - Arguments = ["--fail-fast"] }); } } diff --git a/TUnit.Pipeline/Modules/RunSourceGeneratorTestsModule.cs b/TUnit.Pipeline/Modules/RunSourceGeneratorTestsModule.cs index 452cbd8c98..5eb29f0e14 100644 --- a/TUnit.Pipeline/Modules/RunSourceGeneratorTestsModule.cs +++ b/TUnit.Pipeline/Modules/RunSourceGeneratorTestsModule.cs @@ -24,7 +24,6 @@ protected override Task GetTestOptions(IPipelineContext contex { ["DISABLE_GITHUB_REPORTER"] = "true", }, - Arguments = ["--", "--fail-fast"] }); } } diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt index f242e4115c..fa73df8d0f 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet10_0.verified.txt @@ -1100,14 +1100,6 @@ namespace .Conditions protected override string GetExpectation() { } public . Using(. comparer) { } } - [.("IsIn")] - public class IsInAssertion : . - { - public IsInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } [.("IsNotAssignableTo")] public class IsNotAssignableToAssertion : . { @@ -1139,14 +1131,6 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } - [.("IsNotIn")] - public class IsNotInAssertion : . - { - public IsNotInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } public class IsTypeOfRuntimeAssertion : . { public IsTypeOfRuntimeAssertion(. context, expectedType) { } @@ -1996,7 +1980,6 @@ namespace .Extensions public static . IsEqualTo(this . source, string? expected, comparison, [.("expected")] string? expression = null) { } [.("Uses reflection to compare members")] public static . IsEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsIn(this . source, params TValue[] collection) { } public static . IsNegative(this . source) where TValue : { } public static . IsNegative(this . source) @@ -2006,7 +1989,6 @@ namespace .Extensions where TEnum : struct, { } [.("Uses reflection to compare members")] public static . IsNotEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsNotIn(this . source, params TValue[] collection) { } public static . IsNotNull(this . source) where TValue : class { } public static . IsNotNull(this . source) @@ -2043,7 +2025,7 @@ namespace .Extensions [.(3)] public static . Member(this . source, .<>> memberSelector, <.<., TKey, TValue>, .> assertions) { } public static . Satisfies(this . source, predicate, [.("predicate")] string? expression = null) { } - public static . Satisfies(this . source, > selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } + public static . Satisfies(this . source, > selector, <., .> assertions, [.("selector")] string? selectorExpression = null) { } public static . Satisfies(this . source, selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } public static . Throws(this . source) where TException : { } @@ -3126,6 +3108,21 @@ namespace .Extensions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + public static class GenericAssertions + { + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn__Assertion IsIn(this . source, params T[] collection) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn_IEnumerableT_Assertion IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn_IEnumerableT_IEqualityComparerT_Assertion IsIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn__Assertion IsNotIn(this . source, params T[] collection) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn_IEnumerableT_Assertion IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion IsNotIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + } public static class GreaterThanAssertionExtensions { public static . IsGreaterThan(this . source, TValue minimum, [.("minimum")] string? minimumExpression = null) @@ -3345,10 +3342,6 @@ namespace .Extensions public static . IsEquivalentTo(this . source, . expected, . comparer, . ordering = 0, [.("expected")] string? expectedExpression = null, [.("comparer")] string? comparerExpression = null, [.("ordering")] string? orderingExpression = null) where TCollection : . { } } - public static class IsInAssertionExtensions - { - public static . IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class IsNotAssignableToAssertionExtensions { public static . IsNotAssignableTo(this . source) { } @@ -3368,10 +3361,6 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : class { } } - public static class IsNotInAssertionExtensions - { - public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class LazyAssertionExtensions { [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] @@ -3804,6 +3793,48 @@ namespace .Extensions public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn_IEnumerableT_Assertion : . + { + public T_IsIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn__Assertion : . + { + public T_IsIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn_IEnumerableT_Assertion : . + { + public T_IsNotIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn__Assertion : . + { + public T_IsNotIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class TaskAssertionExtensions { public static . IsCanceled(this . source) diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt index 8ab7682f97..74d83c96fd 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet8_0.verified.txt @@ -1097,14 +1097,6 @@ namespace .Conditions protected override string GetExpectation() { } public . Using(. comparer) { } } - [.("IsIn")] - public class IsInAssertion : . - { - public IsInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } [.("IsNotAssignableTo")] public class IsNotAssignableToAssertion : . { @@ -1136,14 +1128,6 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } - [.("IsNotIn")] - public class IsNotInAssertion : . - { - public IsNotInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } public class IsTypeOfRuntimeAssertion : . { public IsTypeOfRuntimeAssertion(. context, expectedType) { } @@ -1993,7 +1977,6 @@ namespace .Extensions public static . IsEqualTo(this . source, string? expected, comparison, [.("expected")] string? expression = null) { } [.("Uses reflection to compare members")] public static . IsEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsIn(this . source, params TValue[] collection) { } public static . IsNegative(this . source) where TValue : { } public static . IsNegative(this . source) @@ -2003,7 +1986,6 @@ namespace .Extensions where TEnum : struct, { } [.("Uses reflection to compare members")] public static . IsNotEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsNotIn(this . source, params TValue[] collection) { } public static . IsNotNull(this . source) where TValue : class { } public static . IsNotNull(this . source) @@ -2033,7 +2015,7 @@ namespace .Extensions public static . Member(this . source, .<> memberSelector, <., .> assertions) { } public static . Member(this . source, .<>> memberSelector, <.<., TKey, TValue>, .> assertions) { } public static . Satisfies(this . source, predicate, [.("predicate")] string? expression = null) { } - public static . Satisfies(this . source, > selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } + public static . Satisfies(this . source, > selector, <., .> assertions, [.("selector")] string? selectorExpression = null) { } public static . Satisfies(this . source, selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } public static . Throws(this . source) where TException : { } @@ -3110,6 +3092,21 @@ namespace .Extensions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + public static class GenericAssertions + { + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn__Assertion IsIn(this . source, params T[] collection) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn_IEnumerableT_Assertion IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn_IEnumerableT_IEqualityComparerT_Assertion IsIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn__Assertion IsNotIn(this . source, params T[] collection) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn_IEnumerableT_Assertion IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion IsNotIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + } public static class GreaterThanAssertionExtensions { public static . IsGreaterThan(this . source, TValue minimum, [.("minimum")] string? minimumExpression = null) @@ -3328,10 +3325,6 @@ namespace .Extensions public static . IsEquivalentTo(this . source, . expected, . comparer, . ordering = 0, [.("expected")] string? expectedExpression = null, [.("comparer")] string? comparerExpression = null, [.("ordering")] string? orderingExpression = null) where TCollection : . { } } - public static class IsInAssertionExtensions - { - public static . IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class IsNotAssignableToAssertionExtensions { public static . IsNotAssignableTo(this . source) { } @@ -3351,10 +3344,6 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : class { } } - public static class IsNotInAssertionExtensions - { - public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class LazyAssertionExtensions { [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] @@ -3785,6 +3774,48 @@ namespace .Extensions public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn_IEnumerableT_Assertion : . + { + public T_IsIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn__Assertion : . + { + public T_IsIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn_IEnumerableT_Assertion : . + { + public T_IsNotIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn__Assertion : . + { + public T_IsNotIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class TaskAssertionExtensions { public static . IsCanceled(this . source) diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt index 8435ae4c01..a13bbb36f9 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.DotNet9_0.verified.txt @@ -1100,14 +1100,6 @@ namespace .Conditions protected override string GetExpectation() { } public . Using(. comparer) { } } - [.("IsIn")] - public class IsInAssertion : . - { - public IsInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } [.("IsNotAssignableTo")] public class IsNotAssignableToAssertion : . { @@ -1139,14 +1131,6 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } - [.("IsNotIn")] - public class IsNotInAssertion : . - { - public IsNotInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } public class IsTypeOfRuntimeAssertion : . { public IsTypeOfRuntimeAssertion(. context, expectedType) { } @@ -1996,7 +1980,6 @@ namespace .Extensions public static . IsEqualTo(this . source, string? expected, comparison, [.("expected")] string? expression = null) { } [.("Uses reflection to compare members")] public static . IsEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsIn(this . source, params TValue[] collection) { } public static . IsNegative(this . source) where TValue : { } public static . IsNegative(this . source) @@ -2006,7 +1989,6 @@ namespace .Extensions where TEnum : struct, { } [.("Uses reflection to compare members")] public static . IsNotEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsNotIn(this . source, params TValue[] collection) { } public static . IsNotNull(this . source) where TValue : class { } public static . IsNotNull(this . source) @@ -2043,7 +2025,7 @@ namespace .Extensions [.(3)] public static . Member(this . source, .<>> memberSelector, <.<., TKey, TValue>, .> assertions) { } public static . Satisfies(this . source, predicate, [.("predicate")] string? expression = null) { } - public static . Satisfies(this . source, > selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } + public static . Satisfies(this . source, > selector, <., .> assertions, [.("selector")] string? selectorExpression = null) { } public static . Satisfies(this . source, selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } public static . Throws(this . source) where TException : { } @@ -3126,6 +3108,21 @@ namespace .Extensions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + public static class GenericAssertions + { + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn__Assertion IsIn(this . source, params T[] collection) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn_IEnumerableT_Assertion IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsIn_IEnumerableT_IEqualityComparerT_Assertion IsIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn__Assertion IsNotIn(this . source, params T[] collection) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn_IEnumerableT_Assertion IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public static .Extensions.T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion IsNotIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + } public static class GreaterThanAssertionExtensions { public static . IsGreaterThan(this . source, TValue minimum, [.("minimum")] string? minimumExpression = null) @@ -3345,10 +3342,6 @@ namespace .Extensions public static . IsEquivalentTo(this . source, . expected, . comparer, . ordering = 0, [.("expected")] string? expectedExpression = null, [.("comparer")] string? comparerExpression = null, [.("ordering")] string? orderingExpression = null) where TCollection : . { } } - public static class IsInAssertionExtensions - { - public static . IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class IsNotAssignableToAssertionExtensions { public static . IsNotAssignableTo(this . source) { } @@ -3368,10 +3361,6 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : class { } } - public static class IsNotInAssertionExtensions - { - public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class LazyAssertionExtensions { [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] @@ -3804,6 +3793,48 @@ namespace .Extensions public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn_IEnumerableT_Assertion : . + { + public T_IsIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsIn__Assertion : . + { + public T_IsIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn_IEnumerableT_Assertion : . + { + public T_IsNotIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + [.("Trimming", "IL2091", Justification="Generic type parameter is only used for property access, not instantiation")] + public sealed class T_IsNotIn__Assertion : . + { + public T_IsNotIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class TaskAssertionExtensions { public static . IsCanceled(this . source) diff --git a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt index 9ce8985843..499b883a65 100644 --- a/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt +++ b/TUnit.PublicAPI/Tests.Assertions_Library_Has_No_API_Changes.Net4_7.verified.txt @@ -1040,14 +1040,6 @@ namespace .Conditions protected override string GetExpectation() { } public . Using(. comparer) { } } - [.("IsIn")] - public class IsInAssertion : . - { - public IsInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } [.("IsNotAssignableTo")] public class IsNotAssignableToAssertion : . { @@ -1079,14 +1071,6 @@ namespace .Conditions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } - [.("IsNotIn")] - public class IsNotInAssertion : . - { - public IsNotInAssertion(. context, . collection) { } - protected override .<.> CheckAsync(. metadata) { } - protected override string GetExpectation() { } - public . Using(. comparer) { } - } public class IsTypeOfRuntimeAssertion : . { public IsTypeOfRuntimeAssertion(. context, expectedType) { } @@ -1824,7 +1808,6 @@ namespace .Extensions where TEnum : struct, { } public static . IsEqualTo(this . source, string? expected, comparison, [.("expected")] string? expression = null) { } public static . IsEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsIn(this . source, params TValue[] collection) { } public static . IsNegative(this . source) where TValue : { } public static . IsNegative(this . source) @@ -1833,7 +1816,6 @@ namespace .Extensions public static ..IsNotDefinedAssertion IsNotDefined(this . source) where TEnum : struct, { } public static . IsNotEquivalentTo(this . source, object? expected, [.("expected")] string? expression = null) { } - public static . IsNotIn(this . source, params TValue[] collection) { } public static . IsNotNull(this . source) where TValue : class { } public static . IsNotNull(this . source) @@ -1857,7 +1839,7 @@ namespace .Extensions public static . Member(this . source, .<> memberSelector, <., .> assertions) { } public static . Member(this . source, .<>> memberSelector, <.<., TKey, TValue>, .> assertions) { } public static . Satisfies(this . source, predicate, [.("predicate")] string? expression = null) { } - public static . Satisfies(this . source, > selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } + public static . Satisfies(this . source, > selector, <., .> assertions, [.("selector")] string? selectorExpression = null) { } public static . Satisfies(this . source, selector, <., .?> assertions, [.("selector")] string? selectorExpression = null) { } public static . Throws(this . source) where TException : { } @@ -2799,6 +2781,15 @@ namespace .Extensions protected override .<.> CheckAsync(. metadata) { } protected override string GetExpectation() { } } + public static class GenericAssertions + { + public static .Extensions.T_IsIn__Assertion IsIn(this . source, params T[] collection) { } + public static .Extensions.T_IsIn_IEnumerableT_Assertion IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + public static .Extensions.T_IsIn_IEnumerableT_IEqualityComparerT_Assertion IsIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + public static .Extensions.T_IsNotIn__Assertion IsNotIn(this . source, params T[] collection) { } + public static .Extensions.T_IsNotIn_IEnumerableT_Assertion IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } + public static .Extensions.T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion IsNotIn(this . source, . collection, . equalityComparer, [.("collection")] string? collectionExpression = null, [.("equalityComparer")] string? equalityComparerExpression = null) { } + } public static class GreaterThanAssertionExtensions { public static . IsGreaterThan(this . source, TValue minimum, [.("minimum")] string? minimumExpression = null) @@ -3000,10 +2991,6 @@ namespace .Extensions public static . IsEquivalentTo(this . source, . expected, . comparer, . ordering = 0, [.("expected")] string? expectedExpression = null, [.("comparer")] string? comparerExpression = null, [.("ordering")] string? orderingExpression = null) where TCollection : . { } } - public static class IsInAssertionExtensions - { - public static . IsIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class IsNotAssignableToAssertionExtensions { public static . IsNotAssignableTo(this . source) { } @@ -3023,10 +3010,6 @@ namespace .Extensions public static . IsNotDefault(this . source) where TValue : class { } } - public static class IsNotInAssertionExtensions - { - public static . IsNotIn(this . source, . collection, [.("collection")] string? collectionExpression = null) { } - } public static class LazyAssertionExtensions { public static ._IsValueCreated_Assertion IsValueCreated(this .<> source) { } @@ -3306,6 +3289,42 @@ namespace .Extensions public static . IsNullOrEmpty(this . source) { } public static . IsNullOrWhiteSpace(this . source) { } } + public sealed class T_IsIn_IEnumerableT_Assertion : . + { + public T_IsIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class T_IsIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class T_IsIn__Assertion : . + { + public T_IsIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class T_IsNotIn_IEnumerableT_Assertion : . + { + public T_IsNotIn_IEnumerableT_Assertion(. context, . collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion : . + { + public T_IsNotIn_IEnumerableT_IEqualityComparerT_Assertion(. context, . collection, . equalityComparer) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } + public sealed class T_IsNotIn__Assertion : . + { + public T_IsNotIn__Assertion(. context, T[] collection) { } + protected override .<.> CheckAsync(. metadata) { } + protected override string GetExpectation() { } + } public static class TaskAssertionExtensions { public static . IsCanceled(this . source) diff --git a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet10_0.verified.txt b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet10_0.verified.txt index 3232960360..c9501be01a 100644 --- a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet10_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet10_0.verified.txt @@ -1441,6 +1441,7 @@ namespace public required .MethodMetadata MethodMetadata { get; init; } public required .PropertyDataSource[] PropertyDataSources { get; init; } public .PropertyInjectionData[] PropertyInjections { get; init; } + public int? RepeatCount { get; init; } [.(..None | ..PublicParameterlessConstructor | ..PublicConstructors | ..PublicMethods | ..PublicProperties)] public required TestClassType { get; init; } public ? TestInvoker { get; init; } diff --git a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet8_0.verified.txt b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet8_0.verified.txt index 422794f37e..e7a230ce6d 100644 --- a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet8_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet8_0.verified.txt @@ -1441,6 +1441,7 @@ namespace public required .MethodMetadata MethodMetadata { get; init; } public required .PropertyDataSource[] PropertyDataSources { get; init; } public .PropertyInjectionData[] PropertyInjections { get; init; } + public int? RepeatCount { get; init; } [.(..None | ..PublicParameterlessConstructor | ..PublicConstructors | ..PublicMethods | ..PublicProperties)] public required TestClassType { get; init; } public ? TestInvoker { get; init; } diff --git a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet9_0.verified.txt b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet9_0.verified.txt index e0010fbf29..3db44143c6 100644 --- a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet9_0.verified.txt +++ b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.DotNet9_0.verified.txt @@ -1441,6 +1441,7 @@ namespace public required .MethodMetadata MethodMetadata { get; init; } public required .PropertyDataSource[] PropertyDataSources { get; init; } public .PropertyInjectionData[] PropertyInjections { get; init; } + public int? RepeatCount { get; init; } [.(..None | ..PublicParameterlessConstructor | ..PublicConstructors | ..PublicMethods | ..PublicProperties)] public required TestClassType { get; init; } public ? TestInvoker { get; init; } diff --git a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.Net4_7.verified.txt b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.Net4_7.verified.txt index a58f4b47ae..8b79270768 100644 --- a/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.Net4_7.verified.txt +++ b/TUnit.PublicAPI/Tests.Core_Library_Has_No_API_Changes.Net4_7.verified.txt @@ -1395,6 +1395,7 @@ namespace public required .MethodMetadata MethodMetadata { get; init; } public required .PropertyDataSource[] PropertyDataSources { get; init; } public .PropertyInjectionData[] PropertyInjections { get; init; } + public int? RepeatCount { get; init; } public required TestClassType { get; init; } public ? TestInvoker { get; init; } public required string TestMethodName { get; init; } diff --git a/TUnit.Templates/content/TUnit.AspNet.FSharp/TestProject/TestProject.fsproj b/TUnit.Templates/content/TUnit.AspNet.FSharp/TestProject/TestProject.fsproj index 11470092b7..91f0a6e0c8 100644 --- a/TUnit.Templates/content/TUnit.AspNet.FSharp/TestProject/TestProject.fsproj +++ b/TUnit.Templates/content/TUnit.AspNet.FSharp/TestProject/TestProject.fsproj @@ -10,8 +10,8 @@ - - + + diff --git a/TUnit.Templates/content/TUnit.AspNet/TestProject/TestProject.csproj b/TUnit.Templates/content/TUnit.AspNet/TestProject/TestProject.csproj index df8607e357..3f09cc4357 100644 --- a/TUnit.Templates/content/TUnit.AspNet/TestProject/TestProject.csproj +++ b/TUnit.Templates/content/TUnit.AspNet/TestProject/TestProject.csproj @@ -9,7 +9,7 @@ - + diff --git a/TUnit.Templates/content/TUnit.Aspire.Starter/ExampleNamespace.TestProject/ExampleNamespace.TestProject.csproj b/TUnit.Templates/content/TUnit.Aspire.Starter/ExampleNamespace.TestProject/ExampleNamespace.TestProject.csproj index 4edc91b281..2807d7224b 100644 --- a/TUnit.Templates/content/TUnit.Aspire.Starter/ExampleNamespace.TestProject/ExampleNamespace.TestProject.csproj +++ b/TUnit.Templates/content/TUnit.Aspire.Starter/ExampleNamespace.TestProject/ExampleNamespace.TestProject.csproj @@ -11,7 +11,7 @@ - + diff --git a/TUnit.Templates/content/TUnit.Aspire.Test/ExampleNamespace.csproj b/TUnit.Templates/content/TUnit.Aspire.Test/ExampleNamespace.csproj index 02fa9e6e4c..6414123352 100644 --- a/TUnit.Templates/content/TUnit.Aspire.Test/ExampleNamespace.csproj +++ b/TUnit.Templates/content/TUnit.Aspire.Test/ExampleNamespace.csproj @@ -10,7 +10,7 @@ - + diff --git a/TUnit.Templates/content/TUnit.FSharp/TestProject.fsproj b/TUnit.Templates/content/TUnit.FSharp/TestProject.fsproj index ee617a08d6..1b0dec9845 100644 --- a/TUnit.Templates/content/TUnit.FSharp/TestProject.fsproj +++ b/TUnit.Templates/content/TUnit.FSharp/TestProject.fsproj @@ -10,8 +10,8 @@ - - + + diff --git a/TUnit.Templates/content/TUnit.Playwright/TestProject.csproj b/TUnit.Templates/content/TUnit.Playwright/TestProject.csproj index 97999dfecd..9e83610945 100644 --- a/TUnit.Templates/content/TUnit.Playwright/TestProject.csproj +++ b/TUnit.Templates/content/TUnit.Playwright/TestProject.csproj @@ -8,7 +8,7 @@ - + diff --git a/TUnit.Templates/content/TUnit.VB/TestProject.vbproj b/TUnit.Templates/content/TUnit.VB/TestProject.vbproj index 928065fc76..7908a08bcd 100644 --- a/TUnit.Templates/content/TUnit.VB/TestProject.vbproj +++ b/TUnit.Templates/content/TUnit.VB/TestProject.vbproj @@ -8,6 +8,6 @@ - + diff --git a/TUnit.Templates/content/TUnit/TestProject.csproj b/TUnit.Templates/content/TUnit/TestProject.csproj index 0bffb52722..750ba6000f 100644 --- a/TUnit.Templates/content/TUnit/TestProject.csproj +++ b/TUnit.Templates/content/TUnit/TestProject.csproj @@ -8,7 +8,7 @@ - + \ No newline at end of file diff --git a/TUnit.TestProject/Bugs/Issue2504CollectionExpressionTest.cs b/TUnit.TestProject/Bugs/Issue2504CollectionExpressionTest.cs index 6623279309..ca912f64b1 100644 --- a/TUnit.TestProject/Bugs/Issue2504CollectionExpressionTest.cs +++ b/TUnit.TestProject/Bugs/Issue2504CollectionExpressionTest.cs @@ -17,7 +17,7 @@ public class Issue2504CollectionExpressionTest public async Task TestWithSingleArgument(int value) { ExecutedTests.Add($"SingleParam:{value}"); - await Assert.That(value).IsIn(10, 20); // 5*2=10, 10*2=20 + await Assert.That(value).IsIn([10, 20]); // 5*2=10, 10*2=20 } [Test] @@ -34,7 +34,7 @@ public async Task TestWithMultipleArguments(int number, string text) public async Task TestWithArrayArgument(int value) { ExecutedTests.Add($"ArrayParam:{value}"); - await Assert.That(value).IsIn(4, 5); + await Assert.That(value).IsIn([4, 5]); } public static IEnumerable GetDataWithSingleIntParam(int multiplier) diff --git a/TUnit.TestProject/Bugs/Issue2504CompilationTest.cs b/TUnit.TestProject/Bugs/Issue2504CompilationTest.cs index 462229a6d6..7232cd9f50 100644 --- a/TUnit.TestProject/Bugs/Issue2504CompilationTest.cs +++ b/TUnit.TestProject/Bugs/Issue2504CompilationTest.cs @@ -15,7 +15,7 @@ public class Issue2504CompilationTest public async Task TestWithCollectionExpressionSyntax(int value) { // Test should receive 10 (5 * 2) and 20 (10 * 2) - await Assert.That(value).IsIn(10, 20); + await Assert.That(value).IsIn([10, 20]); } [Test] diff --git a/TUnit.TestProject/DynamicTests/Basic.cs b/TUnit.TestProject/DynamicTests/Basic.cs index a47f048d72..8f9c7ce0ec 100644 --- a/TUnit.TestProject/DynamicTests/Basic.cs +++ b/TUnit.TestProject/DynamicTests/Basic.cs @@ -48,49 +48,49 @@ public void BuildTests(DynamicTestBuilderContext context) { TestMethod = @class => @class.SomeMethod(), TestMethodArguments = [], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); context.AddTest(new DynamicTest { TestMethod = @class => @class.SomeMethod_Task(), TestMethodArguments = [], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); context.AddTest(new DynamicTest { TestMethod = @class => @class.SomeMethod_ValueTask(), TestMethodArguments = [], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); context.AddTest(new DynamicTest { TestMethod = @class => @class.SomeMethod_Args(1, "test", true), TestMethodArguments = [2, "test", false], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); context.AddTest(new DynamicTest { TestMethod = @class => @class.SomeMethod_Task_Args(1, "test", true), TestMethodArguments = [2, "test", false], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); context.AddTest(new DynamicTest { TestMethod = @class => @class.SomeMethod_ValueTask_Args(1, "test", true), TestMethodArguments = [2, "test", false], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); context.AddTest(new DynamicTest { TestMethod = @class => @class.SomeMethod_ValueTask_Args(1, "test", true), TestMethodArguments = [2, "test", false], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); } } diff --git a/TUnit.TestProject/DynamicTests/Runtime.cs b/TUnit.TestProject/DynamicTests/Runtime.cs index b525a5f58a..79b5b5c830 100644 --- a/TUnit.TestProject/DynamicTests/Runtime.cs +++ b/TUnit.TestProject/DynamicTests/Runtime.cs @@ -29,7 +29,7 @@ await context.AddDynamicTest(new DynamicTest TestMethod = @class => @class.SomeMethod(0, 0, 0), TestClassArguments = [a + 10, b + 10, c + 10], TestMethodArguments = [d + 10, e + 10, f + 10], - Attributes = [new RepeatAttribute(5)] + Attributes = [] }); } } diff --git a/TUnit/TUnit.csproj b/TUnit/TUnit.csproj index 90d69d876e..8da0bf21bf 100644 --- a/TUnit/TUnit.csproj +++ b/TUnit/TUnit.csproj @@ -7,6 +7,11 @@ + + + + + diff --git a/assets/banner.png b/assets/banner.png index cc6ed2bdf5..ae5cb4b575 100644 Binary files a/assets/banner.png and b/assets/banner.png differ