Skip to content

Commit b108c62

Browse files
committed
Assert Taskbuilder tests
1 parent dd208ee commit b108c62

File tree

2 files changed

+86
-70
lines changed

2 files changed

+86
-70
lines changed

tests/FSharpPlus.Tests/Task.fs

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -961,44 +961,52 @@ module Task =
961961
[<Test>]
962962
let taskbuilderTests () =
963963
printfn "Running taskbuilder tests..."
964-
try
965-
testShortCircuitResult()
966-
testDelay()
967-
testNoDelay()
968-
testNonBlocking()
969-
testCatching1()
970-
testCatching2()
971-
testNestedCatching()
972-
testTryFinallyHappyPath()
973-
testTryFinallySadPath()
974-
testTryFinallyCaught()
975-
testUsing()
976-
testUsingFromTask()
977-
testUsingSadPath()
978-
testForLoop()
979-
testForLoopSadPath()
980-
testExceptionAttachedToTaskWithoutAwait() // *1
981-
testExceptionAttachedToTaskWithAwait() // *1
982-
testExceptionThrownInFinally()
983-
test2ndExceptionThrownInFinally()
984-
testFixedStackWhileLoop() // *2
985-
testFixedStackForLoop() // *2
986-
testTypeInference()
987-
// testNoStackOverflowWithImmediateResult() // *3
988-
testNoStackOverflowWithYieldResult()
964+
let tests = [
965+
testShortCircuitResult
966+
testDelay
967+
testNoDelay
968+
testNonBlocking
969+
testCatching1
970+
testCatching2
971+
testNestedCatching
972+
testTryFinallyHappyPath
973+
testTryFinallySadPath
974+
testTryFinallyCaught
975+
testUsing
976+
testUsingFromTask
977+
testUsingSadPath
978+
testForLoop
979+
testForLoopSadPath
980+
testExceptionAttachedToTaskWithoutAwait // *1
981+
testExceptionAttachedToTaskWithAwait // *1
982+
testExceptionThrownInFinally
983+
test2ndExceptionThrownInFinally
984+
testFixedStackWhileLoop // *2
985+
testFixedStackForLoop // *2
986+
testTypeInference
987+
// testNoStackOverflowWithImmediateResult // *3
988+
testNoStackOverflowWithYieldResult
989989
// (Original note from TaskBuilder, n/a here)
990990
// we don't support TCO, so large tail recursions will stack overflow
991991
// or at least use O(n) heap. but small ones should at least function OK.
992-
testSmallTailRecursion()
993-
testTryOverReturnFrom()
994-
testTryFinallyOverReturnFromWithException()
995-
testTryFinallyOverReturnFromWithoutException()
996-
// testCompatibilityWithOldUnitTask() // *4
997-
testAsyncsMixedWithTasks() // *5
998-
printfn "Passed all tests!"
999-
with
1000-
| exn ->
1001-
eprintfn "Exception: %O" exn
992+
testSmallTailRecursion
993+
testTryOverReturnFrom
994+
testTryFinallyOverReturnFromWithException
995+
testTryFinallyOverReturnFromWithoutException
996+
// testCompatibilityWithOldUnitTask // *4
997+
testAsyncsMixedWithTasks // *5
998+
]
999+
1000+
let passed, failed =
1001+
tests
1002+
|> List.map Choice.protect
1003+
|> List.partitionMap (fun x -> x())
1004+
1005+
let failureMsg = sprintf "Some tests failed: %A" failed + (failed |> String.concat System.Environment.NewLine (sprintfn "Exception: %O"))
1006+
1007+
Assert.AreEqual (0, List.length failed, failureMsg)
1008+
printfn "Passed all TaskBuilder tests (%i) !" (List.length passed)
1009+
10021010
()
10031011

10041012
// *1 Test adapted due to errors not being part of the workflow, this is by-design.

tests/FSharpPlus.Tests/ValueTask.fs

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -912,44 +912,52 @@ module ValueTask =
912912
[<Test>]
913913
let taskbuilderTests () =
914914
printfn "Running taskbuilder tests..."
915-
try
916-
testShortCircuitResult()
917-
testDelay()
918-
testNoDelay()
919-
testNonBlocking()
920-
testCatching1()
921-
testCatching2()
922-
testNestedCatching()
923-
testTryFinallyHappyPath()
924-
testTryFinallySadPath()
925-
testTryFinallyCaught()
926-
testUsing()
927-
testUsingFromValueTask()
928-
testUsingSadPath()
929-
testForLoop()
930-
testForLoopSadPath()
931-
testExceptionAttachedToValueTaskWithoutAwait() // *1
932-
testExceptionAttachedToValueTaskWithAwait() // *1
933-
testExceptionThrownInFinally()
934-
test2ndExceptionThrownInFinally()
935-
testFixedStackWhileLoop() // *2
936-
testFixedStackForLoop() // *2
937-
testTypeInference()
938-
// testNoStackOverflowWithImmediateResult() // *3
939-
testNoStackOverflowWithYieldResult()
915+
let tests = [
916+
testShortCircuitResult
917+
testDelay
918+
testNoDelay
919+
testNonBlocking
920+
testCatching1
921+
testCatching2
922+
testNestedCatching
923+
testTryFinallyHappyPath
924+
testTryFinallySadPath
925+
testTryFinallyCaught
926+
testUsing
927+
testUsingFromValueTask
928+
testUsingSadPath
929+
testForLoop
930+
testForLoopSadPath
931+
testExceptionAttachedToValueTaskWithoutAwait // *1
932+
testExceptionAttachedToValueTaskWithAwait // *1
933+
testExceptionThrownInFinally
934+
test2ndExceptionThrownInFinally
935+
testFixedStackWhileLoop // *2
936+
testFixedStackForLoop // *2
937+
testTypeInference
938+
// testNoStackOverflowWithImmediateResult // *3
939+
testNoStackOverflowWithYieldResult
940940
// (Original note from ValueTaskBuilder, n/a here)
941941
// we don't support TCO, so large tail recursions will stack overflow
942942
// or at least use O(n) heap. but small ones should at least function OK.
943-
testSmallTailRecursion()
944-
testTryOverReturnFrom()
945-
testTryFinallyOverReturnFromWithException()
946-
testTryFinallyOverReturnFromWithoutException()
947-
// testCompatibilityWithOldUnitValueTask() // *4
948-
testAsyncsMixedWithValueTasks() // *5
949-
printfn "Passed all tests!"
950-
with
951-
| exn ->
952-
eprintfn "Exception: %O" exn
943+
testSmallTailRecursion
944+
testTryOverReturnFrom
945+
testTryFinallyOverReturnFromWithException
946+
testTryFinallyOverReturnFromWithoutException
947+
// testCompatibilityWithOldUnitValueTask // *4
948+
testAsyncsMixedWithValueTasks // *5
949+
]
950+
951+
let passed, failed =
952+
tests
953+
|> List.map Choice.protect
954+
|> List.partitionMap (fun x -> x())
955+
956+
let failureMsg = sprintf "Some tests failed: %A" failed + (failed |> String.concat System.Environment.NewLine (sprintfn "Exception: %O"))
957+
958+
Assert.AreEqual (0, List.length failed, failureMsg)
959+
printfn "Passed all TaskBuilder tests (%i) !" (List.length passed)
960+
953961
()
954962

955963
// *1 Test adapted due to errors not being part of the workflow, this is by-design.

0 commit comments

Comments
 (0)