From 7662a8040d5427907c041ca8e682fe09f6f17d26 Mon Sep 17 00:00:00 2001 From: Mark Allen Date: Tue, 29 Mar 2016 16:39:54 -0500 Subject: [PATCH] Add comments and change binding name for clarity --- test/lager_test_backend.erl | 42 +++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/test/lager_test_backend.erl b/test/lager_test_backend.erl index 2616191..d4141b4 100644 --- a/test/lager_test_backend.erl +++ b/test/lager_test_backend.erl @@ -1127,50 +1127,66 @@ error_logger_redirect_test_() -> end }, {"warning messages with unicode characters in Args are printed", + %% The next 4 tests need to store the current value of + %% `error_logger:warning_map/0' into a process dictionary + %% key `warning_map' so that the error message level used + %% to process the log messages will match what lager + %% expects. + %% + %% The atom returned by `error_logger:warning_map/0' + %% changed between OTP 17 and 18 (and later releases) + %% + %% `warning_map' is consumed in the `test/sync_error_logger.erl' + %% module. The default message level used in sync_error_logger + %% was fine for OTP releases through 17 and then broke + %% when 18 was released. By storing the expected value + %% in the process dictionary, sync_error_logger will + %% use the correct message level to process the + %% messages and these tests will no longer + %% break. fun(Sink) -> - Map = error_logger:warning_map(), - put(warning_map, Map), + Lvl = error_logger:warning_map(), + put(warning_map, Lvl), sync_error_logger:warning_msg("~ts", ["Привет!"]), _ = gen_event:which_handlers(error_logger), {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Map),Level), + ?assertEqual(lager_util:level_to_num(Lvl),Level), ?assertEqual(self(),proplists:get_value(pid,Metadata)), ?assertEqual("Привет!", lists:flatten(Msg)) end }, - {"warning messages are printed at the correct level", fun(Sink) -> - Map = error_logger:warning_map(), - put(warning_map, Map), + Lvl = error_logger:warning_map(), + put(warning_map, Lvl), sync_error_logger:warning_msg("doom, doom has come upon you all"), _ = gen_event:which_handlers(error_logger), {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Map),Level), + ?assertEqual(lager_util:level_to_num(Lvl),Level), ?assertEqual(self(),proplists:get_value(pid,Metadata)), ?assertEqual("doom, doom has come upon you all", lists:flatten(Msg)) end }, {"warning reports are printed at the correct level", fun(Sink) -> - Map = error_logger:warning_map(), - put(warning_map, Map), + Lvl = error_logger:warning_map(), + put(warning_map, Lvl), sync_error_logger:warning_report([{i, like}, pie]), _ = gen_event:which_handlers(error_logger), {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Map),Level), + ?assertEqual(lager_util:level_to_num(Lvl),Level), ?assertEqual(self(),proplists:get_value(pid,Metadata)), ?assertEqual("i: like, pie", lists:flatten(Msg)) end }, {"single term warning reports are printed at the correct level", fun(Sink) -> - Map = error_logger:warning_map(), - put(warning_map, Map), + Lvl = error_logger:warning_map(), + put(warning_map, Lvl), sync_error_logger:warning_report({foolish, bees}), _ = gen_event:which_handlers(error_logger), {Level, _, Msg,Metadata} = pop(Sink), - ?assertEqual(lager_util:level_to_num(Map),Level), + ?assertEqual(lager_util:level_to_num(Lvl),Level), ?assertEqual(self(),proplists:get_value(pid,Metadata)), ?assertEqual("{foolish,bees}", lists:flatten(Msg)) end