diff --git a/tests/FSharpPlus.Tests/Asyncs.fs b/tests/FSharpPlus.Tests/Asyncs.fs index f70a47589..ec9cabe20 100644 --- a/tests/FSharpPlus.Tests/Asyncs.fs +++ b/tests/FSharpPlus.Tests/Asyncs.fs @@ -29,9 +29,11 @@ module Async = if not isFailed && delay = 0 then async.Return value else async { - if delay = 0 then do! Async.raise (TestException (sprintf "Ouch, can't create: %A" value )) + let excn = TestException (sprintf "Ouch, can't create: %A" value) + excn.Data.Add("key", value) + if delay = 0 then do! Async.raise excn do! Async.Sleep delay - if isFailed then do! Async.raise (TestException (sprintf "Ouch, can't create: %A" value )) + if isFailed then do! Async.raise excn return value } @@ -54,7 +56,7 @@ module Async = let t12123 = Async.zip3 t12t12 t33 t4 let ac1 = try - Async.AsTaskAndWait(t12123).Exception.InnerExceptions |> Seq.map (fun x -> int (Char.GetNumericValue x.Message.[35])) + Async.AsTaskAndWait(t12123).Exception.InnerExceptions |> Seq.map (fun x -> x.Data["key"] :?> int) with e -> failwithf "Failure in testAsyncZip. Async status is %A . Exception is %A" (Async.AsTaskAndWait t12123).Status e @@ -62,7 +64,7 @@ module Async = let t13 = Async.zip3 (Async.zip t1 t3) t4 (Async.zip t5 t6) Assert.AreEqual (true, Async.AsTaskAndWait(t13).IsFaulted, "Async.zip(3) between a value, an exception and a cancellation -> exception wins.") - let ac2 = Async.AsTaskAndWait(t13).Exception.InnerExceptions |> Seq.map (fun x -> int (Char.GetNumericValue x.Message.[35])) + let ac2 = Async.AsTaskAndWait(t13).Exception.InnerExceptions |> Seq.map (fun x -> x.Data["key"] :?> int) CollectionAssert.AreEquivalent ([1; 3], ac2, "Async.zip between 2 exceptions => both exceptions returned, even after combining with cancellation and values.") [] @@ -84,7 +86,7 @@ module Async = let t12123 = Async.zip3 t12t12 t33 t4 let ac1 = try - Async.AsTaskAndWait(t12123).Exception.InnerExceptions |> Seq.map (fun x -> int (Char.GetNumericValue x.Message.[35])) + Async.AsTaskAndWait(t12123).Exception.InnerExceptions |> Seq.map (fun x -> x.Data["key"] :?> int) with e -> failwithf "Failure in testAsyncZipAsync. Async status is %A . Exception is %A" (Async.AsTaskAndWait t12123).Status e @@ -92,7 +94,7 @@ module Async = let t13 = Async.zip3 (Async.zip t1 t3) t4 (Async.zip t5 t6) Assert.AreEqual (true, Async.AsTaskAndWait(t13).IsFaulted, "Async.zip(3)Async between a value, an exception and a cancellation -> exception wins.") - let ac2 = Async.AsTaskAndWait(t13).Exception.InnerExceptions |> Seq.map (fun x -> int (Char.GetNumericValue x.Message.[35])) + let ac2 = Async.AsTaskAndWait(t13).Exception.InnerExceptions |> Seq.map (fun x -> x.Data["key"] :?> int) CollectionAssert.AreEquivalent ([1; 3], ac2, "Async.zipAsync between 2 exceptions => both exceptions returned, even after combining with cancellation and values.") [] diff --git a/tests/FSharpPlus.Tests/Task.fs b/tests/FSharpPlus.Tests/Task.fs index 171a6c6b9..9b831e052 100644 --- a/tests/FSharpPlus.Tests/Task.fs +++ b/tests/FSharpPlus.Tests/Task.fs @@ -18,9 +18,11 @@ module Task = if not isFailed && delay = 0 then Task.FromResult value else let tcs = TaskCompletionSource<_> () - if delay = 0 then tcs.SetException (TestException (sprintf "Ouch, can't create: %A" value )) + let excn = TestException (sprintf "Ouch, can't create: %A" value) + excn.Data.Add("key", value) + if delay = 0 then tcs.SetException (excn) else (Task.Delay delay).ContinueWith (fun _ -> - if isFailed then tcs.SetException (TestException (sprintf "Ouch, can't create: %A" value )) else tcs.SetResult value) |> ignore + if isFailed then tcs.SetException (excn) else tcs.SetResult value) |> ignore tcs.Task let (|AggregateException|_|) (x: exn) = diff --git a/tests/FSharpPlus.Tests/ValueTask.fs b/tests/FSharpPlus.Tests/ValueTask.fs index e91f24cd8..8f71b38e6 100644 --- a/tests/FSharpPlus.Tests/ValueTask.fs +++ b/tests/FSharpPlus.Tests/ValueTask.fs @@ -40,9 +40,12 @@ module ValueTask = if not isFailed && delay = 0 then ValueTask.result value else let tcs = TaskCompletionSource<_> () - if delay = 0 then tcs.SetException (TestException (sprintf "Ouch, can't create: %A" value )) + let excn = TestException (sprintf "Ouch, can't create: %A" value) + excn.Data.Add("key", value) + + if delay = 0 then tcs.SetException (excn) else (Task.Delay delay).ContinueWith (fun _ -> - if isFailed then tcs.SetException (TestException (sprintf "Ouch, can't create: %A" value )) else tcs.SetResult value) |> ignore + if isFailed then tcs.SetException (excn) else tcs.SetResult value) |> ignore tcs.Task |> ValueTask<'T> let (|AggregateException|_|) (x: exn) =