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

Generalize hunit assertions to MonadIO? #320

Open
brandon-leapyear opened this issue Dec 20, 2021 · 1 comment
Open

Generalize hunit assertions to MonadIO? #320

brandon-leapyear opened this issue Dec 20, 2021 · 1 comment

Comments

@brandon-leapyear
Copy link

Curious what people's thoughts are on making tasty-hunit functions work on any MonadIO. It's not uncommon for me to write hunit tests with assertions interspersed through my monadic code, e.g.

testCase "Check database operations" $
  runMyMonad $ do
    x <- doThing1
    liftIO $ x @?= 100
    x2 <- doThing2
    liftIO $ x2 @?= "hello world"

It would be a minor improvement to be able to do simply

testCase "Check database operations" $
  runMyMonad $ do
    x <- doThing1
    x @?= 100
    x2 <- doThing2
    x2 @?= "hello world"

I'm willing to open a PR; the only downside I can see is making the Haddock docs a bit less straightforward (instead of returning a simple Assertion, it would now return MonadIO m => m ()).

@UnkindPartition
Copy link
Owner

My main concern would be mainly introducing ambiguous types, esp. if it breaks existing code. It should be fine with the "standard" usage of testCase "name" $ 2 @?= 2 because testCase forces the m to IO, and also with lifting it using liftIO as in your own example. So I guess the risk is not that high.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants