diff --git a/Directory.Build.props b/Directory.Build.props index 257ab3a..9f89b97 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,18 +1,12 @@ - - - + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + - - + true true @@ -44,4 +38,9 @@ PackagePath="\" Link="LICENSE" /> + + + enable + net8.0;net10.0 + diff --git a/Directory.Packages.props b/Directory.Packages.props new file mode 100644 index 0000000..5829fb0 --- /dev/null +++ b/Directory.Packages.props @@ -0,0 +1,37 @@ + + + true + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Hyperbee.Expressions.sln b/Hyperbee.Expressions.sln index 0776c78..99d0478 100644 --- a/Hyperbee.Expressions.sln +++ b/Hyperbee.Expressions.sln @@ -1,11 +1,12 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.10.35122.118 +# Visual Studio Version 18 +VisualStudioVersion = 18.1.11312.151 d18.0 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6103145C-EC79-4B5F-9CE6-8F10BFC6ACC5}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props + Directory.Packages.props = Directory.Packages.props LICENSE = LICENSE README.md = README.md version.json = version.json diff --git a/src/Hyperbee.Expressions.Lab/Hyperbee.Expressions.Lab.csproj b/src/Hyperbee.Expressions.Lab/Hyperbee.Expressions.Lab.csproj index 056a7f3..ffa4bd6 100644 --- a/src/Hyperbee.Expressions.Lab/Hyperbee.Expressions.Lab.csproj +++ b/src/Hyperbee.Expressions.Lab/Hyperbee.Expressions.Lab.csproj @@ -1,8 +1,6 @@  - net8.0;net9.0 - enable disable true @@ -43,18 +41,16 @@ - - - - - - - + + + + + + + + - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/src/Hyperbee.Expressions/Hyperbee.Expressions.csproj b/src/Hyperbee.Expressions/Hyperbee.Expressions.csproj index 6d79648..3b340b8 100644 --- a/src/Hyperbee.Expressions/Hyperbee.Expressions.csproj +++ b/src/Hyperbee.Expressions/Hyperbee.Expressions.csproj @@ -1,8 +1,6 @@ - net8.0;net9.0 - enable disable true @@ -43,15 +41,13 @@ - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + + + + + + + diff --git a/test/Hyperbee.Expressions.Benchmark/BenchmarkConfig.cs b/test/Hyperbee.Expressions.Benchmark/BenchmarkConfig.cs index dbce1f5..b4bfbac 100644 --- a/test/Hyperbee.Expressions.Benchmark/BenchmarkConfig.cs +++ b/test/Hyperbee.Expressions.Benchmark/BenchmarkConfig.cs @@ -1,6 +1,7 @@ using BenchmarkDotNet.Columns; using BenchmarkDotNet.Configs; using BenchmarkDotNet.Diagnosers; +using BenchmarkDotNet.Environments; using BenchmarkDotNet.Exporters; using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Loggers; @@ -15,7 +16,14 @@ public class Config : ManualConfig { public Config() { - AddJob( Job.ShortRun ); + AddJob( Job.ShortRun + .WithRuntime( CoreRuntime.Core80 ) + .WithId( ".NET 8" ) ); + + AddJob( Job.ShortRun + .WithRuntime( CoreRuntime.Core10_0 ) + .WithId( ".NET 10" ) ); + AddExporter( MarkdownExporter.GitHub ); AddValidator( JitOptimizationsValidator.DontFailOnError ); diff --git a/test/Hyperbee.Expressions.Benchmark/Hyperbee.Expressions.Benchmark.csproj b/test/Hyperbee.Expressions.Benchmark/Hyperbee.Expressions.Benchmark.csproj index dc036ac..f52b112 100644 --- a/test/Hyperbee.Expressions.Benchmark/Hyperbee.Expressions.Benchmark.csproj +++ b/test/Hyperbee.Expressions.Benchmark/Hyperbee.Expressions.Benchmark.csproj @@ -1,17 +1,15 @@ - + Exe - net9.0 - enable disable false - - - + + + @@ -19,10 +17,7 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/test/Hyperbee.Expressions.Tests/BlockAsyncBasicTests.cs b/test/Hyperbee.Expressions.Tests/BlockAsyncBasicTests.cs index 640900c..5dfa161 100644 --- a/test/Hyperbee.Expressions.Tests/BlockAsyncBasicTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockAsyncBasicTests.cs @@ -121,7 +121,6 @@ public async Task BlockAsync_ShouldAwaitMultipleTasks_WithDifferentResults( Comp [DataRow( CompilerType.Fast )] [DataRow( CompilerType.System )] [DataRow( CompilerType.Interpret )] - [ExpectedException( typeof( InvalidOperationException ) )] public async Task BlockAsync_ShouldThrowException_WithFaultedTask( CompilerType compiler ) { // Arrange @@ -133,14 +132,13 @@ public async Task BlockAsync_ShouldThrowException_WithFaultedTask( CompilerType var compiledLambda = lambda.Compile( compiler ); // Act & Assert - await compiledLambda(); + await Assert.ThrowsExactlyAsync( async () => await compiledLambda() ); } [TestMethod] [DataRow( CompilerType.Fast )] [DataRow( CompilerType.System )] [DataRow( CompilerType.Interpret )] - [ExpectedException( typeof( TaskCanceledException ) )] public async Task BlockAsync_ShouldHandleCanceledTask_WithCancellation( CompilerType compiler ) { // Arrange @@ -153,7 +151,7 @@ public async Task BlockAsync_ShouldHandleCanceledTask_WithCancellation( Compiler var compiledLambda = lambda.Compile( compiler ); // Act & Assert - await compiledLambda(); + await Assert.ThrowsExactlyAsync( async () => await compiledLambda() ); } [TestMethod] @@ -554,7 +552,7 @@ public async Task BlockAsync_ShouldAllowParallelBlocks_WithTaskWhenAll( Complete var result = await compiledLambda(); // Assert - Assert.AreEqual( threadCount, result.Length ); + Assert.HasCount( threadCount, result ); for ( var tC = 0; tC < threadCount; tC++ ) { Assert.AreEqual( tC, result[tC] ); diff --git a/test/Hyperbee.Expressions.Tests/BlockAsyncConditionalTests.cs b/test/Hyperbee.Expressions.Tests/BlockAsyncConditionalTests.cs index b497355..1583dfc 100644 --- a/test/Hyperbee.Expressions.Tests/BlockAsyncConditionalTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockAsyncConditionalTests.cs @@ -370,7 +370,6 @@ public async Task AsyncBlock_ShouldAwaitSuccessfully_WithConditionalReturningTas } [TestMethod] - [ExpectedException( typeof( NullReferenceException ) )] public async Task AsyncBlock_ShouldThrowException_WithNullTaskInConditional() { // Arrange: One of the branches returns a null task, leading to exception @@ -385,6 +384,6 @@ public async Task AsyncBlock_ShouldThrowException_WithNullTaskInConditional() var compiledLambda = lambda.Compile(); // Act & Assert - await compiledLambda(); + await Assert.ThrowsExactlyAsync( async () => await compiledLambda() ); } } diff --git a/test/Hyperbee.Expressions.Tests/BlockAsyncSwitchTests.cs b/test/Hyperbee.Expressions.Tests/BlockAsyncSwitchTests.cs index a05f24b..8d24c85 100644 --- a/test/Hyperbee.Expressions.Tests/BlockAsyncSwitchTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockAsyncSwitchTests.cs @@ -189,29 +189,29 @@ public async Task AsyncBlock_ShouldAwaitSuccessfully_WithNestedSwitchesAndAwaits [DataRow( CompleterType.Deferred, CompilerType.Fast )] [DataRow( CompleterType.Deferred, CompilerType.System )] [DataRow( CompleterType.Deferred, CompilerType.Interpret )] - [ExpectedException( typeof( ArgumentException ) )] public async Task AsyncBlock_ShouldThrowException_WithAwaitInSwitchCaseTestValues( CompleterType completer, CompilerType compiler ) { - // Arrange: Switch case test values cannot contain awaited tasks - var block = Switch( - Constant( 1 ), - Constant( 0 ), - SwitchCase( - Constant( 10 ), - Await( BlockAsync( - Await( AsyncHelper.Completer( - Constant( completer ), - Constant( 1 ) + // Act & Assert: The exception should be thrown during lambda construction or compilation + await Assert.ThrowsExactlyAsync(async () => + { + var block = Switch( + Constant( 1 ), + Constant( 0 ), + SwitchCase( + Constant( 10 ), + Await( BlockAsync( + Await( AsyncHelper.Completer( + Constant( completer ), + Constant( 1 ) + ) ) ) ) - ) ) - ), - SwitchCase( Constant( 20 ), Constant( 2 ) ) - ); - var lambda = Lambda>>( block ); - var compiledLambda = lambda.Compile( compiler ); - - // Act - await compiledLambda(); + ), + SwitchCase( Constant( 20 ), Constant( 2 ) ) + ); + var lambda = Lambda>>( block ); + var compiledLambda = lambda.Compile( compiler ); + await compiledLambda(); + }); } [TestMethod] diff --git a/test/Hyperbee.Expressions.Tests/BlockYieldConditionalTests.cs b/test/Hyperbee.Expressions.Tests/BlockYieldConditionalTests.cs index 3becaec..f27b54c 100644 --- a/test/Hyperbee.Expressions.Tests/BlockYieldConditionalTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockYieldConditionalTests.cs @@ -83,7 +83,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithIfThenElseBreaks( CompilerTyp var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 10, result[0] ); } @@ -109,7 +109,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithIfThen_TrueBreak( CompilerTyp var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 0, result.Length ); + Assert.IsEmpty( result ); } [TestMethod] @@ -134,7 +134,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithIfThen_FalseBreak( CompilerTy var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 5, result[0] ); } diff --git a/test/Hyperbee.Expressions.Tests/BlockYieldLoopTests.cs b/test/Hyperbee.Expressions.Tests/BlockYieldLoopTests.cs index a6a301c..fa49d78 100644 --- a/test/Hyperbee.Expressions.Tests/BlockYieldLoopTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockYieldLoopTests.cs @@ -112,7 +112,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithOutLoopBreakOrContinue( Compi var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); // Loop continues past the first iteration + Assert.HasCount( 2, result ); // Loop continues past the first iteration Assert.AreEqual( 1, result[0] ); Assert.AreEqual( 2, result[1] ); } @@ -152,7 +152,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldBeforeContinue( Compiler var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); // Loop continues past the first iteration + Assert.HasCount( 2, result ); // Loop continues past the first iteration Assert.AreEqual( 1, result[0] ); Assert.AreEqual( 2, result[1] ); } @@ -192,7 +192,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldAfterContinue( CompilerT var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); // Loop continues past the first iteration + Assert.HasCount( 1, result ); // Loop continues past the first iteration Assert.AreEqual( 2, result[0] ); } @@ -227,7 +227,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithMultipleYieldInLoop( Compiler var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); + Assert.HasCount( 2, result ); Assert.AreEqual( 0, result[0] ); Assert.AreEqual( 1, result[1] ); } @@ -272,7 +272,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithBreakAndContinueLabels( Compi var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 3, result.Length ); + Assert.HasCount( 3, result ); Assert.AreEqual( 1, result[0] ); Assert.AreEqual( 2, result[1] ); Assert.AreEqual( 3, result[2] ); diff --git a/test/Hyperbee.Expressions.Tests/BlockYieldSwitchTests.cs b/test/Hyperbee.Expressions.Tests/BlockYieldSwitchTests.cs index 775e40d..567de93 100644 --- a/test/Hyperbee.Expressions.Tests/BlockYieldSwitchTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockYieldSwitchTests.cs @@ -34,7 +34,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldInSwitchValue( CompilerT var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 1, result[0] ); } @@ -61,7 +61,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithAwaitInDefaultBody( CompilerT var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 99, result[0] ); } @@ -91,7 +91,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithAwaitInSwitchCaseBody( Compil var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 100, result[0] ); } @@ -124,7 +124,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldInSwitchValueAndCaseBody var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); + Assert.HasCount( 2, result ); Assert.AreEqual( 25, result[0] ); Assert.AreEqual( 50, result[1] ); } @@ -161,7 +161,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithNestedSwitchesAndYields( Comp var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 30, result[0] ); } @@ -189,7 +189,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldBeforeAndAfterSwitch( Co var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); + Assert.HasCount( 2, result ); Assert.AreEqual( 30, result[0] ); Assert.AreEqual( 15, result[1] ); } diff --git a/test/Hyperbee.Expressions.Tests/BlockYieldTryCatchTests.cs b/test/Hyperbee.Expressions.Tests/BlockYieldTryCatchTests.cs index caecd53..5fce03b 100644 --- a/test/Hyperbee.Expressions.Tests/BlockYieldTryCatchTests.cs +++ b/test/Hyperbee.Expressions.Tests/BlockYieldTryCatchTests.cs @@ -29,7 +29,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldInTryBlock( CompilerType var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 10, result[0] ); } @@ -61,7 +61,7 @@ public void YieldBlock_ShouldCatchExceptionSuccessfully_WithYieldInCatchBlock( C var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 1, result.Length ); + Assert.HasCount( 1, result ); Assert.AreEqual( 99, result[0] ); } @@ -92,7 +92,7 @@ public void YieldBlock_ShouldHandleExceptionSuccessfully_WithTryCatchFinally( Co var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); + Assert.HasCount( 2, result ); Assert.AreEqual( 30, result[0] ); Assert.AreEqual( 50, result[1] ); } @@ -120,7 +120,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldInTryAndFinallyBlocks( C var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 3, result.Length ); + Assert.HasCount( 3, result ); Assert.AreEqual( 15, result[0] ); Assert.AreEqual( 25, result[1] ); Assert.AreEqual( 5, result[2] ); @@ -154,7 +154,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldInTryCatchAndFinallyBloc var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 4, result.Length ); + Assert.HasCount( 4, result ); Assert.AreEqual( 10, result[0] ); Assert.AreEqual( 20, result[1] ); Assert.AreEqual( 30, result[2] ); @@ -190,7 +190,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithYieldAfterThrow( CompilerType var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 0, result.Length ); + Assert.IsEmpty( result ); } [TestMethod] @@ -226,7 +226,7 @@ public void YieldBlock_ShouldCatchMultipleExceptionsInNestedTryBlocks( CompilerT var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 2, result.Length ); + Assert.HasCount( 2, result ); Assert.AreEqual( 20, result[0] ); Assert.AreEqual( 50, result[1] ); } @@ -273,7 +273,7 @@ public void YieldBlock_ShouldYieldSuccessfully_WithComplexNestedTryBlock( Compil var result = compiledLambda().ToArray(); // Assert - Assert.AreEqual( 8, result.Length ); + Assert.HasCount( 8, result ); Assert.AreEqual( 0, result[0] ); Assert.AreEqual( 10, result[1] ); Assert.AreEqual( 20, result[2] ); diff --git a/test/Hyperbee.Expressions.Tests/DebugExpressionTests.cs b/test/Hyperbee.Expressions.Tests/DebugExpressionTests.cs index 465b551..0160862 100644 --- a/test/Hyperbee.Expressions.Tests/DebugExpressionTests.cs +++ b/test/Hyperbee.Expressions.Tests/DebugExpressionTests.cs @@ -96,7 +96,6 @@ public void DebugExpression_Should_Not_Invoke_DebugDelegate_When_Condition_Is_Fa } [TestMethod] - [ExpectedException( typeof( ArgumentException ) )] public void DebugExpression_Should_Throw_If_Condition_Is_Not_Boolean() { // Arrange @@ -107,7 +106,7 @@ static void DebugAction( int value ) var invalidCondition = Constant( 42 ); // Act - _ = Debug( DebugAction, invalidCondition, Constant( 10 ) ); + Assert.ThrowsExactly( () => _ = Debug( DebugAction, invalidCondition, Constant( 10 ) ) ); // Assert: Exception is expected } diff --git a/test/Hyperbee.Expressions.Tests/ForEachTests.cs b/test/Hyperbee.Expressions.Tests/ForEachTests.cs index 23e4be9..8bae3a1 100644 --- a/test/Hyperbee.Expressions.Tests/ForEachTests.cs +++ b/test/Hyperbee.Expressions.Tests/ForEachTests.cs @@ -160,7 +160,7 @@ public void ForEachExpression_ShouldIterateOverCollection_WithYields( CompilerTy var results = compiledLambda().ToArray(); // Assert: - Assert.AreEqual( 5, results.Length ); + Assert.HasCount( 5, results ); Assert.AreEqual( 1, results[0] ); Assert.AreEqual( 2, results[1] ); Assert.AreEqual( 3, results[2] ); diff --git a/test/Hyperbee.Expressions.Tests/ForExpressionTests.cs b/test/Hyperbee.Expressions.Tests/ForExpressionTests.cs index 3bbab77..4e2e4a3 100644 --- a/test/Hyperbee.Expressions.Tests/ForExpressionTests.cs +++ b/test/Hyperbee.Expressions.Tests/ForExpressionTests.cs @@ -107,7 +107,7 @@ public void ForExpression_ShouldIterateOverCollection_WithYields( CompilerType c var results = compiledLambda().ToArray(); // Assert: - Assert.AreEqual( 5, results.Length ); + Assert.HasCount( 5, results ); Assert.AreEqual( 0, results[0] ); Assert.AreEqual( 1, results[1] ); Assert.AreEqual( 2, results[2] ); diff --git a/test/Hyperbee.Expressions.Tests/Hyperbee.Expressions.Tests.csproj b/test/Hyperbee.Expressions.Tests/Hyperbee.Expressions.Tests.csproj index cdb6a9c..2183ad4 100644 --- a/test/Hyperbee.Expressions.Tests/Hyperbee.Expressions.Tests.csproj +++ b/test/Hyperbee.Expressions.Tests/Hyperbee.Expressions.Tests.csproj @@ -1,8 +1,6 @@ - + - net8.0;net9.0 - enable disable false true @@ -13,19 +11,16 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - + + + + + + + + + + @@ -38,10 +33,7 @@ - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - + diff --git a/test/Hyperbee.Expressions.Tests/InjectExpressionTests.cs b/test/Hyperbee.Expressions.Tests/InjectExpressionTests.cs index 58c8469..f738aaa 100644 --- a/test/Hyperbee.Expressions.Tests/InjectExpressionTests.cs +++ b/test/Hyperbee.Expressions.Tests/InjectExpressionTests.cs @@ -82,7 +82,6 @@ public void InjectExpression_ShouldInjectSuccessfully_WithKeyedFallback( Compile [DataRow( CompilerType.Fast )] [DataRow( CompilerType.System )] [DataRow( CompilerType.Interpret )] - [ExpectedException( typeof( InvalidOperationException ), "Service is not available." )] public void InjectExpression_ShouldInjectSuccessfully_WithBadKey( CompilerType compiler ) { // Arrange @@ -96,7 +95,7 @@ public void InjectExpression_ShouldInjectSuccessfully_WithBadKey( CompilerType c var lambda = Lambda>( block ); var compiledLambda = lambda.Compile( compiler ); - compiledLambda(); + Assert.ThrowsExactly( () => compiledLambda() ); } [TestMethod] diff --git a/test/Hyperbee.Expressions.Tests/StringFormatExpressionTests.cs b/test/Hyperbee.Expressions.Tests/StringFormatExpressionTests.cs index f924d7f..7a374e4 100644 --- a/test/Hyperbee.Expressions.Tests/StringFormatExpressionTests.cs +++ b/test/Hyperbee.Expressions.Tests/StringFormatExpressionTests.cs @@ -48,14 +48,13 @@ public void StringFormatExpression_Should_Format_String_With_Arguments( Compiler } [TestMethod] - [ExpectedException( typeof( ArgumentException ) )] public void StringFormatExpression_Should_Throw_If_Format_Is_Not_String() { // Arrange var invalidFormat = Expression.Constant( 42 ); // Act - _ = ExpressionExtensions.StringFormat( invalidFormat, Expression.Constant( 10 ) ); + Assert.ThrowsExactly( () => _ = ExpressionExtensions.StringFormat( invalidFormat, Expression.Constant( 10 ) ) ); // Assert: Exception is expected } diff --git a/test/Hyperbee.Expressions.Tests/TestSupport/ExpressionCompilerExtensions.cs b/test/Hyperbee.Expressions.Tests/TestSupport/ExpressionCompilerExtensions.cs index 413a069..53c1302 100644 --- a/test/Hyperbee.Expressions.Tests/TestSupport/ExpressionCompilerExtensions.cs +++ b/test/Hyperbee.Expressions.Tests/TestSupport/ExpressionCompilerExtensions.cs @@ -20,9 +20,22 @@ public static Action Compile( this Expression expression, CompilerType c #if FAST_COMPILER if ( compilerType == CompilerType.Fast ) { - var compiledExpression = expression.CompileFast( false, CompilerFlags.EnableDelegateDebugInfo | CompilerFlags.ThrowOnNotSupportedExpression ); - var target = compiledExpression.Target; // keep for debugging - return compiledExpression; + try + { + var compiledExpression = expression.CompileFast( false, CompilerFlags.EnableDelegateDebugInfo ); + if ( compiledExpression != null ) + { + var target = compiledExpression.Target; // keep for debugging + return compiledExpression; + } + } + catch ( NotSupportedExpressionException ) + { + // Fall back to system compiler when FastExpressionCompiler doesn't support the expression + } + + // Fall back to system compiler + return expression.Compile(); } #endif if ( compilerType == CompilerType.Interpret ) @@ -38,9 +51,22 @@ public static Func Compile( this Expression> expression, CompilerT #if FAST_COMPILER if ( compilerType == CompilerType.Fast ) { - var compiledExpression = expression.CompileFast( false, CompilerFlags.EnableDelegateDebugInfo | CompilerFlags.ThrowOnNotSupportedExpression ); - var target = compiledExpression.Target; // keep for debugging - return compiledExpression; + try + { + var compiledExpression = expression.CompileFast( false, CompilerFlags.EnableDelegateDebugInfo ); + if ( compiledExpression != null ) + { + var target = compiledExpression.Target; // keep for debugging + return compiledExpression; + } + } + catch ( NotSupportedExpressionException ) + { + // Fall back to system compiler when FastExpressionCompiler doesn't support the expression + } + + // Fall back to system compiler + return expression.Compile(); } #endif if ( compilerType == CompilerType.Interpret ) @@ -56,9 +82,22 @@ public static Func Compile( this Expression> expres #if FAST_COMPILER if ( compilerType == CompilerType.Fast ) { - var compiledExpression = expression.CompileFast( false, CompilerFlags.EnableDelegateDebugInfo | CompilerFlags.ThrowOnNotSupportedExpression ); - var target = compiledExpression.Target; // keep for debugging - return compiledExpression; + try + { + var compiledExpression = expression.CompileFast( false, CompilerFlags.EnableDelegateDebugInfo ); + if ( compiledExpression != null ) + { + var target = compiledExpression.Target; // keep for debugging + return compiledExpression; + } + } + catch ( NotSupportedExpressionException ) + { + // Fall back to system compiler when FastExpressionCompiler doesn't support the expression + } + + // Fall back to system compiler + return expression.Compile(); } #endif if ( compilerType == CompilerType.Interpret ) @@ -74,9 +113,22 @@ public static Func Compile( this Expression( () => Using( nonDisposableExpression, Empty() ) ); // Assert: Expect an ArgumentException due to non-disposable resource // The constructor should throw the exception, no need for further assertions diff --git a/test/Hyperbee.Expressions.Tests/WhileExpressionTests.cs b/test/Hyperbee.Expressions.Tests/WhileExpressionTests.cs index 1262245..e0097f9 100644 --- a/test/Hyperbee.Expressions.Tests/WhileExpressionTests.cs +++ b/test/Hyperbee.Expressions.Tests/WhileExpressionTests.cs @@ -104,7 +104,7 @@ public void WhileExpression_ShouldIterateOverCollection_WithYields( CompilerType var results = compiledLambda().ToArray(); // Assert: - Assert.AreEqual( 5, results.Length ); + Assert.HasCount( 5, results ); Assert.AreEqual( 0, results[0] ); Assert.AreEqual( 1, results[1] ); Assert.AreEqual( 2, results[2] ); diff --git a/version.json b/version.json index 3b53b39..79e8f85 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.2.0", + "version": "1.2.1", "publicReleaseRefSpec": [ "^refs/heads/main$", "^refs/heads/hotfix$",