Skip to content

Commit

Permalink
Short-circuit SatisfyAny after first success
Browse files Browse the repository at this point in the history
  • Loading branch information
Christer van der Meeren committed Sep 8, 2023
1 parent 9e86d6f commit 46cbad1
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions src/Faqt/HigherOrderAssertions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ type HigherOrderAssertions =
use _ = t.Assert(true)
let assertions = assertions |> Seq.toArray

let exceptions =
assertions
|> Array.choose (fun f ->
try
f t.Subject |> ignore
None
with :? AssertionFailedException as ex ->
Some ex
)

if assertions.Length > 0 && exceptions.Length = assertions.Length then
t
.With("Failures", exceptions |> Array.map (fun ex -> ex.FailureData))
.Fail(because)
if assertions.Length > 0 then
let failures = ResizeArray()
let mutable succeeded = false

for f in assertions do
if not succeeded then
try
f t.Subject |> ignore
succeeded <- true
with :? AssertionFailedException as ex ->
failures.Add ex.FailureData

if not succeeded then
t.With("Failures", failures).Fail(because)

And(t)

Expand Down

0 comments on commit 46cbad1

Please sign in to comment.