From 1f9ebb9e1ee3c1ca1b508f7a40077c756b442105 Mon Sep 17 00:00:00 2001 From: Jon Meredith Date: Thu, 7 Jul 2011 12:18:19 -0600 Subject: [PATCH] Added a FudgeLen to bound how far over it can go. trunc_io:format checks the length after formatting funs/bignums etc so it can go over. --- test/trunc_io_eqc.erl | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/test/trunc_io_eqc.erl b/test/trunc_io_eqc.erl index 549c483..85bd7c8 100644 --- a/test/trunc_io_eqc.erl +++ b/test/trunc_io_eqc.erl @@ -36,9 +36,10 @@ %%==================================================================== eqc_test_() -> - {spawn, - [?_assertEqual(true, quickcheck(numtests(500, ?QC_OUT(prop_format()))))] - }. + {timeout, 300, + {spawn, + [?_assertEqual(true, quickcheck(numtests(500, ?QC_OUT(prop_format()))))] + }}. %%==================================================================== %% Shell helpers @@ -114,15 +115,17 @@ gen_fun() -> prop_format() -> ?FORALL({FmtArgs, MaxLen}, {gen_fmt_args(), gen_max_len()}, begin + FudgeLen = 31, %% trunc_io does not correctly calc safe size of pid/port/numbers {FmtStr, Args} = build_fmt_args(FmtArgs), try Str = lists:flatten(trunc_io:format(FmtStr, Args, MaxLen)), ?WHENFAIL(begin - io:format("FmtStr: ~p\n", [FmtStr]), - io:format("Args: ~p\n", [Args]), - io:format("MaxLen: ~p\n", [MaxLen]), - io:format("ActLen: ~p\n", [length(Str)]), - io:format("Str: ~p\n", [Str]) + io:format(user, "FmtStr: ~p\n", [FmtStr]), + io:format(user, "Args: ~p\n", [Args]), + io:format(user, "FudgeLen: ~p\n", [FudgeLen]), + io:format(user, "MaxLen: ~p\n", [MaxLen]), + io:format(user, "ActLen: ~p\n", [length(Str)]), + io:format(user, "Str: ~p\n", [Str]) end, %% Make sure the result is a printable list %% and if the format string is less than the length, @@ -130,12 +133,12 @@ prop_format() -> conjunction([{printable, Str == "" orelse io_lib:printable_list(Str)}, {length, length(FmtStr) > MaxLen orelse - length(Str) =< MaxLen}])) + length(Str) =< MaxLen + FudgeLen}])) catch _:Err -> io:format(user, "\nException: ~p\n", [Err]), - io:format("FmtStr: ~p\n", [FmtStr]), - io:format("Args: ~p\n", [Args]), + io:format(user, "FmtStr: ~p\n", [FmtStr]), + io:format(user, "Args: ~p\n", [Args]), false end end).