Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- before :: IO inner -> TestDefM outers inner result -> TestDefM outers () result
- before_ :: IO () -> TestDefM outers inner result -> TestDefM outers inner result
- beforeWith :: forall outers oldInner newInner result. (oldInner -> IO newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result
- beforeWith' :: HContains outers outer => (outer -> oldInner -> IO newInner) -> TestDefM outers newInner result -> TestDefM outers oldInner result
- after :: (inner -> IO ()) -> TestDefM outers inner result -> TestDefM outers inner result
- after_ :: IO () -> TestDefM outers inner result -> TestDefM outers inner result
- around :: ((inner -> IO ()) -> IO ()) -> TestDefM outers inner result -> TestDefM outers () result
- around_ :: (IO () -> IO ()) -> TestDefM outers inner result -> TestDefM outers inner result
- aroundWith :: forall newInner oldInner outers result. ((newInner -> IO ()) -> oldInner -> IO ()) -> TestDefM outers newInner result -> TestDefM outers oldInner result
- aroundWith' :: forall newInner oldInner outer result (outers :: [Type]). HContains outers outer => ((outer -> newInner -> IO ()) -> outer -> oldInner -> IO ()) -> TestDefM outers newInner result -> TestDefM outers oldInner result
Documentation
:: 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
.
:: 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.
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
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
:: (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
.
:: 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.
:: ((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_
.
:: (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
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.
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_
.
:: 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.