Skip to content

Commit f69e481

Browse files
committed
+ Additional tests for tryFinally
1 parent 8fc7c68 commit f69e481

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/FSharpPlus.Tests/Task.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,28 @@ module Task =
242242
CollectionAssert.AreNotEquivalent (t123.Exception.InnerExceptions, t123''.Exception.InnerExceptions, "Task.map3 (fun x y z -> [x; y; z]) t1 t2 t3 is not the same as sequence [t1; t2; t3]")
243243

244244

245+
// This module contains tests for ComputationExpression not covered by the below TaskBuilderTests module
246+
module ComputationExpressionTests =
247+
open System
248+
open System.Threading.Tasks
249+
open NUnit.Framework
250+
open FSharpPlus
251+
open FSharpPlus.Tests.Helpers
252+
253+
[<Test>]
254+
let testTryFinally () =
255+
let mutable ran = false
256+
let t = monad' {
257+
try
258+
do! Task.FromException<unit> (exn "This is a failed task")
259+
finally
260+
ran <- true
261+
return 1
262+
}
263+
t.Wait()
264+
require ran "never ran"
265+
require (not (isNull t.Exception)) "didn't capture exception"
266+
245267
module TaskBuilderTests =
246268

247269
// Tests for TaskBuilder.fs

tests/FSharpPlus.Tests/ValueTask.fs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,28 @@ module ValueTask =
205205
CollectionAssert.AreNotEquivalent (t123.Exception.InnerExceptions, t123''.Exception.InnerExceptions, "ValueTask.map3 (fun x y z -> [x; y; z]) t1 t2 t3 is not the same as sequence [t1; t2; t3]")
206206

207207

208+
// This module contains tests for ComputationExpression not covered by the below TaskBuilderTests module
209+
module ComputationExpressionTests =
210+
open System
211+
open System.Threading.Tasks
212+
open NUnit.Framework
213+
open FSharpPlus
214+
open FSharpPlus.Tests.Helpers
215+
216+
[<Test>]
217+
let testTryFinally () =
218+
let mutable ran = false
219+
let t = monad' {
220+
try
221+
do! ValueTask.FromException<unit> (exn "This is a failed task")
222+
finally
223+
ran <- true
224+
return 1
225+
}
226+
t.Wait()
227+
require ran "never ran"
228+
require (not (isNull t.Exception)) "didn't capture exception"
229+
208230
module ValueTaskBuilderTests =
209231

210232
// Same tests, same note as in Task.fs about these tests

0 commit comments

Comments
 (0)