@ -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 " ) ) .
@ -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 ( ) - >
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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 " ,
@ -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
}
@ -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 " ,