UnkindPartition / tasty

Modern and extensible testing framework for Haskell
640 stars 110 forks source link

Generalize hunit assertions to MonadIO? #320

Open brandon-leapyear opened 2 years ago

brandon-leapyear commented 2 years ago

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 commented 2 years ago

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.