summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Bolinder <hasse@erlang.org>2021-07-15 10:33:49 +0200
committerHans Bolinder <hasse@erlang.org>2021-07-15 13:16:09 +0200
commita3323d9cd1630c5e9cb3357dde16e697aedf65ae (patch)
tree84929dda3a55dc72fa6c358a3a2b7e551adb49e8
parent6d5a5f31c36bbdaad21585d25974177bd1b75e66 (diff)
downloaderlang-a3323d9cd1630c5e9cb3357dde16e697aedf65ae.tar.gz
stdlib: Fix a concerning io_lib option 'chars_limit'
See also https://github.com/erlang/otp/issues/5053.
-rw-r--r--lib/stdlib/src/io_lib_pretty.erl6
-rw-r--r--lib/stdlib/test/io_SUITE.erl28
2 files changed, 31 insertions, 3 deletions
diff --git a/lib/stdlib/src/io_lib_pretty.erl b/lib/stdlib/src/io_lib_pretty.erl
index 77f02eafe0..fbc2919a95 100644
--- a/lib/stdlib/src/io_lib_pretty.erl
+++ b/lib/stdlib/src/io_lib_pretty.erl
@@ -185,6 +185,8 @@ pp({S,_Len,_,_}, _Col, _Ll, _M, _TInd, _Ind, _LD, _W) ->
%% Print a tagged tuple by indenting the rest of the elements
%% differently to the tag. Tuple has size >= 2.
+pp_tag_tuple({dots, _, _, _}, _Col, _Ll, _M, _TInd, _Ind, _LD, _W) ->
+ "...";
pp_tag_tuple([{Tag,Tlen,_,_} | L], Col, Ll, M, TInd, Ind, LD, W) ->
%% this uses TInd
TagInd = Tlen + 2,
@@ -973,7 +975,9 @@ cind_tag_tuple([{_Tag,Tlen,_,_} | L], Col, Ll, M, Ind, LD, W) ->
cind_list(L, Tcol, Ll, M, Ind, LD, W + Tlen + 1);
true ->
throw(no_good)
- end.
+ end;
+cind_tag_tuple(_, _Col, _Ll, _M, Ind, _LD, _W) ->
+ Ind.
cind_map([P | Ps], Col, Ll, M, Ind, LD, W) ->
PW = cind_pair(P, Col, Ll, M, Ind, last_depth(Ps, LD), W),
diff --git a/lib/stdlib/test/io_SUITE.erl b/lib/stdlib/test/io_SUITE.erl
index 4eb5b1772c..bc96529a00 100644
--- a/lib/stdlib/test/io_SUITE.erl
+++ b/lib/stdlib/test/io_SUITE.erl
@@ -32,7 +32,8 @@
io_with_huge_message_queue/1, format_string/1,
maps/1, coverage/1, otp_14178_unicode_atoms/1, otp_14175/1,
otp_14285/1, limit_term/1, otp_14983/1, otp_15103/1, otp_15076/1,
- otp_15159/1, otp_15639/1, otp_15705/1, otp_15847/1, otp_15875/1]).
+ otp_15159/1, otp_15639/1, otp_15705/1, otp_15847/1, otp_15875/1,
+ otp_17525/1]).
-export([pretty/2, trf/3]).
@@ -65,7 +66,7 @@ all() ->
io_lib_width_too_small, io_with_huge_message_queue,
format_string, maps, coverage, otp_14178_unicode_atoms, otp_14175,
otp_14285, limit_term, otp_14983, otp_15103, otp_15076, otp_15159,
- otp_15639, otp_15705, otp_15847, otp_15875].
+ otp_15639, otp_15705, otp_15847, otp_15875, otp_17525].
%% Error cases for output.
error_1(Config) when is_list(Config) ->
@@ -2718,3 +2719,26 @@ otp_15847(_Config) ->
otp_15875(_Config) ->
S = io_lib:format("~tp", [[{0, [<<"00">>]}]], [{chars_limit, 18}]),
"[{0,[<<48,...>>]}]" = lists:flatten(S).
+
+%% GH-5053. 'chars_limit' bug.
+otp_17525(_Config) ->
+ L = [{xxxxxxxxx,aaaa},
+ {yyyyyyyyyyyy,1},
+ {eeeeeeeeeeeee,bbbb},
+ {ddddddddd,1111111111},
+ {gggggggggggggggggggg,cccc},
+ {uuuuuuuuuuuu,11}],
+ S = io_lib:format("aaaaaaaaaaaaaaaaaa ~p bbbbbbbbbbb ~p",
+ ["cccccccccccccccccccccccccccccccccccccc", L],
+ [{chars_limit, 155}]),
+ "aaaaaaaaaaaaaaaaaa \"cccccccccccccccccccccccccccccccccccccc\" bbbbbbbbbbb [{xxxxxxxxx,\n"
+ " aaaa},\n"
+ " {yyyyyyyyyyyy,\n"
+ " 1},\n"
+ " {eeeeeeeeeeeee,\n"
+ " bbbb},\n"
+ " {ddddddddd,\n"
+ " 1111111111},\n"
+ " {...}|...]" =
+ lists:flatten(S),
+ ok.