From 7696cc937ddd3b3289748f65ad27b5ffec76e79a Mon Sep 17 00:00:00 2001 From: Andrew Thompson Date: Tue, 28 Jun 2011 23:27:26 -0400 Subject: [PATCH] More tests --- src/error_logger_lager_h.erl | 10 +++--- test/lager_test_backend.erl | 65 ++++++++++++++++++++++++++++++++++-- 2 files changed, 69 insertions(+), 6 deletions(-) diff --git a/src/error_logger_lager_h.erl b/src/error_logger_lager_h.erl index 58561d5..5a53d62 100644 --- a/src/error_logger_lager_h.erl +++ b/src/error_logger_lager_h.erl @@ -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)]) 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|_]}) -> "call to undefined function " ++ format_mfa(MFA); format_reason({bad_return_value, Val}) -> @@ -129,14 +131,14 @@ format_reason({if_clause, [MFA|_]}) -> format_reason({{try_clause, Val}, [MFA|_]}) -> io_lib:format("no try clause matching ~w in ", [Val]) ++ format_mfa(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|_]}) -> io_lib:format("no match of right hand value ~w in ", [Val]) ++ format_mfa(MFA); %format_reason({system_limit, -format_reason({badarg, [MFA|_]}) -> +format_reason({badarg, [MFA,MFA2|_]}) -> 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 "bad argument in " ++ format_mfa(MFA) diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 18cd900..174605a 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -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])), ?assertEqual(Expected, lists:flatten(Msg)) 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 } - - ] }.