Browse Source

More tests

pull/4/head
Andrew Thompson 14 years ago
parent
commit
7696cc937d
2 changed files with 69 additions and 6 deletions
  1. +6
    -4
      src/error_logger_lager_h.erl
  2. +63
    -2
      test/lager_test_backend.erl

+ 6
- 4
src/error_logger_lager_h.erl View File

@ -116,6 +116,8 @@ format_offender(Off) ->
io_lib:format("with name ~w started with ~s at ~w", [Name, MFA, proplists:get_value(pid, Off)]) io_lib:format("with name ~w started with ~s at ~w", [Name, MFA, proplists:get_value(pid, Off)])
end. end.
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({undef, [MFA|_]}) -> format_reason({undef, [MFA|_]}) ->
"call to undefined function " ++ format_mfa(MFA); "call to undefined function " ++ format_mfa(MFA);
format_reason({bad_return_value, Val}) -> format_reason({bad_return_value, Val}) ->
@ -129,14 +131,14 @@ format_reason({if_clause, [MFA|_]}) ->
format_reason({{try_clause, Val}, [MFA|_]}) -> format_reason({{try_clause, Val}, [MFA|_]}) ->
io_lib:format("no try clause matching ~w in ", [Val]) ++ format_mfa(MFA); io_lib:format("no try clause matching ~w in ", [Val]) ++ format_mfa(MFA);
format_reason({badarith, [MFA|_]}) -> format_reason({badarith, [MFA|_]}) ->
"bad arithmetic expression in function " ++ format_mfa(MFA);
"bad arithmetic expression in " ++ format_mfa(MFA);
format_reason({{badmatch, Val}, [MFA|_]}) -> format_reason({{badmatch, Val}, [MFA|_]}) ->
io_lib:format("no match of right hand value ~w in ", [Val]) ++ format_mfa(MFA); io_lib:format("no match of right hand value ~w in ", [Val]) ++ format_mfa(MFA);
%format_reason({system_limit, %format_reason({system_limit,
format_reason({badarg, [MFA|_]}) ->
format_reason({badarg, [MFA,MFA2|_]}) ->
case MFA of case MFA of
{_, _, A} when is_list(A) ->
"bad argument in call to " ++ format_mfa(MFA);
{_M, _F, A} when is_list(A) ->
"bad argument in call to " ++ format_mfa(MFA) ++ " in " ++ format_mfa(MFA2);
_ -> _ ->
%% seems to be generated by a bad call to a BIF %% seems to be generated by a bad call to a BIF
"bad argument in " ++ format_mfa(MFA) "bad argument in " ++ format_mfa(MFA)

+ 63
- 2
test/lager_test_backend.erl View File

@ -251,9 +251,70 @@ error_logger_redirect_test_() ->
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no try clause matching [] in crash:handle_call/3", [Pid])), 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)) ?assertEqual(Expected, lists:flatten(Msg))
end end
},
{"undefined function",
fun() ->
Pid = whereis(crash),
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))
end
},
{"bad math",
fun() ->
Pid = whereis(crash),
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))
end
},
{"bad match",
fun() ->
Pid = whereis(crash),
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))
end
},
{"bad arity",
fun() ->
Pid = whereis(crash),
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))
end
},
{"bad arg1",
fun() ->
Pid = whereis(crash),
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))
end
},
{"bad arg2",
fun() ->
Pid = whereis(crash),
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([[102,111,111],bar]) in crash:handle_call/3", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
},
{"noproc",
fun() ->
Pid = whereis(crash),
crash(noproc),
{_, _, Msg} = pop(),
Expected = lists:flatten(io_lib:format("[error] ~w gen_server crash terminated with reason: no such process or port in call to gen_event:call(foo, bar, baz)", [Pid])),
?assertEqual(Expected, lists:flatten(Msg))
end
} }
] ]
}. }.

Loading…
Cancel
Save