File 0243-test-logger_formatter-add-deeply-nested-test.patch of Package erlang

From fb2f632c064aa037c34565b36f465c57fce0c266 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Niemier?= <lukasz@niemier.pl>
Date: Wed, 15 Jan 2020 22:36:50 +0100
Subject: [PATCH 3/4] test(logger_formatter): add deeply nested test

---
 lib/kernel/src/logger_formatter.erl        |  4 +-
 lib/kernel/test/logger_formatter_SUITE.erl | 63 ++++++++++++----------
 2 files changed, 36 insertions(+), 31 deletions(-)

diff --git a/lib/kernel/src/logger_formatter.erl b/lib/kernel/src/logger_formatter.erl
index 3df467d56c..a65c48cfa9 100644
--- a/lib/kernel/src/logger_formatter.erl
+++ b/lib/kernel/src/logger_formatter.erl
@@ -532,8 +532,8 @@ check_template([Str|T]) when is_list(Str) ->
         false -> error
     end;
 check_template([Bin|T]) when is_binary(Bin) ->
-    case unicode:character_to_list(Bin) of
-        Str -> check_template([Str|T]);
+    case unicode:characters_to_list(Bin) of
+        Str when is_list(Str) -> check_template([Str|T]);
         _Error -> error
     end;
 check_template([]) ->
diff --git a/lib/kernel/test/logger_formatter_SUITE.erl b/lib/kernel/test/logger_formatter_SUITE.erl
index dc95cbc8e3..166b3e4df8 100644
--- a/lib/kernel/test/logger_formatter_SUITE.erl
+++ b/lib/kernel/test/logger_formatter_SUITE.erl
@@ -248,72 +248,77 @@ template(_Config) ->
     "" = String5,
 
     Template6 = [<<"binary">>],
-    String6 = format(info,{"~p",[term]},#{time=>Time},#{template=>Template5}),
+    String6 = format(info,{"~p",[term]},#{time=>Time},#{template=>Template6}),
     ct:log(String6),
     "binary" = String6,
 
-    Ref7 = erlang:make_ref(),
-    Meta7 = #{atom=>some_atom,
+    Template7 = [{metakey,[[$e,<<"x">>,$i,[<<"s">>],":"],metakey],[[[[[[[[["does ",<<"not">>," exist"]]]]]]]]]},[[[<<" more ">>]],"deep"]],
+    String7 = format(info,{"~p",[term]},#{time=>Time},#{template=>Template7}),
+    ct:log(String7),
+    "does not exist more deep" = String7,
+
+    Ref8 = erlang:make_ref(),
+    Meta8 = #{atom=>some_atom,
               integer=>632,
               list=>[list,"string",4321,#{},{tuple}],
               mfa=>{mod,func,0},
               pid=>self(),
-              ref=>Ref6,
+              ref=>Ref8,
               string=>"some string",
               time=>Time,
               tuple=>{1,atom,"list"},
               nested=>#{subkey=>subvalue}},
-    Template7 = lists:join(";",lists:sort(maps:keys(maps:remove(nested,Meta6))) ++
+    Template8 = lists:join(";",lists:sort(maps:keys(maps:remove(nested,Meta8))) ++
                                [[nested,subkey]]),
-    String7 = format(info,{"~p",[term]},Meta6,#{template=>Template6,
+    String8 = format(info,{"~p",[term]},Meta8,#{template=>Template8,
                                                 single_line=>true}),
     ct:log(String6),
     SelfStr = pid_to_list(self()),
-    RefStr7 = ref_to_list(Ref7),
+    RefStr8 = ref_to_list(Ref8),
     ListStr = "[list,\"string\",4321,#{},{tuple}]",
-    ExpectedTime7 = default_time_format(Time),
+    ExpectedTime8 = default_time_format(Time),
     ["some_atom",
      "632",
      ListStr,
      "mod:func/0",
      SelfStr,
-     RefStr7,
+     RefStr8,
      "some string",
-     ExpectedTime7,
+     ExpectedTime8,
      "{1,atom,\"list\"}",
-     "subvalue"] = string:lexemes(String7,";"),
+     "subvalue"] = string:lexemes(String8,";"),
 
-    Meta8 = #{time=>Time,
+    Meta9 = #{time=>Time,
               nested=>#{key1=>#{subkey1=>value1},
                         key2=>value2}},
-    Template8 = lists:join(";",[nested,
+    Template9 = lists:join(";",[nested,
                                 [nested,key1],
                                 [nested,key1,subkey1],
                                 [nested,key2],
                                 [nested,key2,subkey2],
                                 [nested,key3],
                                 [nested,key3,subkey3]]),
-    String8 = format(info,{"~p",[term]},Meta7,#{template=>Template7,
+    String9 = format(info,{"~p",[term]},Meta9,#{template=>Template9,
                                                 single_line=>true}),
-    ct:log(String8),
-    [MultipleKeysStr8,
+    ct:log(String9),
+    [MultipleKeysStr9,
      "#{subkey1 => value1}",
      "value1",
      "value2",
      "",
      "",
-     ""] = string:split(String8,";",all),
+     ""] = string:split(String9,";",all),
     %% Order of keys is not fixed
-    case MultipleKeysStr8 of
+    case MultipleKeysStr9 of
         "#{key2 => value2,key1 => #{subkey1 => value1}}" -> ok;
         "#{key1 => #{subkey1 => value1},key2 => value2}" -> ok;
-        _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr8})
+        _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr9})
     end,
 
-    Meta9 = #{time=>Time,
+    Meta10 = #{time=>Time,
               nested=>#{key1=>#{subkey1=>value1},
                         key2=>value2}},
-    Template9 =
+    Template10 =
         lists:join(
           ";",
           [{nested,["exist:",nested],["noexist"]},
@@ -323,21 +328,21 @@ template(_Config) ->
            {[nested,key2,subkey2],["exist:",[nested,key2,subkey2]],["noexist"]},
            {[nested,key3],["exist:",[nested,key3]],["noexist"]},
            {[nested,key3,subkey3],["exist:",[nested,key3,subkey3]],["noexist"]}]),
-    String9 = format(info,{"~p",[term]},Meta8,#{template=>Template8,
-                                                single_line=>true}),
-    ct:log(String9),
-    [MultipleKeysStr9,
+    String10 = format(info,{"~p",[term]},Meta10,#{template=>Template10,
+                                                 single_line=>true}),
+    ct:log(String10),
+    [MultipleKeysStr10,
      "exist:#{subkey1 => value1}",
      "exist:value1",
      "exist:value2",
      "noexist",
      "noexist",
-     "noexist"] = string:split(String9,";",all),
+     "noexist"] = string:split(String10,";",all),
     %% Order of keys is not fixed
-    case MultipleKeysStr9 of
+    case MultipleKeysStr10 of
         "exist:#{key2 => value2,key1 => #{subkey1 => value1}}" -> ok;
         "exist:#{key1 => #{subkey1 => value1},key2 => value2}" -> ok;
-        _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr9})
+        _ -> ct:fail({full_nested_map_unexpected,MultipleKeysStr10})
     end,
 
     ok.
@@ -847,7 +852,7 @@ format(Level,Msg,Meta,Config) ->
     format(#{level=>Level,msg=>Msg,meta=>add_time(Meta)},Config).
 
 format(Log,Config) ->
-    lists:flatten(logger_formatter:format(Log,Config)).
+    unicode:characters_to_list(logger_formatter:format(Log,Config)).
 
 default_time_format(Timestamp) ->
     default_time_format(Timestamp,false).
-- 
2.26.2

openSUSE Build Service is sponsored by