소스 검색

Fix EQC test to work with floats and padding

pull/25/head
Andrew Thompson 13 년 전
부모
커밋
f459624b8d
1개의 변경된 파일23개의 추가작업 그리고 9개의 파일을 삭제
  1. +23
    -9
      test/trunc_io_eqc.erl

+ 23
- 9
test/trunc_io_eqc.erl 파일 보기

@ -23,7 +23,7 @@
-ifdef(TEST).
-ifdef(EQC).
-export([test/0, test/1, check/0]).
-export([test/0, test/1, check/0, prop_format/0]).
-include_lib("eqc/include/eqc.hrl").
-include_lib("eunit/include/eunit.hrl").
@ -76,13 +76,13 @@ gen_fmt_args() ->
{"~.36B", nat()},
{"~62P", gen_any(5), 4},
{"~c", gen_char()},
{"~tc", gen_char()}
%{"~f", real()}, %% floats like to make the fudge limit fail, so don't enable them
%{"~10.f", real()},
%{"~g", real()},
%{"~10.g", real()},
%{"~e", real()},
%{"~10.e", real()}
{"~tc", gen_char()},
{"~f", real()},
{"~10.f", real()},
{"~g", real()},
{"~10.g", real()},
{"~e", real()},
{"~10.e", real()}
])).
@ -139,7 +139,8 @@ gen_char() ->
prop_format() ->
?FORALL({FmtArgs, MaxLen}, {gen_fmt_args(), gen_max_len()},
begin
FudgeLen = 50, %% trunc_io does not correctly calc safe size of pid/port/numbers/funs
%% trunc_io does not correctly calc safe size of pid/port/numbers/funs
FudgeLen = calculate_fudge(FmtArgs, 50),
{FmtStr, Args} = build_fmt_args(FmtArgs),
try
Str = lists:flatten(lager_trunc_io:format(FmtStr, Args, MaxLen)),
@ -182,5 +183,18 @@ build_fmt_args(FmtArgs) ->
end,
lists:foldl(F, {"", []}, FmtArgs).
calculate_fudge([], Acc) ->
Acc;
calculate_fudge([{"~62P", _Arg, _Depth}|T], Acc) ->
calculate_fudge(T, Acc+62);
calculate_fudge([{Fmt, Arg}|T], Acc) when
Fmt == "~f"; Fmt == "~10.f";
Fmt == "~g"; Fmt == "~10.g";
Fmt == "~e"; Fmt == "~10.e";
Fmt == "~x"; Fmt == "~X" ->
calculate_fudge(T, Acc + length(lists:flatten(io_lib:format(Fmt, [Arg]))));
calculate_fudge([_|T], Acc) ->
calculate_fudge(T, Acc).
-endif. % (EQC).
-endif. % (TEST).

불러오는 중...
취소
저장