assert_raise with bad message/1 implementation

137 views
Skip to first unread message

Michał Muskała

unread,
Jun 16, 2017, 8:56:36 AM6/16/17
to elixir-l...@googlegroups.com
Hello everybody,

Right now, when using assert_raise/2 (without passing the message) the test succeeds even if the exception itself has bad implementation of the message/1 function and raises.

I propose that assert_raise should fail whenever such a broken exception implementation is encountered. This should allow catching additional bugs in test suites.

Michał.

José Valim

unread,
Jun 16, 2017, 9:02:45 AM6/16/17
to elixir-l...@googlegroups.com
Great catch. Yes, let's always invoke Exception.message on it, even if you don't match on it.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4b610622-28db-4025-95c4-0cfe7d9bbdf1%40Spark.
For more options, visit https://groups.google.com/d/optout.

Michał Muskała

unread,
Jun 16, 2017, 9:10:45 AM6/16/17
to elixir-l...@googlegroups.com
I don't think running Exception.message will cut it, since it will output a string that the message/1 implementation failed. Ideally, I wish the test would fail in that case.

One solution would be to call error_module.message(error) manually, but this would mean ex_unit needs to replicate logic from Exception.message. Alternative would be to pattern match on the string returned from Exception.message, but this seems even more error-prone.

Michał.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4KS0XvaSSAjtr3pkD3Edi6R%2B6yrASkHfJN99CZXUiGf-Q%40mail.gmail.com.

José Valim

unread,
Jun 16, 2017, 9:13:30 AM6/16/17
to elixir-l...@googlegroups.com
"error_module.message(error)" sounds good, yes!



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Fri, Jun 16, 2017 at 3:08 PM, Michał Muskała <mic...@muskala.eu> wrote:
I don't think running Exception.message will cut it, since it will output a string that the message/1 implementation failed. Ideally, I wish the test would fail in that case.

One solution would be to call error_module.message(error) manually, but this would mean ex_unit needs to replicate logic from Exception.message. Alternative would be to pattern match on the string returned from Exception.message, but this seems even more error-prone.

Michał.

On 16 Jun 2017, 15:02 +0200, José Valim <jose....@plataformatec.com.br>, wrote:
Great catch. Yes, let's always invoke Exception.message on it, even if you don't match on it.



José Valim
Skype: jv.ptec
Founder and Director of R&D

On Fri, Jun 16, 2017 at 2:54 PM, Michał Muskała <mic...@muskala.eu> wrote:
Hello everybody,

Right now, when using assert_raise/2 (without passing the message) the test succeeds even if the exception itself has bad implementation of the message/1 function and raises.

I propose that assert_raise should fail whenever such a broken exception implementation is encountered. This should allow catching additional bugs in test suites.

Michał.
--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/4b610622-28db-4025-95c4-0cfe7d9bbdf1%40Spark.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscribe@googlegroups.com.

Michał Muskała

unread,
Jun 16, 2017, 9:17:52 AM6/16/17
to elixir-l...@googlegroups.com
Great, I'll work on this.

Michał.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4%2BthkD7q-eqgj2EZKWXs68H8HbbkYQ%3DfYqH%2BBzEZiEsGg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages