summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTim Watson <tim@rabbitmq.com>2014-03-21 13:54:29 +0000
committerTim Watson <tim@rabbitmq.com>2014-03-21 13:54:29 +0000
commit861de1cbda2fb007369eaf81e3eb6412e2a8dd10 (patch)
tree09b92126147f1226738f56187ea1cecb8113ac4c /src
parenta8aa69cad8a1790fd90ddbd83a93a9df829c2bb7 (diff)
downloadrabbitmq-server-861de1cbda2fb007369eaf81e3eb6412e2a8dd10.tar.gz
Avoid crashing as we approach Len == 0, improve test output
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_trunc_term.erl7
-rw-r--r--src/rabbit_trunc_term_tests.erl8
2 files changed, 10 insertions, 5 deletions
diff --git a/src/rabbit_trunc_term.erl b/src/rabbit_trunc_term.erl
index eaa8e65b..55eb30fa 100644
--- a/src/rabbit_trunc_term.erl
+++ b/src/rabbit_trunc_term.erl
@@ -57,9 +57,10 @@ shrink_term(T, N) when is_list(T) ->
IsPrintable = io_lib:printable_list(T),
case length(T) > N of
true when IsPrintable ->
- lists:append(lists:sublist(T, N-3), "...");
+ lists:append(lists:sublist(T, suffix_len(N-3)), "...");
true ->
- lists:append([shrink_term(E, N-1) || E <- lists:sublist(T, N-1)],
+ lists:append([shrink_term(E, N-1) ||
+ E <- lists:sublist(T, suffix_len(N-1))],
['...']);
false when IsPrintable ->
T;
@@ -77,3 +78,5 @@ shrink_term(T, N) when is_tuple(T) ->
end;
shrink_term(T, _) -> T.
+suffix_len(N) -> erlang:max(N, 1).
+
diff --git a/src/rabbit_trunc_term_tests.erl b/src/rabbit_trunc_term_tests.erl
index 26dcbde9..e298da81 100644
--- a/src/rabbit_trunc_term_tests.erl
+++ b/src/rabbit_trunc_term_tests.erl
@@ -30,10 +30,11 @@ prop_trunc_any_term() ->
Shrunk = rabbit_trunc_term:shrink_term(GenAny, MaxSz),
SzShrunk = erts_debug:size(Shrunk),
?WHENFAIL(begin
- io:format("Input: ~p\n", [GenAny]),
io:format("MaxLen: ~p\n", [MaxSz]),
io:format("Input-Size: ~p\n", [SzInitial]),
- io:format("Shrunk-Size: ~p\n", [SzShrunk])
+ io:format("Shrunk-Size: ~p\n", [SzShrunk]),
+ io:format("Input: ~p\n", [GenAny]),
+ io:format("Output: ~p\n", [Shrunk])
end,
case size_of_thing(GenAny) > MaxSz of
true -> true = SzShrunk < SzInitial;
@@ -41,7 +42,8 @@ prop_trunc_any_term() ->
end)
catch
_:Err ->
- io:format("\nException: ~p\n", [Err]),
+ io:format("\nException: ~p\n",
+ [{Err, erlang:get_stacktrace()}]),
io:format("Input: ~p\n", [GenAny]),
io:format("Max-Size: ~p\n", [MaxSz]),
false