[erlang-questions] clarify: EUnit ?assertError vs try/catch

Samuel <>
Tue Jan 19 09:41:51 CET 2016


Note that the error you are getting is not badmatch, but {badmatch,
Stuff} (stuff being the right side of the failed match). In your first
example the tests passes because you match against {badmatch, _}, but
in the second you expect just the atom badmatch. If you do
?assertError({badmatch, _}, ...) it should work.

On 19 January 2016 at 09:22, Bengt Kleberg <> wrote:
> Greetings,
>
> How should I use EUnit ?assertError to replace try/catch?
> I have erl -version
> Erlang (SMP,ASYNC_THREADS) (BEAM) emulator version 5.10.4.1
> (I think it is R16B03)
>
>
> This EUnit test case pass:
>             try
>             apython( [{python_init, MFA}] ),
>             erlang:throw( fail )
>
>             catch error:{badmatch, _} -> ok
>
>             end
>
>
> When I try
>     ?assertError( badmatch, apython([{python_init, MFA}]) )
>
> it fails with:
> **error:{assertException_failed,
>     [{module,ise_scheduler_gen_server_tests},
>      {line,424},
>      {expression,"apython ( [ { python_init , MFA } ] )"},
>      {pattern,"{ error , badmatch , [...] }"},
>      {unexpected_exception,
>          {error,
>              {badmatch,
>                  {error,
>                      {function_clause,
> [{ise_scheduler_gen_server,...},{...}|...]}}},
> [{ise_scheduler_gen_server_tests,apython,2,[{file,...},{...}]},
> {ise_scheduler_gen_server_tests,'-python_fail_test_/0-fun-0-',
>                   0,
>                   [{...}|...]},
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions



-- 
Samuel


More information about the erlang-questions mailing list