Skip to content

Commit

Permalink
improved layout of error messages - stack trace before error term
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Carlsson authored and rimmius committed Aug 10, 2012
1 parent 975a3d5 commit dab05b7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions lib/eunit/src/eunit_lib.erl
Expand Up @@ -59,8 +59,9 @@ format_exception({Class,Term,Trace}, Depth)
when is_atom(Class), is_list(Trace) ->
case is_stacktrace(Trace) of
true ->
io_lib:format("~w:~P\n~s",
[Class, Term, Depth, format_stacktrace(Trace)]);
io_lib:format("~s**~w:~s",
[format_stacktrace(Trace), Class,
format_term(Term, Depth)]);
false ->
format_term(Term, Depth)
end;
Expand Down Expand Up @@ -103,7 +104,7 @@ format_stacktrace(Trace) ->
format_stacktrace(Trace, "in function", "in call from").

format_stacktrace([{M,F,A,L}|Fs], Pre, Pre1) when is_integer(A) ->
[io_lib:fwrite(" ~s ~w:~w/~w~s\n",
[io_lib:fwrite("~s ~w:~w/~w~s\n",
[Pre, M, F, A, format_stacktrace_location(L)])
| format_stacktrace(Fs, Pre1, Pre1)];
format_stacktrace([{M,F,As,L}|Fs], Pre, Pre1) when is_list(As) ->
Expand All @@ -119,7 +120,7 @@ format_stacktrace([{M,F,As,L}|Fs], Pre, Pre1) when is_list(As) ->
false ->
io_lib:fwrite("~w(~s)", [F,format_arglist(As)])
end,
[io_lib:fwrite(" ~s ~w:~w/~w~s\n called as ~s\n",
[io_lib:fwrite("~s ~w:~w/~w~s\n called as ~s\n",
[Pre,M,F,A,format_stacktrace_location(L),C])
| format_stacktrace(Fs,Pre1,Pre1)];
format_stacktrace([{M,F,As}|Fs], Pre, Pre1) ->
Expand Down Expand Up @@ -181,23 +182,23 @@ format_error({instantiation_failed, Exception}) ->
[format_exception(Exception)]).

error_msg(Title, Fmt, Args) ->
Msg = io_lib:format("::"++Fmt, Args), % gets indentation right
Msg = io_lib:format("**"++Fmt, Args), % gets indentation right
io_lib:fwrite("*** ~s ***\n~s\n\n", [Title, Msg]).

-ifdef(TEST).
format_exception_test_() ->
[?_assertMatch(
"error:dummy"++_,
lists:flatten(
"\nymmud:rorre"++_,
lists:reverse(lists:flatten(
format_exception(try erlang:error(dummy)
catch C:R -> {C, R, erlang:get_stacktrace()}
end))),
end)))),
?_assertMatch(
"error:dummy"++_,
lists:flatten(
"\nymmud:rorre"++_,
lists:reverse(lists:flatten(
format_exception(try erlang:error(dummy, [a])
catch C:R -> {C, R, erlang:get_stacktrace()}
end)))].
end))))].
-endif.

%% ---------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions lib/eunit/src/eunit_tty.erl
Expand Up @@ -213,7 +213,7 @@ print_test_end(Data) ->

print_test_error({error, Exception}, Data) ->
Output = proplists:get_value(output, Data),
fwrite("*failed*\n::~s", [eunit_lib:format_exception(Exception)]),
fwrite("*failed*\n~s", [eunit_lib:format_exception(Exception)]),
case Output of
<<>> ->
fwrite("\n\n");
Expand All @@ -228,7 +228,7 @@ print_test_error({skipped, Reason}, _) ->
format_skipped({module_not_found, M}) ->
io_lib:fwrite("missing module: ~w", [M]);
format_skipped({no_such_function, {M,F,A}}) ->
io_lib:fwrite("no such function: ~w:~w/~w", [M,F,A]).
io_lib:fwrite("no such function: ~w:~w/~w", [M,F,A]).

print_test_cancel(Reason) ->
fwrite(format_cancel(Reason)).
Expand Down

0 comments on commit dab05b7

Please sign in to comment.