Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
seed: make state_is_clean more debug friendly
Browse files Browse the repository at this point in the history
fenollp committed May 19, 2018
1 parent 30f784a commit 4ff58ae
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions test/proper_tests.erl
Original file line number Diff line number Diff line change
@@ -40,8 +40,8 @@

%% NOTE: Never add long_result to Opts for these macros.

state_is_clean() ->
get() =:= [].
-define(state_is_clean(), ?assertEqual([],get())).
-define(_state_is_clean(), ?_assertEqual([],get())).

assertEqualsOneOf(_X, none) ->
ok;
@@ -64,13 +64,13 @@ assertEqualsOneOf(X, List) ->
?_test(begin
?assertMatch(ExpResult, proper:quickcheck(Test,Opts)),
proper:clean_garbage(),
?assert(state_is_clean()),
?state_is_clean(),
case AlsoLongResult of
true ->
?assertMatch(ExpResult,
proper:quickcheck(Test,[long_result|Opts])),
proper:clean_garbage(),
?assert(state_is_clean());
?state_is_clean();
false ->
ok
end
@@ -85,7 +85,7 @@ assertEqualsOneOf(X, List) ->
-define(assertCheck(ExpShortResult, CExm, Test, Opts),
begin
?assertMatch(ExpShortResult, proper:check(Test,CExm,Opts)),
?assert(state_is_clean())
?state_is_clean()
end).

-define(_fails(Test),
@@ -141,7 +141,7 @@ assertEqualsOneOf(X, List) ->
get_cexm() ->
CExm = proper:counterexample(),
proper:clean_garbage(),
?assert(state_is_clean()),
?state_is_clean(),
CExm.

-define(checkCExm(CExm, ExpCExm, AllCExms, Test, Opts),
@@ -160,7 +160,7 @@ get_cexm() ->
?assertEqual(N, get_temp()),
erase_temp(),
proper:clean_garbage(),
?assert(state_is_clean())
?state_is_clean()
end)).

inc_temp() ->
@@ -236,7 +236,7 @@ assert_can_translate(Mod, TypeStr) ->
Result1 = proper_typeserver:translate_type(Type),
Result2 = proper_typeserver:translate_type(Type),
proper_typeserver:stop(),
?assert(state_is_clean()),
?state_is_clean(),
{ok,Type1} = Result1,
{ok,Type2} = Result2,
?assert(proper_types:equal_types(Type1,Type2)),
@@ -246,20 +246,21 @@ assert_cant_translate(Mod, TypeStr) ->
proper_typeserver:start(),
Result = proper_typeserver:translate_type({Mod,TypeStr}),
proper_typeserver:stop(),
?assert(state_is_clean()),
?state_is_clean(),
?assertMatch({error,_}, Result).

%% TODO: after fixing the typesystem, use generic reverse function.
assert_is_instance(X, Type) ->
?assert(proper_types:is_inst(X, Type) andalso state_is_clean()).
?assert(proper_types:is_inst(X, Type)),
?state_is_clean().

assert_can_generate(Type, CheckIsInstance) ->
lists:foreach(fun(Size) -> try_generate(Type,Size,CheckIsInstance) end,
[1, 2, 5, 10, 20, 40, 50]).

try_generate(Type, Size, CheckIsInstance) ->
{ok,Instance} = proper_gen:pick(Type, Size),
?assert(state_is_clean()),
?state_is_clean(),
case CheckIsInstance of
true -> assert_is_instance(Instance, Type);
false -> ok
@@ -280,22 +281,23 @@ assert_native_can_generate(Mod, TypeStr, CheckIsInstance) ->

assert_cant_generate(Type) ->
?assertEqual(error, proper_gen:pick(Type)),
?assert(state_is_clean()).
?state_is_clean().

assert_cant_generate_cmds(Type, N) ->
?assertEqual(error, proper_gen:pick(?SUCHTHAT(T, Type, length(T) > N))),
?assert(state_is_clean()).
?state_is_clean().

assert_not_is_instance(X, Type) ->
?assert(not proper_types:is_inst(X, Type) andalso state_is_clean()).
?assert(not proper_types:is_inst(X, Type)),
?state_is_clean().

assert_function_type_works(FunType) ->
{ok,F} = proper_gen:pick(FunType),
%% TODO: this isn't exception-safe
?assert(proper_types:is_instance(F, FunType)),
assert_is_pure_function(F),
proper:global_state_erase(),
?assert(state_is_clean()).
?state_is_clean().

assert_is_pure_function(F) ->
{arity,Arity} = erlang:fun_info(F, arity),
@@ -1048,7 +1050,7 @@ seeded_test_() ->
proper:clean_garbage(),
R
end,
[[?_assert(state_is_clean()), ?_assertEqual(QC(Prop),Check)]
[[?_state_is_clean(), ?_assertEqual(QC(Prop),Check)]
|| Prop <- [?FORALL(_, integer(), false)
,?FORALL(_, integer(), ?TRAPEXIT(false))
,?FORALL_TARGETED(I, integer(), begin ?MAXIMIZE(I),false end)

0 comments on commit 4ff58ae

Please sign in to comment.