Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. How to test "error"? (Hilco Wijbenga)
2. Re: How to test "error"? (Michele Alzetta)
3. Re: How to test "error"? (Francesco Ariis)
----------------------------------------------------------------------
Message: 1
Date: Mon, 10 Jun 2019 20:44:30 -0700
From: Hilco Wijbenga <[email protected]>
To: Haskell Beginners <[email protected]>
Subject: [Haskell-beginners] How to test "error"?
Message-ID:
<CAE1pOi3bKP3KmOZteQMGYmkfx1o=awdqjyq17yw-slyzkke...@mail.gmail.com>
Content-Type: text/plain; charset="UTF-8"
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
------------------------------
Message: 2
Date: Tue, 11 Jun 2019 09:43:53 +0200
From: Michele Alzetta <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] How to test "error"?
Message-ID:
<CANhs-xCpDWcAmRVorfQwaJq=xmqbrojnpj-dwm4ub_4sqk1...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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 <
[email protected]> 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
> [email protected]
> 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-0001.html>
------------------------------
Message: 3
Date: Tue, 11 Jun 2019 11:39:09 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] How to test "error"?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
Hello Hilco,
On Mon, Jun 10, 2019 at 08:44:30PM -0700, Hilco Wijbenga wrote:
> f :: Whatever
> f = error "This should never happen."
>
> spec :: Spec
> spec =
> describe "f" $
> it "error" $
> return f `shouldThrow` anyErrorCall
import qualified Control.Exception as E
and
E.evaluate tt' f `shouldThrow` anyErrorCall
should work. Does this work?
-F
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 132, Issue 3
*****************************************