I'm write a test with EUnit, but not anything exception detail output in console.
Run this module:exp_test() in the Erlang Shell output following
** exception error: bad argument in an arithmetic expression
in function exp_test:'-exp_test/0-fun-0-'/1 (src/test/eunit/xxx_test.erl, line 8)
But in EUnit output following
> xxx_test: exp_test...*failed*
EUnit not output anything exception trace info
Im trying the verbose config in eunit, but no effect.
I want to output some exception detail in eunit test result.
Eunit is quite old and while it is officially maintained by the OTP team at Ericsson, it is usually uncared for. Eunit currently has the bad habit of eating up stack traces, and hasn't been updated for R15's line numbers in exceptions.
I wouldn't argue that "that's how it's supposed to work". No sane test tool should hide exception details and line numbers for you.
The problem seems to be that the version of eunit shipped with R15 does not understand the new stack trace format in R15. This has been fixed in the development version of eunit: github.com/richcarl/eunit
Eshell V5.10 (abort with ^G) 1> eunit:test(fun() -> (fun() -> exit(foo), ok end)() end). erl_eval: expr...*failed* in function erl_eval:do_apply/6 (erl_eval.erl, line 576) in call from erl_eval:exprs/5 (erl_eval.erl, line 118) **exit:foo
I hope this will make it into the next release of OTP R15.
This is a known problem in eunit as released in R15B and R15B01. This has been fixed in release R15B02. If you're stuck with an earlier version, you can download and apply a patch:
You can fix the problem in your local installation by recompiling the affected module:
Download and unpack the Erlang/OTP sources, if you don't have them already.
wget http://www.erlang.org/download/otp_src_R15B01.tar.gz tar xzf otp_src_R15B01.tar.gz cd otp_src_R15B01
Download and apply the patch.
wget -O eunit-stacktrace.patch https://github.com/erlang/otp/commit/73b94a990bb91fd263dace4ccbaef6ff727a9637.patch patch -p1 < eunit-stacktrace.patch
cd lib/eunit erlc -o ebin -I include src/eunit_lib.erl
Copy the new
eunit_lib.beam over the old one (usually somewhere below
ls /usr/local/lib/erlang/lib/eunit-2.2.2/ebin/ # check that eunit_lib.beam is actually there sudo cp ebin/eunit_lib.beam /usr/local/lib/erlang/lib/eunit-2.2.2/ebin/
A trick I like to use is
?debugVal(catch expr) where expr is either a
begin end block
or a call to the failing function. For example,
?debugVal(catch begin 1 = 2 end) will output a stacktrace in your tests.