sydtest-0.13.0.4: A modern testing framework for Haskell with good defaults and advanced testing features.
Safe HaskellSafe-Inferred
LanguageHaskell2010

Test.Syd.Def.Around

Synopsis

Documentation

before Source #

Arguments

:: IO inner

The function to run before every test, to produce the inner resource

-> TestDefM outers inner result 
-> TestDefM outers () result 

Run a custom action before every spec item, to set up an inner resource inner.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

before_ Source #

Arguments

:: IO ()

The function to run before every test

-> TestDefM outers inner result 
-> TestDefM outers inner result 

Run a custom action before every spec item without setting up any inner resources.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

beforeWith :: forall outers oldInner newInner result. (oldInner -> IO newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result Source #

Run a custom action before every spec item, to set up an inner resource newInner using the previously set up resource oldInner

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

beforeWith' :: HContains outers outer => (outer -> oldInner -> IO newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result Source #

Run a custom action before every spec item, to set up an inner resource newInner using the previously set up resource oldInner and potentially any of the outer resources

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

after Source #

Arguments

:: (inner -> IO ())

The function to run after every test, using the inner resource

-> TestDefM outers inner result 
-> TestDefM outers inner result 

Run a custom action after every spec item, using the inner resource c.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

after_ Source #

Arguments

:: IO ()

The function to run after every test

-> TestDefM outers inner result 
-> TestDefM outers inner result 

Run a custom action after every spec item without using any inner resources.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

around Source #

Arguments

:: ((inner -> IO ()) -> IO ())

The function to provide the inner resource around every test

-> TestDefM outers inner result 
-> TestDefM outers () result 

Run a custom action before and/or after every spec item, to provide access to an inner resource c.

See the FOOTGUN note in the docs for around_.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

around_ Source #

Arguments

:: (IO () -> IO ())

The function to wrap every test with

-> TestDefM outers inner result 
-> TestDefM outers inner result 

Run a custom action before and/or after every spec item without accessing any inner resources.

It is important that the wrapper function that you provide runs the action that it gets _exactly once_.

FOOTGUN

Expand

This combinator gives the programmer a lot of power. In fact, it gives the programmer enough power to break the test framework. Indeed, you can provide a wrapper function that just _doesn't_ run the function like this:

spec :: Spec
spec = do
   let don'tDo :: IO () -> IO ()
       don'tDo _ = pure ()
   around_ don'tDo $ do
     it "should pass" True

During execution, you'll then get an error like this:

thread blocked indefinitely in an MVar operation

The same problem exists when using aroundAll_.

The same thing will go wrong if you run the given action more than once like this:

spec :: Spec
spec = do
   let doTwice :: IO () -> IO ()
       doTwice f = f >> f
   around_ doTwice $ do
     it "should pass" True

Note: If you're interested in fixing this, talk to me, but only after GHC has gotten impredicative types because that will likely be a requirement.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

aroundWith :: forall newInner oldInner outers result. ((newInner -> IO ()) -> oldInner -> IO ()) -> TestDefM outers newInner result -> TestDefM outers oldInner result Source #

Run a custom action before and/or after every spec item, to provide access to an inner resource c while using the inner resource d.

See the FOOTGUN note in the docs for around_.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331

aroundWith' Source #

Arguments

:: forall newInner oldInner outer result (outers :: [Type]). HContains outers outer 
=> ((outer -> newInner -> IO ()) -> outer -> oldInner -> IO ())

The function that provides the new inner resource using the old resource. It can also use and modify the outer resource

-> TestDefM outers newInner result 
-> TestDefM outers oldInner result 

Run a custom action around every spec item, to provide access to an inner resource newInner while using the inner resource oldInner and any outer resource available.

Note that this function turns off shrinking. See https://github.com/nick8325/quickcheck/issues/331