From 9d0f6537ddcea5de5bc02285cff03d188d7fe7fa Mon Sep 17 00:00:00 2001 From: Eirik Tsarpalis Date: Thu, 16 Jul 2026 15:50:44 +0300 Subject: [PATCH] Bump to .NET 10 SDK and C# 14 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: e96cf6d5-ac36-4e33-ac15-0a1e865e8681 --- .github/workflows/build.yml | 2 +- Directory.Build.props | 2 +- Dockerfile | 5 +- global.json | 6 ++ .../Domain/IUserService.cs | 2 +- .../EffBindings/EffectLogger.cs | 2 +- .../EffBindings/RecordingEffectHandler.cs | 2 +- samples/Eff.Examples.Config/ConfigEffect.cs | 2 +- .../Container.cs | 2 +- .../DomainLogic.cs | 4 +- .../Program.cs | 4 +- .../NonDetEffectHandler.cs | 2 +- .../Eff.Examples.RecordReplay/Container.cs | 2 +- .../RecordEffectHandler.cs | 2 +- samples/Eff.Examples.Resumable/Program.cs | 2 +- src/Eff/Handlers/EffStateMachine.cs | 2 +- tests/Eff.Benchmarks/Benchmark.cs | 61 +++++++++---------- tests/Eff.Benchmarks/Program.cs | 15 +++-- .../CancellationEffectHandlerTests.cs | 8 +-- .../CustomEffectHandler.cs | 4 +- .../CustomEffectHandler/CustomEffects.cs | 6 +- tests/Eff.Tests/CustomEffectHandlerTests.cs | 16 ++--- tests/Eff.Tests/DefaultEffectHandlerTests.cs | 18 +++--- .../Eff.Tests/DependencyEffectHandlerTests.cs | 6 +- tests/Eff.Tests/EffAwaiterTests.cs | 2 +- tests/Eff.Tests/EffStateMachineTests.cs | 16 ++--- tests/Eff.Tests/EffTests.cs | 4 +- tests/Eff.Tests/EffectHandlerTests.cs | 26 ++++---- tests/Eff.Tests/NonDeterminismTests.cs | 20 +++--- 29 files changed, 126 insertions(+), 119 deletions(-) create mode 100644 global.json diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 526b316..8b21c32 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -13,6 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v7 - name: Build run: make docker-build diff --git a/Directory.Build.props b/Directory.Build.props index 68104cb..3d90369 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ enable - 12.0 + 14.0 false enable diff --git a/Dockerfile b/Dockerfile index 71da33c..2fae081 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,7 @@ -FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine +FROM mcr.microsoft.com/dotnet/runtime:8.0-alpine AS net8-runtime +FROM mcr.microsoft.com/dotnet/sdk:10.0-alpine + +COPY --from=net8-runtime /usr/share/dotnet/shared/Microsoft.NETCore.App /usr/share/dotnet/shared/Microsoft.NETCore.App RUN apk add git make diff --git a/global.json b/global.json new file mode 100644 index 0000000..545c92c --- /dev/null +++ b/global.json @@ -0,0 +1,6 @@ +{ + "sdk": { + "version": "10.0.302", + "rollForward": "latestFeature" + } +} diff --git a/samples/Eff.Examples.AspNetCore/Domain/IUserService.cs b/samples/Eff.Examples.AspNetCore/Domain/IUserService.cs index 1b9a99b..a04b864 100644 --- a/samples/Eff.Examples.AspNetCore/Domain/IUserService.cs +++ b/samples/Eff.Examples.AspNetCore/Domain/IUserService.cs @@ -22,7 +22,7 @@ public interface IUserService /// public class InMemoryUserService : IUserService { - private ConcurrentDictionary _users = new ConcurrentDictionary(); + private ConcurrentDictionary _users = new(); public async Task Exists(string username) => _users.ContainsKey(username); public async Task Create(string username, string password) diff --git a/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs b/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs index 2e7f8a6..14f9c97 100644 --- a/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs +++ b/samples/Eff.Examples.AspNetCore/EffBindings/EffectLogger.cs @@ -13,7 +13,7 @@ namespace Nessos.Effects.Examples.AspNetCore.EffBindings; public class EffectLogger { private ConcurrentDictionary> _store = - new ConcurrentDictionary>(); + new(); /// /// Commit an effect trace log, returning a unique identifier that can be used for future retrievals. diff --git a/samples/Eff.Examples.AspNetCore/EffBindings/RecordingEffectHandler.cs b/samples/Eff.Examples.AspNetCore/EffBindings/RecordingEffectHandler.cs index 50a160c..d77d079 100644 --- a/samples/Eff.Examples.AspNetCore/EffBindings/RecordingEffectHandler.cs +++ b/samples/Eff.Examples.AspNetCore/EffBindings/RecordingEffectHandler.cs @@ -17,7 +17,7 @@ namespace Nessos.Effects.Examples.AspNetCore.EffBindings; /// public class RecordingEffectHandler : DependencyEffectHandler, IDisposableEffectHandler { - private readonly List _results = new List(); + private readonly List _results = []; private readonly EffectLogger _store; private readonly HttpResponse _response; diff --git a/samples/Eff.Examples.Config/ConfigEffect.cs b/samples/Eff.Examples.Config/ConfigEffect.cs index edd7797..a4fc3a7 100644 --- a/samples/Eff.Examples.Config/ConfigEffect.cs +++ b/samples/Eff.Examples.Config/ConfigEffect.cs @@ -12,5 +12,5 @@ public ConfigEffect(string key) public string Key { get; } - public static ConfigEffect Get(string key) => new ConfigEffect(key); + public static ConfigEffect Get(string key) => new(key); } diff --git a/samples/Eff.Examples.DependencyInjection/Container.cs b/samples/Eff.Examples.DependencyInjection/Container.cs index 2acec62..0735531 100644 --- a/samples/Eff.Examples.DependencyInjection/Container.cs +++ b/samples/Eff.Examples.DependencyInjection/Container.cs @@ -6,7 +6,7 @@ // Poor man's DI container public class Container : IContainer, IEnumerable { - private Dictionary _dict = new Dictionary(); + private Dictionary _dict = []; public void Add(T value) => _dict[typeof(T)] = value!; diff --git a/samples/Eff.Examples.DependencyInjection/DomainLogic.cs b/samples/Eff.Examples.DependencyInjection/DomainLogic.cs index b21c617..3ccf98b 100644 --- a/samples/Eff.Examples.DependencyInjection/DomainLogic.cs +++ b/samples/Eff.Examples.DependencyInjection/DomainLogic.cs @@ -54,9 +54,9 @@ public static async Eff CreateNewUser(string userName, string password) public static async Eff CreateNewUsers((string userName, string password)[] credentials) { - foreach (var cred in credentials) + foreach (var (userName, password) in credentials) { - await DomainLogic.CreateNewUser(cred.userName, cred.password); + await DomainLogic.CreateNewUser(userName, password); } return credentials.Length; diff --git a/samples/Eff.Examples.DependencyInjection/Program.cs b/samples/Eff.Examples.DependencyInjection/Program.cs index 0ac719a..e1484d5 100644 --- a/samples/Eff.Examples.DependencyInjection/Program.cs +++ b/samples/Eff.Examples.DependencyInjection/Program.cs @@ -1,7 +1,7 @@ using Nessos.Effects.DependencyInjection; using Nessos.Effects.Examples.DependencyInjection; -Container container = new(); +Container container = []; container.Add(new ConsoleLogger()); container.Add(new MockUserService()); @@ -20,7 +20,7 @@ class ConsoleLogger : ILogger class MockUserService : IUserService { - private readonly HashSet _users = new HashSet(); + private readonly HashSet _users = []; #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously public async Task CreateUser(string username, string password) => _users.Add(username); public async Task Exists(string username) => _users.Contains(username); diff --git a/samples/Eff.Examples.NonDeterminism/NonDetEffectHandler.cs b/samples/Eff.Examples.NonDeterminism/NonDetEffectHandler.cs index 46cc9d0..9841b6c 100644 --- a/samples/Eff.Examples.NonDeterminism/NonDetEffectHandler.cs +++ b/samples/Eff.Examples.NonDeterminism/NonDetEffectHandler.cs @@ -130,7 +130,7 @@ private static EffectAwaiter CloneAwaiter(EffectAwaiter public class NonDetResultHolder { - public List Values { get; } = new List(); + public List Values { get; } = []; public Exception? Exception { get; set; } public TResult[] GetResults() { diff --git a/samples/Eff.Examples.RecordReplay/Container.cs b/samples/Eff.Examples.RecordReplay/Container.cs index 9b2d672..ed97846 100644 --- a/samples/Eff.Examples.RecordReplay/Container.cs +++ b/samples/Eff.Examples.RecordReplay/Container.cs @@ -6,7 +6,7 @@ // Poor man's DI container public class Container : IContainer, IEnumerable { - private Dictionary _dict = new Dictionary(); + private Dictionary _dict = []; public void Add(T value) => _dict[typeof(T)] = value!; diff --git a/samples/Eff.Examples.RecordReplay/RecordEffectHandler.cs b/samples/Eff.Examples.RecordReplay/RecordEffectHandler.cs index c0e6319..99be4d0 100644 --- a/samples/Eff.Examples.RecordReplay/RecordEffectHandler.cs +++ b/samples/Eff.Examples.RecordReplay/RecordEffectHandler.cs @@ -5,7 +5,7 @@ public class RecordEffectHandler : DependencyEffectHandler { - private readonly List _results = new List(); + private readonly List _results = []; public RecordEffectHandler(IContainer dependencies) : base(dependencies) { diff --git a/samples/Eff.Examples.Resumable/Program.cs b/samples/Eff.Examples.Resumable/Program.cs index 77bd849..0223988 100644 --- a/samples/Eff.Examples.Resumable/Program.cs +++ b/samples/Eff.Examples.Resumable/Program.cs @@ -3,7 +3,7 @@ using System.Diagnostics; // Define a resumable computation -async Eff ResumableWorkflow() +static async Eff ResumableWorkflow() { for (int i = 0; i < 20; i++) { diff --git a/src/Eff/Handlers/EffStateMachine.cs b/src/Eff/Handlers/EffStateMachine.cs index 01f10d2..876701d 100644 --- a/src/Eff/Handlers/EffStateMachine.cs +++ b/src/Eff/Handlers/EffStateMachine.cs @@ -210,7 +210,7 @@ internal EffStateMachine() /// /// Gets an identifier for the particular awaiter instance. /// - public override string Id => nameof(EffStateMachine); + public override string Id => nameof(EffStateMachine<>); /// /// Processes the awaiter using the provided effect handler. diff --git a/tests/Eff.Benchmarks/Benchmark.cs b/tests/Eff.Benchmarks/Benchmark.cs index b5c9c97..9ac9fbe 100644 --- a/tests/Eff.Benchmarks/Benchmark.cs +++ b/tests/Eff.Benchmarks/Benchmark.cs @@ -4,49 +4,48 @@ using System.Linq; using System.Threading.Tasks; -namespace Nessos.Effects.Benchmarks +namespace Nessos.Effects.Benchmarks; + +[MemoryDiagnoser] +public class Benchmark { - [MemoryDiagnoser] - public class Benchmark - { - const int ResultOffset = 50_000; // prevent task caching from kicking in - private readonly int[] _data = Enumerable.Range(0, 100).Select(x => x + ResultOffset).ToArray(); - private readonly IEffectHandler _handler = new DefaultEffectHandler(); + const int ResultOffset = 50_000; // prevent task caching from kicking in + private readonly int[] _data = Enumerable.Range(0, 100).Select(x => x + ResultOffset).ToArray(); + private readonly IEffectHandler _handler = new DefaultEffectHandler(); - [Benchmark(Description = "Task Builder", Baseline = true)] - public async ValueTask TaskBuilder() => await TaskFlow.SumOfOddSquares(_data); + [Benchmark(Description = "Task Builder", Baseline = true)] + public async ValueTask TaskBuilder() => await TaskFlow.SumOfOddSquares(_data); - [Benchmark(Description = "Eff Builder")] - public async ValueTask EffBuilder() => await EffFlow.SumOfOddSquares(_data).Run(_handler); + [Benchmark(Description = "Eff Builder")] + public async ValueTask EffBuilder() => await EffFlow.SumOfOddSquares(_data).Run(_handler); - private static class TaskFlow + private static class TaskFlow + { + public static async Task SumOfOddSquares(int[] inputs) { - public static async Task SumOfOddSquares(int[] inputs) - { - int sum = 0; - foreach (var i in inputs) - if (i % 2 == 1) sum += await Square(i); + int sum = 0; + foreach (var i in inputs) + if (i % 2 == 1) sum += await Square(i); - return sum; + return sum; - static async Task Square(int x) => await Echo(x) * await Echo(x); - static async Task Echo(T x) => x; - } + static async Task Square(int x) => await Echo(x) * await Echo(x); + static async Task Echo(T x) => x; } + } - private static class EffFlow + private static class EffFlow + { + public static async Eff SumOfOddSquares(int[] inputs) { - public static async Eff SumOfOddSquares(int[] inputs) - { - int sum = 0; - foreach (var i in inputs) - if (i % 2 == 1) sum += await Square(i); + int sum = 0; + foreach (var i in inputs) + if (i % 2 == 1) sum += await Square(i); - return sum; + return sum; - static async Eff Square(int x) => await Echo(x) * await Echo(x); - static async Eff Echo(T x) => x; - } + static async Eff Square(int x) => await Echo(x) * await Echo(x); + static async Eff Echo(T x) => x; } } } diff --git a/tests/Eff.Benchmarks/Program.cs b/tests/Eff.Benchmarks/Program.cs index 3f6a62c..9987a94 100644 --- a/tests/Eff.Benchmarks/Program.cs +++ b/tests/Eff.Benchmarks/Program.cs @@ -1,15 +1,14 @@ using System; using BenchmarkDotNet.Running; -namespace Nessos.Effects.Benchmarks +namespace Nessos.Effects.Benchmarks; + +class Program { - class Program + static void Main(string[] args) { - static void Main(string[] args) - { - var assembly = System.Reflection.Assembly.GetExecutingAssembly(); - var switcher = new BenchmarkSwitcher(assembly); - var summaries = switcher.Run(args); - } + var assembly = System.Reflection.Assembly.GetExecutingAssembly(); + var switcher = new BenchmarkSwitcher(assembly); + var summaries = switcher.Run(args); } } diff --git a/tests/Eff.Tests/CancellationEffectHandlerTests.cs b/tests/Eff.Tests/CancellationEffectHandlerTests.cs index 25b501e..c0b63a6 100644 --- a/tests/Eff.Tests/CancellationEffectHandlerTests.cs +++ b/tests/Eff.Tests/CancellationEffectHandlerTests.cs @@ -11,7 +11,7 @@ public class CancellationEffectHandlerTests : EffectHandlerTests [Fact] public async Task Stub_CanceledToken_ShouldThrowOperationCanceledException() { - async Eff Test() => 42; + static async Eff Test() => 42; var handler = new CancellationEffectHandler(new CancellationToken(canceled: true)); await Assert.ThrowsAsync(() => Test().Run(handler).AsTask()); @@ -20,7 +20,7 @@ public async Task Stub_CanceledToken_ShouldThrowOperationCanceledException() [Fact] public async Task DivergingWorkflow_CanceledToken_ShouldThrowOperationCanceledException() { - async Eff Test() + static async Eff Test() { while (await ShouldContinue()) { @@ -28,7 +28,7 @@ async Eff Test() } - async Eff ShouldContinue() => true; + static async Eff ShouldContinue() => true; } using var cts = new CancellationTokenSource(1_000); @@ -39,7 +39,7 @@ async Eff Test() [Fact] public async Task CancellationTokenEffect_PassedToTask_ShouldThrowTaskCanceledException() { - async Eff Test() + static async Eff Test() { var token = await CancellationTokenEffect.Value; await Task.Delay(60_000, token); diff --git a/tests/Eff.Tests/CustomEffectHandler/CustomEffectHandler.cs b/tests/Eff.Tests/CustomEffectHandler/CustomEffectHandler.cs index 4e9c877..e557a1b 100644 --- a/tests/Eff.Tests/CustomEffectHandler/CustomEffectHandler.cs +++ b/tests/Eff.Tests/CustomEffectHandler/CustomEffectHandler.cs @@ -7,8 +7,8 @@ public class CustomEffectHandler : EffectHandler { private readonly DateTime _now; - public List ExceptionLogs { get; } = new List(); - public List TraceLogs { get; } = new List(); + public List ExceptionLogs { get; } = []; + public List TraceLogs { get; } = []; public CustomEffectHandler(DateTime now) { diff --git a/tests/Eff.Tests/CustomEffectHandler/CustomEffects.cs b/tests/Eff.Tests/CustomEffectHandler/CustomEffects.cs index 86f7ca1..ff2018f 100644 --- a/tests/Eff.Tests/CustomEffectHandler/CustomEffects.cs +++ b/tests/Eff.Tests/CustomEffectHandler/CustomEffects.cs @@ -13,9 +13,9 @@ public interface IFuncEffect } public struct CustomEffect : IDateTimeNowEffect, IFuncEffect { - public DateTimeNowEffect DateTimeNow() => new DateTimeNowEffect(); + public DateTimeNowEffect DateTimeNow() => new(); - public FuncEffect Func(Func func) => new FuncEffect(func); + public FuncEffect Func(Func func) => new(func); - public FuncEffect Action(Action action) => new FuncEffect(() => { action(); return Unit.Value; }); + public FuncEffect Action(Action action) => new(() => { action(); return Unit.Value; }); } diff --git a/tests/Eff.Tests/CustomEffectHandlerTests.cs b/tests/Eff.Tests/CustomEffectHandlerTests.cs index aab4105..09dca62 100644 --- a/tests/Eff.Tests/CustomEffectHandlerTests.cs +++ b/tests/Eff.Tests/CustomEffectHandlerTests.cs @@ -10,7 +10,7 @@ public class CustomEffectHandlerTests : EffectHandlerTests [Fact] public async Task AwaitCustomEffect() { - async Eff Foo() + static async Eff Foo() where T : struct, IDateTimeNowEffect { var y = await default(T).DateTimeNow().ConfigureAwait(); @@ -25,12 +25,12 @@ async Eff Foo() [Fact] public async Task TestExceptionLog() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Nested(x); return y; - async Eff Nested(int x) + static async Eff Nested(int x) { return 1 / x; } @@ -46,12 +46,12 @@ async Eff Nested(int x) [Fact] public async Task TestTraceLog() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Nested(x); return y; - async Eff Nested(int x) + static async Eff Nested(int x) { return x + 1; } @@ -68,7 +68,7 @@ async Eff Nested(int x) [Fact] public async Task TestParametersLogging() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Eff.FromResult(1); return x + y; @@ -87,7 +87,7 @@ async Eff Test(int x) [Fact] public async Task TestLocalVariablesLogging() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Eff.FromResult(1); await Eff.CompletedEff; @@ -137,7 +137,7 @@ async Eff Foo(int x) [Fact] public async Task AwaitCaptureStateEffect() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Eff.FromResult(1); await Eff.CompletedEff; diff --git a/tests/Eff.Tests/DefaultEffectHandlerTests.cs b/tests/Eff.Tests/DefaultEffectHandlerTests.cs index e469273..e8e0d2a 100644 --- a/tests/Eff.Tests/DefaultEffectHandlerTests.cs +++ b/tests/Eff.Tests/DefaultEffectHandlerTests.cs @@ -12,7 +12,7 @@ public class DefaultEffectHandlerTests : EffectHandlerTests [Fact] public async Task EffTyped_AwaitEffect_ShouldThrowNotSupportedException() { - async Eff Test() + static async Eff Test() { return await new TestEffect(); } @@ -31,7 +31,7 @@ public async Task Effect_Run_ShouldThrowNotSupportedException() [Fact] public async Task EffUntyped_AwaitEffect_ShouldThrowNotSupportedException() { - async Eff Test() + static async Eff Test() { await new TestEffect(); } @@ -93,7 +93,7 @@ public class EffectHandlerThatDoesntCompleteAwaiter : EffectHandler [Fact] public async Task EffectHandlerThatDoesntCompleteAwaiter_ShouldThrowInvalidOperationException() { - async Eff Test() + static async Eff Test() { return await new TestEffect(); } @@ -115,7 +115,7 @@ public override ValueTask Handle(EffectAwaiter awaiter) [Fact] public async Task EffectHandlerThatSetsExceptionToAwaiter_ShouldThrowTheException() { - async Eff Test() + static async Eff Test() { return await new TestEffect(); } @@ -136,7 +136,7 @@ public override ValueTask Handle(EffectAwaiter awaiter) [Fact] public async Task EffectHandlerThatThrowsException_ShouldPropagateTheException() { - async Eff Test() + static async Eff Test() { return await new TestEffect(); } @@ -148,14 +148,14 @@ async Eff Test() [Fact] public async Task Exception_Stacktrace_ShouldHaveCorrectDepth() { - async Eff Test() + static async Eff Test() { try { await Nested(0); throw new Exception("Should throw an exception"); - async Eff Nested(int x) => 1 / x; + static async Eff Nested(int x) => 1 / x; } catch (DivideByZeroException exception) { @@ -165,10 +165,10 @@ async Eff Test() var expected = new[] { - nameof(EffStateMachine.MoveNext), + nameof(EffStateMachine<>.MoveNext), nameof(ExceptionDispatchInfo.Throw), nameof(EffAwaiter.GetResult), - nameof(EffStateMachine.MoveNext) + nameof(EffStateMachine<>.MoveNext) }; Assert.Equal(expected, methodNames); diff --git a/tests/Eff.Tests/DependencyEffectHandlerTests.cs b/tests/Eff.Tests/DependencyEffectHandlerTests.cs index ccbbe7d..9688f6c 100644 --- a/tests/Eff.Tests/DependencyEffectHandlerTests.cs +++ b/tests/Eff.Tests/DependencyEffectHandlerTests.cs @@ -13,7 +13,7 @@ public class DependencyEffectHandlerTests : EffectHandlerTests [Fact] public async Task DependencyEffect_IntDependency_HappyPath() { - async Eff Test() + static async Eff Test() { return await IO.Do(x => x + 1); } @@ -97,7 +97,7 @@ public async Task DependencyEffect_Run_HappyPath() [Fact] public async Task DependencyEffect_MissingDependency_ShouldThrowKeyNotFoundException() { - async Eff Test() + static async Eff Test() { await IO.Do(d => d.Test()); } @@ -120,7 +120,7 @@ public void Test() { } private class Container : IContainer, IEnumerable { - private readonly Dictionary _dict = new Dictionary(); + private readonly Dictionary _dict = []; public void Add(TDependency dependency) => _dict[typeof(TDependency)] = dependency; diff --git a/tests/Eff.Tests/EffAwaiterTests.cs b/tests/Eff.Tests/EffAwaiterTests.cs index 3266607..5856c03 100644 --- a/tests/Eff.Tests/EffAwaiterTests.cs +++ b/tests/Eff.Tests/EffAwaiterTests.cs @@ -91,7 +91,7 @@ public static void ConfigureAwait_ShouldAddCallerInfo() [Fact] public static void StateMachine_GetAsyncStateMachine_ShouldReturnCopies() { - async Eff Test() + static async Eff Test() { return await Task.FromResult(42); } diff --git a/tests/Eff.Tests/EffStateMachineTests.cs b/tests/Eff.Tests/EffStateMachineTests.cs index 66e375f..3f563fe 100644 --- a/tests/Eff.Tests/EffStateMachineTests.cs +++ b/tests/Eff.Tests/EffStateMachineTests.cs @@ -16,7 +16,7 @@ public static void NewStateMachine_Position_ShouldReturnNotStarted() Assert.Null(stateMachine.TaskAwaiter); Assert.False(stateMachine.IsCompleted); - async Eff Test() + static async Eff Test() { await Task.Delay(10); return 42; @@ -36,7 +36,7 @@ public static void ReturnedValue_Position_ShouldReturnResult() Assert.Null(stateMachine.TaskAwaiter); Assert.True(stateMachine.IsCompleted); - async Eff Test() => 42; + static async Eff Test() => 42; } [Fact] @@ -67,7 +67,7 @@ public static void OnAwaitedEff_Position_ShouldReturnEffAwaiter() Assert.Null(stateMachine.TaskAwaiter); Assert.False(stateMachine.IsCompleted); - async Eff Test() + static async Eff Test() { return await Eff.FromResult(42); } @@ -85,7 +85,7 @@ public static void OnAwaitedEffect_Position_ShouldReturnEffAwaiter() Assert.Null(stateMachine.TaskAwaiter); Assert.False(stateMachine.IsCompleted); - async Eff Test() + static async Eff Test() { return await new TestEffect(); } @@ -103,7 +103,7 @@ public static void OnTaskAwaiter_Position_ShouldReturnTask() Assert.NotNull(stateMachine.TaskAwaiter); Assert.False(stateMachine.IsCompleted); - async Eff Test() + static async Eff Test() { return await new TaskCompletionSource().Task; } @@ -122,7 +122,7 @@ public static async Task OnTaskAwaiter_Completed_ShouldBeAbleToAdvanceStateMachi stateMachine.MoveNext(); Assert.Equal(42, stateMachine.Result); - async Eff Test() + static async Eff Test() { await Task.Delay(1_000); return 42; @@ -143,11 +143,11 @@ public static async Task OnTaskAwaiter_Delay_ShouldReturnCorrectResult() Assert.Equal(42, stateMachine.Result); - async Eff Test() + static async Eff Test() { return await TaskMethod(); - async Task TaskMethod() + static async Task TaskMethod() { await Task.Delay(1000); return 42; diff --git a/tests/Eff.Tests/EffTests.cs b/tests/Eff.Tests/EffTests.cs index 11777ea..77861f1 100644 --- a/tests/Eff.Tests/EffTests.cs +++ b/tests/Eff.Tests/EffTests.cs @@ -15,7 +15,7 @@ public static void ConfigureAwait_ShouldAddCallerInfo() Assert.True(awaiter.CallerFilePath?.Length > 0); Assert.True(awaiter.CallerLineNumber > 0); - async Eff Test() => 42; + static async Eff Test() => 42; } [Fact] @@ -29,6 +29,6 @@ public static void ConfigureAwait_Untyped_ShouldAddCallerInfo() Assert.True(awaiter.CallerFilePath?.Length > 0); Assert.True(awaiter.CallerLineNumber > 0); - async Eff Test() { }; + static async Eff Test() { }; } } diff --git a/tests/Eff.Tests/EffectHandlerTests.cs b/tests/Eff.Tests/EffectHandlerTests.cs index a395e33..4022a39 100644 --- a/tests/Eff.Tests/EffectHandlerTests.cs +++ b/tests/Eff.Tests/EffectHandlerTests.cs @@ -10,7 +10,7 @@ public abstract class EffectHandlerTests [Fact] public async Task EffTyped_Stub() { - async Eff Test(int x) + static async Eff Test(int x) { return x + 1; } @@ -35,12 +35,12 @@ async Eff Test(int x) [Fact] public async Task EffTyped_NestedAwait() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Nested(x); return y + 1; - async Eff Nested(int x) + static async Eff Nested(int x) { return x + 1; } @@ -252,12 +252,12 @@ public class TestEffect : Effect [Fact] public async Task EffTyped_AwaitSequenceOfTaskEffects() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Nested(x).ConfigureAwait(); return y + 1; - async Eff Nested(int x) + static async Eff Nested(int x) { await Task.Delay(50); var y = await Task.FromResult(x + 1); @@ -293,13 +293,13 @@ async Eff Nested(int x) [Fact] public async Task EffTyped_AwaitCombinationOfEffAndTaskEffects() { - async Eff Test(int x) + static async Eff Test(int x) { await Task.Delay(1000); var y = await Nested(x); return y + 1; - async Eff Nested(int x) + static async Eff Nested(int x) { var y = await Task.FromResult(x + 1); return y; @@ -334,7 +334,7 @@ async Eff Nested(int x) [Fact] public async Task EffTyped_SimpleExceptionPropagation() { - async Eff Test(int x) + static async Eff Test(int x) { return 1 / x; } @@ -346,7 +346,7 @@ async Eff Test(int x) [Fact] public async Task EffUntyped_SimpleExceptionPropagation() { - async Eff Test(int x) + static async Eff Test(int x) { _ = 1 / x; } @@ -358,12 +358,12 @@ async Eff Test(int x) [Fact] public async Task EffTyped_NestedExceptionPropagation() { - async Eff Test(int x) + static async Eff Test(int x) { var y = await Nested(x); return y; - async Eff Nested(int x) + static async Eff Nested(int x) { return 1 / x; } @@ -376,11 +376,11 @@ async Eff Nested(int x) [Fact] public async Task EffUntyped_NestedExceptionPropagation() { - async Eff Test(int x) + static async Eff Test(int x) { await Nested(x); - async Eff Nested(int x) + static async Eff Nested(int x) { _ = 1 / x; } diff --git a/tests/Eff.Tests/NonDeterminismTests.cs b/tests/Eff.Tests/NonDeterminismTests.cs index ef151a9..e5869a6 100644 --- a/tests/Eff.Tests/NonDeterminismTests.cs +++ b/tests/Eff.Tests/NonDeterminismTests.cs @@ -8,7 +8,7 @@ public static class NonDeterminismTests [Fact] public static async Task SimpleValue_HappyPath() { - async Eff Test() => 42; + static async Eff Test() => 42; var expected = new int[] { 42 }; var results = await NonDetEffectHandler.Run(Test()); @@ -18,7 +18,7 @@ public static async Task SimpleValue_HappyPath() [Fact] public static async Task SimpleException_ShouldPropagate() { - async Eff Test(int x) + static async Eff Test(int x) { return 42 / x; } @@ -42,7 +42,7 @@ async Eff Test(int x) [Fact] public static async Task SimpleEffect_HappyPath() { - async Eff Test() => await NonDetEffect.Choose(1, 2, 3, 4); + static async Eff Test() => await NonDetEffect.Choose(1, 2, 3, 4); var expected = new int[] { 1, 2, 3, 4 }; var results = await NonDetEffectHandler.Run(Test()); @@ -52,7 +52,7 @@ public static async Task SimpleEffect_HappyPath() [Fact] public static async Task MultipleValues_HappyPath() { - async Eff<(bool, int, string)> Test() + static async Eff<(bool, int, string)> Test() { var x = await NonDetEffect.Choose(false, true); var y = await NonDetEffect.Choose(1, 2, 3); @@ -73,9 +73,9 @@ public static async Task MultipleValues_HappyPath() [Fact] public static async Task MultipleValues_Nested_HappyPath() { - async Eff<(bool, int, string)> Test() + static async Eff<(bool, int, string)> Test() { - async Eff<(bool, int)> Nested() + static async Eff<(bool, int)> Nested() { var x = await NonDetEffect.Choose(false, true); var y = await NonDetEffect.Choose(1, 2, 3); @@ -101,9 +101,9 @@ public static async Task MultipleValues_Nested_HappyPath() [Fact] public static async Task NestedException_ShouldPropagate() { - async Eff Test() + static async Eff Test() { - async Eff Divide(int y) + static async Eff Divide(int y) { var x = await NonDetEffect.Choose(1, 2, 3); return x / y; @@ -119,9 +119,9 @@ async Eff Divide(int y) [Fact] public static async Task NestedExceptionHandler_ShouldExecuteAsExpected() { - async Eff Test() + static async Eff Test() { - async Eff Divide(int y) + static async Eff Divide(int y) { try {