From 4e49d8e9fbb4fa7c21f7128b8ae471d41bf5d83e Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sun, 24 Dec 2023 12:03:43 +0000 Subject: [PATCH 1/5] Small code cleanup refactorings --- .../Nunit.Extensions.fs | 4 ++-- src/FSharp.Control.TaskSeq.Test/TestUtils.fs | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/FSharp.Control.TaskSeq.Test/Nunit.Extensions.fs b/src/FSharp.Control.TaskSeq.Test/Nunit.Extensions.fs index c43d459c..3fb2d63c 100644 --- a/src/FSharp.Control.TaskSeq.Test/Nunit.Extensions.fs +++ b/src/FSharp.Control.TaskSeq.Test/Nunit.Extensions.fs @@ -134,7 +134,7 @@ module ExtraCustomMatchers = CustomMatcher( $"Throws %s{ex.Name} (Below, XUnit does not show actual value properly)", - (fun fn -> (testForThrowing (fn :?> (unit -> Task))).Result) + (fun fn -> (testForThrowing (fn :?> unit -> Task)).Result) ) /// @@ -170,7 +170,7 @@ module ExtraCustomMatchers = CustomMatcher( $"Throws %s{ex.Name} (Below, XUnit does not show actual value properly)", - (fun fn -> (testForThrowing (fn :?> (unit -> Task))).Result) + (fun fn -> (testForThrowing (fn :?> unit -> Task)).Result) ) let inline assertThrows ty (f: unit -> 'U) = f >> ignore |> should throw ty diff --git a/src/FSharp.Control.TaskSeq.Test/TestUtils.fs b/src/FSharp.Control.TaskSeq.Test/TestUtils.fs index d81b8bf9..a1488a9d 100644 --- a/src/FSharp.Control.TaskSeq.Test/TestUtils.fs +++ b/src/FSharp.Control.TaskSeq.Test/TestUtils.fs @@ -79,6 +79,8 @@ module DelayHelper = /// Default for and /// are 10,000µs and 30,000µs respectively (or 10ms and 30ms). /// +/// Minimum delay in µs +/// Maximum delay in µs type DummyTaskFactory(µsecMin: int64<µs>, µsecMax: int64<µs>) = let mutable x = 0 @@ -98,7 +100,7 @@ type DummyTaskFactory(µsecMin: int64<µs>, µsecMax: int64<µs>) = /// Uses the defaults for and /// with 10,000µs and 30,000µs respectively (or 10ms and 30ms). /// - new() = new DummyTaskFactory(10_000L<µs>, 30_000L<µs>) + new() = DummyTaskFactory(10_000L<µs>, 30_000L<µs>) /// /// Creates dummy tasks with a randomized delay and a mutable state, @@ -106,12 +108,14 @@ type DummyTaskFactory(µsecMin: int64<µs>, µsecMax: int64<µs>) = /// Values and can be /// given in milliseconds. /// + /// Minimum delay in ms + /// Maximum delay in ms new(msecMin: int, msecMax: int) = new DummyTaskFactory(int64 msecMin * 1000L<µs>, int64 msecMax * 1000L<µs>) /// Bunch of delayed tasks that randomly have a yielding delay of 10-30ms, therefore having overlapping execution times. member _.CreateDelayedTasks_SideEffect total = [ - for i in 0 .. total - 1 do + for _ in 0 .. total - 1 do fun () -> runTaskDelayed () ] @@ -123,7 +127,7 @@ type DummyTaskFactory(µsecMin: int64<µs>, µsecMax: int64<µs>) = /// Bunch of delayed tasks without internally using Task.Delay, therefore hot-started and immediately finished. member _.CreateDirectTasks_SideEffect total = [ - for i in 0 .. total - 1 do + for _ in 0 .. total - 1 do fun () -> runTaskDirect () ] @@ -468,7 +472,7 @@ module TestUtils = | SeqWithSideEffect.Sequential_For -> taskSeq { // F# BUG? coloring disappears? - for x = 0 to 9 do + for _ = 0 to 9 do i <- i + 1 yield i } @@ -528,7 +532,7 @@ module TestUtils = /// Will add 1 to the passed integer upon disposing. let getEmptyDisposableTaskSeq (disposed: int ref) = { new IAsyncEnumerable<'T> with - member _.GetAsyncEnumerator(_) = + member _.GetAsyncEnumerator _ = { new IAsyncEnumerator<'T> with member _.MoveNextAsync() = ValueTask.False member _.Current = Unchecked.defaultof<'T> @@ -540,7 +544,7 @@ module TestUtils = /// The singleton value is '42'. Will add 1 to the passed integer upon disposing. let getSingletonDisposableTaskSeq (disposed: int ref) = { new IAsyncEnumerable with - member _.GetAsyncEnumerator(_) = + member _.GetAsyncEnumerator _ = let mutable status = BeforeAll { new IAsyncEnumerator with From 7dbf1ed5a70076e004c6659ac0f0eae68574437d Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sun, 24 Dec 2023 11:36:08 +0000 Subject: [PATCH 2/5] Fix spelling errors, typos, and unused vars --- .../TaskSeq.AsyncExtensions.Tests.fs | 6 ++-- .../TaskSeq.Collect.Tests.fs | 24 +++++++------- .../TaskSeq.Do.Tests.fs | 8 ++--- .../TaskSeq.Filter.Tests.fs | 2 -- .../TaskSeq.Head.Tests.fs | 8 ++--- .../TaskSeq.Last.Tests.fs | 17 +++++----- .../TaskSeq.Length.Tests.fs | 2 +- .../TaskSeq.Let.Tests.fs | 9 +++--- .../TaskSeq.Map.Tests.fs | 6 ++-- .../TaskSeq.MaxMin.Tests.fs | 2 +- .../TaskSeq.Realworld.fs | 4 +-- .../TaskSeq.Skip.Tests.fs | 2 +- .../TaskSeq.SkipWhile.Tests.fs | 2 -- ...Seq.StateTransitionBug-delayed.Tests.CE.fs | 2 +- .../TaskSeq.StateTransitionBug.Tests.CE.fs | 10 +++--- .../TaskSeq.Take.Tests.fs | 6 ++-- .../TaskSeq.TakeWhile.Tests.fs | 2 -- .../TaskSeq.TaskExtensions.Tests.fs | 6 ++-- .../TaskSeq.Tests.CE.fs | 32 +++++++++---------- 19 files changed, 71 insertions(+), 79 deletions(-) diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.AsyncExtensions.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.AsyncExtensions.Tests.fs index 62d58368..f36fe920 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.AsyncExtensions.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.AsyncExtensions.Tests.fs @@ -23,11 +23,11 @@ module EmptySeq = } [] - let ``Async-for CE must execute side effect in empty taskseq`` () = async { + let ``Async-for CE must execute side effect in empty taskSeq`` () = async { let mutable data = 0 let values = taskSeq { do data <- 42 } - for x in values do + for _ in values do () data |> should equal 42 @@ -121,7 +121,7 @@ module Other = let disposed = ref 0 let values = Gen.getEmptyDisposableTaskSeq disposed - for x in values do + for _ in values do () // the DisposeAsync should be called by now diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Collect.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Collect.Tests.fs index 48b1ec41..ae31dd85 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Collect.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Collect.Tests.fs @@ -180,9 +180,9 @@ module SideEffects = // point of this test: just calling 'map' won't execute anything of the sequence! let _ = ts - |> TaskSeq.collect (fun x -> taskSeq { yield 10 }) - |> TaskSeq.collect (fun x -> taskSeq { yield 10 }) - |> TaskSeq.collect (fun x -> taskSeq { yield 10 }) + |> TaskSeq.collect (fun _ -> taskSeq { yield 10 }) + |> TaskSeq.collect (fun _ -> taskSeq { yield 10 }) + |> TaskSeq.collect (fun _ -> taskSeq { yield 10 }) // multiple maps have no effect unless executed i |> should equal 0 @@ -201,9 +201,9 @@ module SideEffects = // point of this test: just calling 'map' won't execute anything of the sequence! let _ = ts - |> TaskSeq.collectAsync (fun x -> task { return taskSeq { yield 10 } }) - |> TaskSeq.collectAsync (fun x -> task { return taskSeq { yield 10 } }) - |> TaskSeq.collectAsync (fun x -> task { return taskSeq { yield 10 } }) + |> TaskSeq.collectAsync (fun _ -> task { return taskSeq { yield 10 } }) + |> TaskSeq.collectAsync (fun _ -> task { return taskSeq { yield 10 } }) + |> TaskSeq.collectAsync (fun _ -> task { return taskSeq { yield 10 } }) // multiple maps have no effect unless executed i |> should equal 0 @@ -222,9 +222,9 @@ module SideEffects = // point of this test: just calling 'map' won't execute anything of the sequence! let _ = ts - |> TaskSeq.collectSeq (fun x -> seq { yield 10 }) - |> TaskSeq.collectSeq (fun x -> seq { yield 10 }) - |> TaskSeq.collectSeq (fun x -> seq { yield 10 }) + |> TaskSeq.collectSeq (fun _ -> seq { yield 10 }) + |> TaskSeq.collectSeq (fun _ -> seq { yield 10 }) + |> TaskSeq.collectSeq (fun _ -> seq { yield 10 }) // multiple maps have no effect unless executed i |> should equal 0 @@ -243,9 +243,9 @@ module SideEffects = // point of this test: just calling 'map' won't execute anything of the sequence! let _ = ts - |> TaskSeq.collectSeqAsync (fun x -> task { return seq { yield 10 } }) - |> TaskSeq.collectSeqAsync (fun x -> task { return seq { yield 10 } }) - |> TaskSeq.collectSeqAsync (fun x -> task { return seq { yield 10 } }) + |> TaskSeq.collectSeqAsync (fun _ -> task { return seq { yield 10 } }) + |> TaskSeq.collectSeqAsync (fun _ -> task { return seq { yield 10 } }) + |> TaskSeq.collectSeqAsync (fun _ -> task { return seq { yield 10 } }) // multiple maps have no effect unless executed i |> should equal 0 diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs index 1f8badae..d206346f 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs @@ -22,7 +22,7 @@ let ``CE taskSeq: use 'do!' with a task`` () = |> Task.map (fun _ -> value |> should equal 1) [] -let ``CE taskSeq: use 'do!' with a valuetask`` () = +let ``CE taskSeq: use 'do!' with a valueTask`` () = let mutable value = 0 taskSeq { do! ValueTask.ofTask (task { do value <- value + 1 }) } @@ -30,7 +30,7 @@ let ``CE taskSeq: use 'do!' with a valuetask`` () = |> Task.map (fun _ -> value |> should equal 1) [] -let ``CE taskSeq: use 'do!' with a non-generic valuetask`` () = +let ``CE taskSeq: use 'do!' with a non-generic valueTask`` () = let mutable value = 0 taskSeq { do! ValueTask(task { do value <- value + 1 }) } @@ -92,8 +92,8 @@ let ``CE taskSeq: use 'do!' with all kinds of overloads at once`` () = do! task { do value <- value + 1 } |> Task.ignore do! ValueTask <| task { do value <- value + 1 } do! ValueTask.ofTask (task { do value <- value + 1 }) - do! ValueTask<_>(()) // unit valuetask that completes immediately - do! Task.fromResult (()) // unit Task that completes immediately + do! ValueTask<_>(()) // unit valueTask that completes immediately + do! Task.fromResult () // unit Task that completes immediately do! Task.Delay 0 do! Async.Sleep 0 do! async { value <- value + 1 } // eq 4 diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Filter.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Filter.Tests.fs index 0e189cc5..bc0fe54d 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Filter.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Filter.Tests.fs @@ -1,7 +1,5 @@ module TaskSeq.Tests.Filter -open System - open Xunit open FsUnit.Xunit diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Head.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Head.Tests.fs index af4cd8fc..1450e9f5 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Head.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Head.Tests.fs @@ -98,10 +98,10 @@ module SideEffects = x <- x + 1 // we never get here } - let! fortytwo = one |> TaskSeq.head + let! fortyTwo = one |> TaskSeq.head let! stillFortyTwo = one |> TaskSeq.head // the statement after 'yield' will never be reached - fortytwo |> should equal 42 + fortyTwo |> should equal 42 stillFortyTwo |> should equal 42 } @@ -114,8 +114,8 @@ module SideEffects = x <- x + 1 // we never get here } - let! fortytwo = one |> TaskSeq.tryHead - fortytwo |> should equal (Some 42) + let! fortyTwo = one |> TaskSeq.tryHead + fortyTwo |> should equal (Some 42) // the statement after 'yield' will never be reached, the mutable will not be updated let! stillFortyTwo = one |> TaskSeq.tryHead diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Last.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Last.Tests.fs index c74e8136..47eed383 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Last.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Last.Tests.fs @@ -109,11 +109,11 @@ module SideEffects = x <- x + 1 } - let! fortytwo = one |> TaskSeq.last - let! fortythree = one |> TaskSeq.last // side effect, re-iterating! + let! fortyTwo = one |> TaskSeq.last + let! fortyThree = one |> TaskSeq.last // side effect, re-iterating! - fortytwo |> should equal 42 - fortythree |> should equal 43 + fortyTwo |> should equal 42 + fortyThree |> should equal 43 } [] @@ -125,13 +125,12 @@ module SideEffects = x <- x + 1 } - let! fortytwo = one |> TaskSeq.tryLast - fortytwo |> should equal (Some 42) + let! fortyTwo = one |> TaskSeq.tryLast + fortyTwo |> should equal (Some 42) // side effect, reiterating causes it to execute again! - let! fortythree = one |> TaskSeq.tryLast - fortythree |> should equal (Some 43) - + let! fortyThree = one |> TaskSeq.tryLast + fortyThree |> should equal (Some 43) } [)>] diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Length.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Length.Tests.fs index ac8c3882..f8f0bfeb 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Length.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Length.Tests.fs @@ -89,7 +89,7 @@ module Immutable = do! run (fun x -> x % 3 = 2) |> Task.map (should equal 3) // [2; 5; 8] } -module SideSeffects = +module SideEffects = [] let ``TaskSeq-length prove we execute after-effects`` () = task { let mutable i = 0 diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs index e7c37844..928e5ad3 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs @@ -1,6 +1,5 @@ module TaskSeq.Tests.Let -open System open System.Threading.Tasks open FsUnit @@ -41,7 +40,7 @@ let ``CE taskSeq: use 'let!' with a task`` () = |> Task.map (should equal "test") [] -let ``CE taskSeq: use 'let!' with a valuetask`` () = +let ``CE taskSeq: use 'let!' with a valueTask`` () = let mutable value = 0 taskSeq { @@ -52,7 +51,7 @@ let ``CE taskSeq: use 'let!' with a valuetask`` () = |> Task.map (fun _ -> value |> should equal 1) [] -let ``CE taskSeq: use 'let!' with a valuetask`` () = +let ``CE taskSeq: use 'let!' with a valueTask`` () = taskSeq { let! test = ValueTask.ofTask (task { return "test" }) yield test @@ -61,7 +60,7 @@ let ``CE taskSeq: use 'let!' with a valuetask`` () = |> Task.map (should equal "test") [] -let ``CE taskSeq: use 'let!' with a non-generic valuetask`` () = +let ``CE taskSeq: use 'let!' with a non-generic valueTask`` () = let mutable value = 0 taskSeq { @@ -136,7 +135,7 @@ let ``CE taskSeq: use 'let!' with all kinds of overloads at once`` () = } |> ValueTask - let! c = ValueTask<_>(4) // valuetask that completes immediately + let! c = ValueTask<_>(4) // valueTask that completes immediately let! _ = Task.Factory.StartNew(fun () -> value <- value + 1) // non-generic Task with side effect let! d = Task.fromResult 99 // normal Task that completes immediately let! _ = Async.Sleep 0 // unit Async diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Map.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Map.Tests.fs index e266b3c9..daf50a94 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Map.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Map.Tests.fs @@ -182,11 +182,11 @@ module SideEffects = [)>] - let ``TaskSeq-map can access mutables which are mutated in correct order`` variant = + let ``TaskSeq-map can access mutables that are mutated in correct order`` variant = let mutable sum = 0 Gen.getSeqWithSideEffect variant - |> TaskSeq.map (fun item -> + |> TaskSeq.map (fun _ -> sum <- sum + 1 char (sum + 64)) |> validateSequence @@ -221,7 +221,7 @@ module SideEffects = let mutable sum = 0 Gen.getSeqWithSideEffect variant - |> TaskSeq.mapAsync (fun item -> task { + |> TaskSeq.mapAsync (fun _ -> task { sum <- sum + 1 return char (sum + 64) }) diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.MaxMin.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.MaxMin.Tests.fs index 8f122b52..638c856a 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.MaxMin.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.MaxMin.Tests.fs @@ -213,7 +213,7 @@ module Immutable = min |> should equal 10 // because -10 maps to item 10 } -module SideSeffects = +module SideEffects = [] let ``TaskSeq-max, maxBy, maxByAsync prove we execute after-effects`` () = task { let mutable i = 0 diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Realworld.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Realworld.fs index f7c8594f..ac9baeef 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Realworld.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Realworld.fs @@ -13,14 +13,14 @@ open Xunit.Abstractions /// Just a naive, simple in-memory reader that acts as an IAsyncEnumerable to use with tests /// IMPORTANT: currently this is not thread-safe!!! -type AsyncBufferedReader(output: ITestOutputHelper, data, blockSize) = +type AsyncBufferedReader(_output: ITestOutputHelper, data, blockSize) = let stream = new MemoryStream(data: byte[]) let buffered = new BufferedStream(stream, blockSize) let mutable current = ValueNone let mutable lastPos = 0L interface IAsyncEnumerable with - member reader.GetAsyncEnumerator(ct) = + member reader.GetAsyncEnumerator _ = { new IAsyncEnumerator<_> with member this.Current = (reader :> IAsyncEnumerator<_>).Current member this.MoveNextAsync() = (reader :> IAsyncEnumerator<_>).MoveNextAsync() diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Skip.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Skip.Tests.fs index c44e4841..660fa939 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Skip.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Skip.Tests.fs @@ -194,7 +194,7 @@ module SideEffects = } [] - let ``TaskSeq-skip prove that an exception from the taskseq is thrown instead of exception from function`` () = + let ``TaskSeq-skip prove that an exception from the taskSeq is thrown instead of exception from function`` () = let items = taskSeq { yield 42 yield! [ 1; 2 ] diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.SkipWhile.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.SkipWhile.Tests.fs index b0bf214e..246a1fe8 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.SkipWhile.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.SkipWhile.Tests.fs @@ -1,7 +1,5 @@ module TaskSeq.Tests.skipWhile -open System - open Xunit open FsUnit.Xunit diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug-delayed.Tests.CE.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug-delayed.Tests.CE.fs index 8eb699bf..8dc5a2b6 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug-delayed.Tests.CE.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug-delayed.Tests.CE.fs @@ -79,7 +79,7 @@ let ``CE taskSeq, MoveNext too far`` () = task { do! Assert.moveNextAndCheck false enum // third item: false // then call it bunch of times to ensure we don't get an InvalidOperationException, see issue #39 and PR #42 - for i in 0..100 do + for _ in 0..100 do do! Assert.moveNextAndCheck false enum // after whatever amount of time MoveNextAsync, we can still safely call Current diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs index 0861911e..154f3a17 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs @@ -11,7 +11,7 @@ open FSharp.Control [] let ``CE empty taskSeq with MoveNextAsync -- untyped`` () = task { - let tskSeq = taskSeq { do ignore () } + let tskSeq = taskSeq { do () } Assert.IsAssignableFrom>(tskSeq) |> ignore @@ -41,7 +41,7 @@ let ``CE empty taskSeq, GetAsyncEnumerator multiple times`` variant = task { [)>] let ``CE empty taskSeq, GetAsyncEnumerator multiple times and then MoveNextAsync`` variant = task { let tskSeq = Gen.getEmptyVariant variant - use enumerator = tskSeq.GetAsyncEnumerator() + use _enumerator = tskSeq.GetAsyncEnumerator() use enumerator = tskSeq.GetAsyncEnumerator() do! Assert.moveNextAndCheck false enumerator } @@ -86,7 +86,7 @@ let ``CE empty taskSeq, GetAsyncEnumerator + MoveNextAsync 100x in a loop`` vari let tskSeq = Gen.getEmptyVariant variant // let's get the enumerator a few times - for i in 0..100 do + for _ in 0..100 do use enumerator = tskSeq.GetAsyncEnumerator() do! Assert.moveNextAndCheck false enumerator // these are all empty } @@ -202,7 +202,7 @@ let ``CE taskSeq, MoveNext too far`` () = task { do! Assert.moveNextAndCheck false enum // third item: false // then call it bunch of times to ensure we don't get an InvalidOperationException, see issue #39 and PR #42 - for i in 0..100 do + for _ in 0..100 do do! Assert.moveNextAndCheck false enum // after whatever amount of time MoveNextAsync, we can still safely call Current @@ -234,7 +234,7 @@ let ``CE taskSeq, call GetAsyncEnumerator twice, both should have equal behavior [] let ``CE seq -- comparison --, call GetEnumerator twice`` () = task { - // this test is for behavioral comparisoni between the same Async test above with TaskSeq + // this test is for behavioral comparison between the same Async test above with TaskSeq let sq = seq { yield 1 yield 2 diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Take.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Take.Tests.fs index 9e633a38..89078b1e 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Take.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Take.Tests.fs @@ -192,7 +192,7 @@ module SideEffects = first |> should equal expected repeat |> should equal expected // if we read too far, this is now [|43, 86|] - x |> should equal 42 // expect: side-effect at end of taskseq not executed + x |> should equal 42 // expect: side-effect at end of taskSeq not executed } [] @@ -207,7 +207,7 @@ module SideEffects = [] - let ``TaskSeq-take prove that an exception from the taskseq is thrown instead of exception from function`` () = + let ``TaskSeq-take prove that an exception from the taskSeq is thrown instead of exception from function`` () = let items = taskSeq { yield 42 yield! [ 1; 2 ] @@ -235,5 +235,5 @@ module SideEffects = first |> should equal expected repeat |> should equal expected // if we read too far, this is now [|43, 86|] - x |> should equal 42 // expect: side-effect at end of taskseq not executed + x |> should equal 42 // expect: side-effect at end of taskSeq not executed } diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.TakeWhile.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.TakeWhile.Tests.fs index 81fc3bf4..91565217 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.TakeWhile.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.TakeWhile.Tests.fs @@ -1,7 +1,5 @@ module TaskSeq.Tests.TakeWhile -open System - open Xunit open FsUnit.Xunit diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.TaskExtensions.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.TaskExtensions.Tests.fs index 0121663f..d50b8667 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.TaskExtensions.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.TaskExtensions.Tests.fs @@ -23,11 +23,11 @@ module EmptySeq = } [] - let ``Task-for CE must execute side effect in empty taskseq`` () = task { + let ``Task-for CE must execute side effect in empty taskSeq`` () = task { let mutable data = 0 let values = taskSeq { do data <- 42 } - for x in values do + for _ in values do () data |> should equal 42 @@ -120,7 +120,7 @@ module Other = let disposed = ref 0 let values = Gen.getEmptyDisposableTaskSeq disposed - for x in values do + for _ in values do () // the DisposeAsync should be called by now diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Tests.CE.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Tests.CE.fs index 4ae88e66..3c73e77a 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Tests.CE.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Tests.CE.fs @@ -38,10 +38,10 @@ let ``CE taskSeq with nested yield!`` () = task { let control = seq { yield! [ 1..10 ] - for i in 0..9 do + for _ in 0..9 do yield! [ 1..2 ] - for i in 0..2 do + for _ in 0..2 do yield! seq { yield 42 } for i in 100..102 do @@ -51,10 +51,10 @@ let ``CE taskSeq with nested yield!`` () = task { let tskSeq = taskSeq { yield! Gen.sideEffectTaskSeq 10 - for i in 0..9 do + for _ in 0..9 do yield! Gen.sideEffectTaskSeq 2 - for i in 0..2 do + for _ in 0..2 do yield! taskSeq { yield 42 } for i in 100..102 do @@ -87,31 +87,31 @@ let ``CE taskSeq with nested deeply yield! perf test 8521 nested tasks`` () = ta yield! createTasks 10 // nestings amount to 8512 sequences of [1;2] - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 - for i in 0..2 do + for _ in 0..2 do yield! createTasks 2 yield! TaskSeq.empty @@ -153,7 +153,7 @@ let ``CE taskSeq: 1000 TaskDelay-delayed tasks using yield!`` () = task { [] let ``CE taskSeq: 1000 sync-running tasks using yield!`` () = task { // Smoke performance test - // Runs in a few 10's of ms, because of absense of Task.Delay + // Runs in a few 10's of ms, because of absence of Task.Delay // should generally be about as fast as `task`, see below let tskSeq = taskSeq { yield! Gen.sideEffectTaskSeq_Sequential 1000 } let! data = tskSeq |> TaskSeq.toListAsync @@ -185,7 +185,7 @@ let ``CE task: 1000 TaskDelay-delayed tasks using for-loop`` () = task { [] let ``CE task: 1000 list of sync-running tasks using for-loop`` () = task { - // runs in a few 10's of ms, because of absense of Task.Delay + // runs in a few 10's of ms, because of absence of Task.Delay // for smoke-test comparison with taskSeq let tasks = DummyTaskFactory().CreateDirectTasks_SideEffect 1000 let mutable i = 0 @@ -199,7 +199,7 @@ let ``CE task: 1000 list of sync-running tasks using for-loop`` () = task { [] let ``CE task: 5000 list of sync-running tasks using for-loop`` () = task { - // runs in a few 100's of ms, because of absense of Task.Delay + // runs in a few 100's of ms, because of absence of Task.Delay // for smoke-test comparison with taskSeq let tasks = DummyTaskFactory().CreateDirectTasks_SideEffect 5000 let mutable i = 0 From 452c28279d552a168d98db945c6d00e98eb04752 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sun, 24 Dec 2023 12:20:23 +0000 Subject: [PATCH 3/5] Add words that can be ignored in Rider for spelling checks --- src/FSharp.Control.TaskSeq.sln.DotSettings | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/FSharp.Control.TaskSeq.sln.DotSettings b/src/FSharp.Control.TaskSeq.sln.DotSettings index 560b0f6c..85faab57 100644 --- a/src/FSharp.Control.TaskSeq.sln.DotSettings +++ b/src/FSharp.Control.TaskSeq.sln.DotSettings @@ -1,5 +1,9 @@  - True - True - True + True + True + True + True + True + True + True \ No newline at end of file From cb6291f43ea39146c42da1d097d5f22ff16d56a8 Mon Sep 17 00:00:00 2001 From: Ruben Bartelink Date: Sun, 24 Dec 2023 16:56:49 +0000 Subject: [PATCH 4/5] Apply review comments Co-Authored-By: Abel Braaksma --- src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs | 8 ++++---- src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs | 8 ++++---- .../TaskSeq.StateTransitionBug.Tests.CE.fs | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs index d206346f..c914a0e7 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Do.Tests.fs @@ -22,7 +22,7 @@ let ``CE taskSeq: use 'do!' with a task`` () = |> Task.map (fun _ -> value |> should equal 1) [] -let ``CE taskSeq: use 'do!' with a valueTask`` () = +let ``CE taskSeq: use 'do!' with a ValueTask`` () = let mutable value = 0 taskSeq { do! ValueTask.ofTask (task { do value <- value + 1 }) } @@ -30,7 +30,7 @@ let ``CE taskSeq: use 'do!' with a valueTask`` () = |> Task.map (fun _ -> value |> should equal 1) [] -let ``CE taskSeq: use 'do!' with a non-generic valueTask`` () = +let ``CE taskSeq: use 'do!' with a non-generic ValueTask`` () = let mutable value = 0 taskSeq { do! ValueTask(task { do value <- value + 1 }) } @@ -92,8 +92,8 @@ let ``CE taskSeq: use 'do!' with all kinds of overloads at once`` () = do! task { do value <- value + 1 } |> Task.ignore do! ValueTask <| task { do value <- value + 1 } do! ValueTask.ofTask (task { do value <- value + 1 }) - do! ValueTask<_>(()) // unit valueTask that completes immediately - do! Task.fromResult () // unit Task that completes immediately + do! ValueTask<_>(()) // unit ValueTask that completes immediately + do! Task.fromResult (()) // unit Task that completes immediately do! Task.Delay 0 do! Async.Sleep 0 do! async { value <- value + 1 } // eq 4 diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs index 928e5ad3..cc474d16 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.Let.Tests.fs @@ -40,7 +40,7 @@ let ``CE taskSeq: use 'let!' with a task`` () = |> Task.map (should equal "test") [] -let ``CE taskSeq: use 'let!' with a valueTask`` () = +let ``CE taskSeq: use 'let!' with a ValueTask`` () = let mutable value = 0 taskSeq { @@ -51,7 +51,7 @@ let ``CE taskSeq: use 'let!' with a valueTask`` () = |> Task.map (fun _ -> value |> should equal 1) [] -let ``CE taskSeq: use 'let!' with a valueTask`` () = +let ``CE taskSeq: use 'let!' with a ValueTask`` () = taskSeq { let! test = ValueTask.ofTask (task { return "test" }) yield test @@ -60,7 +60,7 @@ let ``CE taskSeq: use 'let!' with a valueTask`` () = |> Task.map (should equal "test") [] -let ``CE taskSeq: use 'let!' with a non-generic valueTask`` () = +let ``CE taskSeq: use 'let!' with a non-generic ValueTask`` () = let mutable value = 0 taskSeq { @@ -135,7 +135,7 @@ let ``CE taskSeq: use 'let!' with all kinds of overloads at once`` () = } |> ValueTask - let! c = ValueTask<_>(4) // valueTask that completes immediately + let! c = ValueTask<_>(4) // ValueTask that completes immediately let! _ = Task.Factory.StartNew(fun () -> value <- value + 1) // non-generic Task with side effect let! d = Task.fromResult 99 // normal Task that completes immediately let! _ = Async.Sleep 0 // unit Async diff --git a/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs b/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs index 154f3a17..7aeb00a7 100644 --- a/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs +++ b/src/FSharp.Control.TaskSeq.Test/TaskSeq.StateTransitionBug.Tests.CE.fs @@ -32,16 +32,16 @@ let ``CE empty taskSeq with MoveNextAsync -- typed`` variant = task { [)>] let ``CE empty taskSeq, GetAsyncEnumerator multiple times`` variant = task { let tskSeq = Gen.getEmptyVariant variant - use _e = tskSeq.GetAsyncEnumerator() - use _e = tskSeq.GetAsyncEnumerator() - use _e = tskSeq.GetAsyncEnumerator() + use _ = tskSeq.GetAsyncEnumerator() + use _ = tskSeq.GetAsyncEnumerator() + use _ = tskSeq.GetAsyncEnumerator() () } [)>] let ``CE empty taskSeq, GetAsyncEnumerator multiple times and then MoveNextAsync`` variant = task { let tskSeq = Gen.getEmptyVariant variant - use _enumerator = tskSeq.GetAsyncEnumerator() + use _ = tskSeq.GetAsyncEnumerator() use enumerator = tskSeq.GetAsyncEnumerator() do! Assert.moveNextAndCheck false enumerator } From 42c9ad3faaa85972bf48bb187feaea74bbf80181 Mon Sep 17 00:00:00 2001 From: Abel Braaksma Date: Sun, 24 Dec 2023 18:41:25 +0100 Subject: [PATCH 5/5] Rename `NUnit.Extensions.fs` -> `Xunit.Extensions.fs` --- .../FSharp.Control.TaskSeq.Test.fsproj | 2 +- .../{Nunit.Extensions.fs => Xunit.Extensions.fs} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/FSharp.Control.TaskSeq.Test/{Nunit.Extensions.fs => Xunit.Extensions.fs} (100%) diff --git a/src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj b/src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj index ceb5ab14..459e625b 100644 --- a/src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj +++ b/src/FSharp.Control.TaskSeq.Test/FSharp.Control.TaskSeq.Test.fsproj @@ -7,7 +7,7 @@ - + diff --git a/src/FSharp.Control.TaskSeq.Test/Nunit.Extensions.fs b/src/FSharp.Control.TaskSeq.Test/Xunit.Extensions.fs similarity index 100% rename from src/FSharp.Control.TaskSeq.Test/Nunit.Extensions.fs rename to src/FSharp.Control.TaskSeq.Test/Xunit.Extensions.fs