Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add expectFailure combinator #72

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

palas
Copy link
Contributor

@palas palas commented Sep 24, 2024

This PR adds a new combinator that when applied to a property it will invert its behaviour:

  • If the property fails, the new property will pass
  • If the property passes, the new property will fail

This is useful for writing negative tests

See the following PR for an example of usage: IntersectMBO/cardano-cli#910

Based on equivalent QuickCheck combinator: https://hackage.haskell.org/package/QuickCheck-2.15.0.1/docs/Test-QuickCheck.html#v:expectFailure

@@ -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 -> Integration ()
expectFailure prop = GHC.withFrozenCallStack $ do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be useful to be able to investigate the failure and ascertain if that's the expected failure or an accidental one.

@palas palas force-pushed the add-expect-failure branch from 8ea37f3 to 873fcf3 Compare October 16, 2024 13:24
@palas palas force-pushed the add-expect-failure branch from 15d75ef to 4e739de Compare October 16, 2024 14:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants