-
Notifications
You must be signed in to change notification settings - Fork 23
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
Surprising behaviour of buildTestBracketed #3
Comments
Actually, the problem is larger then this. When there are multiple tests constructed with buildTestBracketed, all their setup functions are run at the start, rather than one by one when each test is run. |
I'll see if I can come up with a patch. |
Ok, so I did look at this, but it's not clear to me how to implement this without making a lot of invasive changes. Ideally, I'd like something like bracketTest :: IO a -> (a -> IO b) -> (a -> Test) -> Test I thought I might be able to implement this much like data BracketTest t = forall a b. BT (IO a) (a -> IO b) (a -> t) and I can give a bracketTest :: IO a -> (a -> IO b) -> (a -> Test) -> Test
bracketTest (Test tn t) = ??? (Note that if we did have something like this, I am now using this workaround: bracketTest :: forall a. IO a -> (a -> IO ()) -> (IO a -> Test) -> Test
bracketTest setup cleanup test = Test.buildTestBracketed $ do
setupMVar <- newMVar Nothing
let runSetup :: IO a
runSetup = modifyMVar setupMVar $ \didSetup ->
case didSetup of
Just a -> return (didSetup, a)
Nothing -> setup >>= \a -> return (Just a, a)
runCleanup :: IO ()
runCleanup = modifyMVar_ setupMVar $ \didSetup ->
case didSetup of
Just st -> do cleanup st ; return Nothing
Nothing -> return Nothing
return (test runSetup, runCleanup) which works without any modifications to |
Suppose we we something like
main = defaultMain [testA, testB]
where
testA
is constructed with buildTestBracketed. If we run the test suite usingthen the IO actions of
testA
will still be executed.The text was updated successfully, but these errors were encountered: