[Haskell-beginners] How to test "error"?

Michele Alzetta michele.alzetta at gmail.com
Tue Jun 11 07:43:53 UTC 2019


As beginner to beginner, so take this with a kg of salt  ... isn't what
you're looking for a construction of the Either sort?

That way you get Right and Left and you can check for Left.





Il giorno mar 11 giu 2019 alle ore 05:45 Hilco Wijbenga <
hilco.wijbenga at gmail.com> ha scritto:

> Hi all,
>
> I have a function that may call "error" if the input represents a bug
> in my program. (Think something like PositiveInt -1; this should never
> happen so Maybe or Either are not applicable.)
>
> f :: Whatever
> f = error "This should never happen."
>
> spec :: Spec
> spec =
>     describe "f" $
>         it "error" $
>             return f `shouldThrow` anyErrorCall
>
> The above does not work, I get "did not get expected exception:
> ErrorCall". Using "anyException" doesn't work either.
>
> How can I write a test for this? And (assuming I can get the test to
> work), how do I check that the error message is indeed what I expect?
>
> Cheers,
> Hilco
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20190611/45e2c350/attachment.html>


More information about the Beginners mailing list