Reputation: 3749
Tasty supports resources, so I can acquire resource, test some data related to this resource (purely) and to release the resource. But how to do some IO actions in my test function?
This is the example from the documentation:
import Test.Tasty
import Test.Tasty.HUnit
-- assumed defintions
data Foo
acquire :: IO Foo
release :: Foo -> IO ()
testWithFoo :: Foo -> Assertion
(acquire, release, testWithFoo) = undefined
main = do
defaultMain $
withResource acquire release tests
tests :: IO Foo -> TestTree
tests getResource =
testGroup "Tests"
[ testCase "x" $ getResource >>= testWithFoo
]
So my resource is some connection (like socket). And I need to make API call in the testWithFoo
, so it can not return just Assertion
but it must be in IO
. How to do it? Or tasty support only pure tests?
Upvotes: 0
Views: 367
Reputation: 957
According to the tasty-hunit documentation, Assertion
is a type synonym for IO ()
.
type Assertion = IO ()
This means that you can make your API call inside the test without issue.
Upvotes: 1