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 assertion function types for return types and monad #17

Closed
osa1 opened this issue Feb 22, 2017 · 4 comments
Closed

Generalize assertion function types for return types and monad #17

osa1 opened this issue Feb 22, 2017 · 4 comments

Comments

@osa1
Copy link

osa1 commented Feb 22, 2017

Literally every single test suite I work on needs these two:

  • Assertion functions that work in any MonadIO. With this I can use same assertion functions in different test monads, e.g. the monad in hspec-webdriver.

  • Assertion functions with generalized return value. Something like

type Assertion' a = IO a

assertFailure :: HasCallStack => String -> Assertion' a

Now I can use this in cases like

x <- case doX of
       T1 -> assertFailure "doX returned T1!"
       T2 x -> return x

Since these additions are so small I usually end up copying same code snippets to every single project I work on. I think these would be great additions to HUnit and other people would also benefit it.

@sol
Copy link
Member

sol commented Feb 23, 2017

For assertions/expectations generalized to MonadIO you can use hspec-expectations-lifted.

It's not suitable as a default because it hurts type inference in Hspec.

@sol
Copy link
Member

sol commented Feb 23, 2017

I'm ok with changing the type of assertFailure:

assertFailure :: HasCallStack => String -> IO a

@osa1
Copy link
Author

osa1 commented Feb 23, 2017

Nice, I didn't know about hspec-expectations-lifted, thanks.

You originally wrote "PR please" but do you still want a PR or are you going to do this yourself?

@sol
Copy link
Member

sol commented Feb 23, 2017

Yes, PR please.

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

No branches or pull requests

2 participants