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

Bengt Kleberg bengt.kleberg@REDACTED
Tue Jan 19 09:22:48 CET 2016


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,
                   [{...}|...]},




More information about the erlang-questions mailing list