Packages
zotonic_stdlib
1.0.3
1.31.2
1.31.1
1.31.0
1.30.1
1.30.0
1.29.1
1.29.0
1.28.1
1.28.0
1.27.0
1.26.1
1.25.0
1.24.0
1.23.1
1.23.0
1.22.0
1.21.0
1.20.3
1.20.2
1.20.1
1.20.0
1.19.0
1.18.0
1.17.0
1.16.0
1.15.1
1.15.0
1.14.0
1.13.0
1.12.0
1.11.2
1.11.1
1.11.0
1.10.0
1.9.0
1.8.0
1.7.0
1.6.0
1.5.11
1.5.10
1.5.9
1.5.8
1.5.7
1.5.6
1.5.5
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.5
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.2
1.3.1
1.3.0
1.2.11
1.2.10
1.2.9
1.2.8
1.2.7
1.2.6
1.2.5
1.2.4
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-alpha5
1.0.0-alpha4
1.0.0-alpha3
1.0.0-alpha2
1.0.0-alpha1
Zotonic standard library
Current section
Files
Jump to
Current section
Files
src/proper_utils.erl
%% Temporary; see https://github.com/manopapad/proper/issues/49 for
%% pull request of this into proper itself.
-module(proper_utils).
-export([opts/0, qc/1, qc/2, qc_/1, qc_/2, print_stdout/1]).
-include_lib("eunit/include/eunit.hrl").
%% @doc Run a function and output to stdout. Useful for PropEr within eunit.
-spec print_stdout(fun(() -> A)) -> A.
print_stdout(Fun) ->
EunitLeader = erlang:group_leader(),
erlang:group_leader(whereis(user), self()),
Ret = Fun(),
erlang:group_leader(EunitLeader, self()),
Ret.
qc(Proper) ->
qc(Proper, opts()).
%% @doc like proper:quickcheck/2, but print to stdout.
%%
%% Removes `timeout' from `Opts'.
qc(Proper, Opts) ->
Opts2 = proplists:delete(timeout, Opts),
print_stdout(fun() -> proper:quickcheck(Proper, Opts2) end).
qc_(Proper) ->
qc_(Proper, opts()).
%% @doc proper:quickcheck/1 helper for eunit. Accepts additional Arg `timeout'.
qc_(Proper, Opts) ->
Timeout = proplists:get_value(timeout, Opts),
if
is_integer(Timeout) ->
{timeout, Timeout, ?_assertEqual(true, qc(Proper, Opts))};
true ->
?_assertEqual(true, qc(Proper, Opts))
end.
%% @doc Default options for PropEr runs
opts() ->
[{constraint_tries, 1000}, {numtests, 1000}, {timeout, 3600}].