Skip to content

Commit

Permalink
Fix tests. and 2 places MFAs werent handling the new 4th parameter
Browse files Browse the repository at this point in the history
Tests now pass on both R15B and R14B03.
  • Loading branch information
Vagabond committed Apr 1, 2012
1 parent 68065c1 commit 807a847
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/error_logger_lager_h.erl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ format_offender(Off) ->
format_reason({'function not exported', [{M, F, A},MFA|_]}) ->
["call to undefined function ", format_mfa({M, F, length(A)}),
" from ", format_mfa(MFA)];
format_reason({'function not exported', [{M, F, A, _Props},MFA|_]}) ->
%% R15 line numbers
["call to undefined function ", format_mfa({M, F, length(A)}),
" from ", format_mfa(MFA)];
format_reason({undef, [MFA|_]}) ->
["call to undefined function ", format_mfa(MFA)];
format_reason({bad_return_value, Val}) ->
Expand Down Expand Up @@ -227,6 +231,9 @@ format_reason({system_limit, [{M, F, _}|_] = Trace}) ->
["system limit: ", Limit];
format_reason({badarg, [MFA,MFA2|_]}) ->
case MFA of
{_M, _F, A, _Props} when is_list(A) ->
%% R15 line numbers
["bad argument in call to ", format_mfa(MFA), " in ", format_mfa(MFA2)];
{_M, _F, A} when is_list(A) ->
["bad argument in call to ", format_mfa(MFA), " in ", format_mfa(MFA2)];
_ ->
Expand Down
45 changes: 32 additions & 13 deletions test/lager_test_backend.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ count_ignored() ->
flush() ->
gen_event:call(lager_event, ?MODULE, flush).

has_line_numbers() ->
%% are we R15 or greater
Rel = erlang:system_info(otp_release),
{match, [Major]} = re:run(Rel, "^R(\\d+)[A|B](|0(\\d))$", [{capture, [1], list}]),
list_to_integer(Major) >= 15.

not_running_test() ->
?assertEqual({error, lager_not_running}, lager:log(info, self(), "not running")).

Expand Down Expand Up @@ -241,6 +247,18 @@ crash(Type) ->
_ = gen_event:which_handlers(error_logger),
ok.

test_body(Expected, Actual, File) ->
case has_line_numbers() of
true ->
FileLine = string:substr(Actual, length(Expected)+1),
Body = string:substr(Actual, 1, length(Expected)),
?assertEqual(Expected, Body),
?assertEqual(File, string:substr(FileLine, 3, length(File)));
false ->
?assertEqual(Expected, Actual)
end.


error_logger_redirect_crash_test_() ->
{foreach,
fun() ->
Expand Down Expand Up @@ -276,6 +294,7 @@ error_logger_redirect_crash_test_() ->
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad return value: bleh", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
%test_body(Expected, lists:flatten(msg), "test/crash.erl")
end
},
{"bad return value with string",
Expand All @@ -293,7 +312,7 @@ error_logger_redirect_crash_test_() ->
crash(case_clause),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no case clause matching {} in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"case clause string",
Expand All @@ -302,7 +321,7 @@ error_logger_redirect_crash_test_() ->
crash(case_clause_string),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no case clause matching \"crash\" in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"function clause",
Expand All @@ -311,7 +330,7 @@ error_logger_redirect_crash_test_() ->
crash(function_clause),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no function clause matching crash:function({})", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"if clause",
Expand All @@ -320,7 +339,7 @@ error_logger_redirect_crash_test_() ->
crash(if_clause),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no true branch found while evaluating if expression in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"try clause",
Expand All @@ -329,7 +348,7 @@ error_logger_redirect_crash_test_() ->
crash(try_clause),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no try clause matching [] in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"undefined function",
Expand All @@ -338,7 +357,7 @@ error_logger_redirect_crash_test_() ->
crash(undef),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: call to undefined function crash:booger/0 from crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"bad math",
Expand All @@ -347,7 +366,7 @@ error_logger_redirect_crash_test_() ->
crash(badarith),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad arithmetic expression in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"bad match",
Expand All @@ -356,7 +375,7 @@ error_logger_redirect_crash_test_() ->
crash(badmatch),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no match of right hand value {} in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"bad arity",
Expand All @@ -365,7 +384,7 @@ error_logger_redirect_crash_test_() ->
crash(badarity),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: fun called with wrong arity of 1 instead of 3 in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"bad arg1",
Expand All @@ -374,7 +393,7 @@ error_logger_redirect_crash_test_() ->
crash(badarg1),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad argument in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"bad arg2",
Expand All @@ -383,7 +402,7 @@ error_logger_redirect_crash_test_() ->
crash(badarg2),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad argument in call to erlang:iolist_to_binary([\"foo\",bar]) in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
},
{"noproc",
Expand All @@ -401,7 +420,7 @@ error_logger_redirect_crash_test_() ->
crash(badfun),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: bad function booger in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/crash.erl")
end
}

Expand Down Expand Up @@ -699,7 +718,7 @@ error_logger_redirect_test_() ->
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~p CRASH REPORT Process ~p with 0 neighbours crashed with reason: no function clause matching special_process:foo(bar)",
[Pid, Pid])),
?assertEqual(Expected, lists:flatten(Msg))
test_body(Expected, lists:flatten(Msg), "test/special_process.erl")
end
},
{"messages should not be generated if they don't satisfy the threshold",
Expand Down

0 comments on commit 807a847

Please sign in to comment.