Skip to content

Commit

Permalink
Add expectFailure combinator
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Oct 16, 2024
1 parent 2a7d307 commit 56f3eed
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Hedgehog/Extras/Test/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module Hedgehog.Extras.Test.Base

, failWithCustom
, failMessage
, expectFailure

, assertByDeadlineM
, assertByDeadlineIO
Expand Down Expand Up @@ -140,6 +141,14 @@ failWithCustom cs mdiff msg = liftTest $ mkTest (Left $ H.Failure (getCaller cs)
failMessage :: MonadTest m => CallStack -> String -> m a
failMessage cs = failWithCustom cs Nothing

-- | Invert the behavior of a property: success becomes failure and vice versa.
expectFailure :: HasCallStack => H.TestT IO m -> H.PropertyT IO ()
expectFailure prop = GHC.withFrozenCallStack $ do
(res, _) <- H.evalIO $ H.runTestT prop
case res of
Left _ -> pure () -- Property failed so we succeed
_ -> H.failWith Nothing "Expected the test to fail but it passed" -- Property passed but we expected a failure

-- | Create a workspace directory which will exist for at least the duration of
-- the supplied block.
--
Expand Down

0 comments on commit 56f3eed

Please sign in to comment.