Permalink
Browse files

Merge branch 'master' of github.com:manopapad/proper into fsm

  • Loading branch information...
2 parents 3979281 + 09bd16e commit d130127bb9b11eed521b4f90d46ea1e03afa9f85 @eiriniar eiriniar committed May 7, 2011
Showing with 31 additions and 113 deletions.
  1. +0 −9 README
  2. BIN rebar
  3. +5 −1 rebar.config
  4. +1 −1 src/proper.app.src
  5. +2 −5 src/proper.erl
  6. +6 −37 src/proper_arith.erl
  7. +9 −48 src/proper_gen.erl
  8. +1 −1 src/proper_statem.erl
  9. +7 −10 src/proper_types.erl
  10. +0 −1 test/proper_tests.erl
View
9 README
@@ -329,15 +329,6 @@ The available options are:
CAUTION: The above output control options are incompatible with each other.
'long_result'
Enables long-result mode (see the 'Counterexamples' section for details).
-'crypto'
- Enables the use of the crypto module for some kinds of random generation
- (namely, the generation of binaries and the generation of ranges of
- integers) - make sure the crypto module is available before enabling this.
- This has the side-effect that an INFO message is printed on screen when
- the program exits, because of the stopping of the crypto server.
- CAUTION: This option is incompatible with the random function generation
- subsystem - do not enable it for tests that contain randomly generated
- functions.
{'numtests', <Positive_number>} or simply <Positive_number>
This is equivalent to the 'numtests' property wrapper. Any 'numtests'
wrappers in the actual property will overwrite this setting.
View
BIN rebar
Binary file not shown.
View
@@ -27,11 +27,15 @@
%% {d,'NO_TYPES'} to erl_opts.
{erl_first_files, ["src/strip_types.erl", "src/vararg.erl"]}.
+{eunit_first_files, ["src/strip_types.erl", "src/vararg.erl",
+ "src/proper_transformer.erl",
+ "src/proper_prop_remover.erl",
+ "src/proper_typeserver.erl"]}.
{erl_opts, [debug_info,
report_warnings, {warn_format,1}, warn_export_vars,
warn_obsolete_guard, warn_unused_import,
warn_missing_spec, warn_untyped_record]}.
{edoc_opts, [{report_missing_type,true}, {report_type_mismatch,true},
{pretty_printer,erl_pp}, {preprocess,true}]}.
{dialyzer_opts, [{warnings,[unmatched_returns]}]}.
-{clean_post_script, "./clean_doc.sh"}.
+{post_hooks,[{clean,"./clean_doc.sh"}]}.
View
@@ -28,5 +28,5 @@
[{description, "A QuickCheck-inspired property-based testing tool for Erlang"},
{vsn, "1.0"},
{registered, []},
- {applications, [compiler,kernel,stdlib,crypto]},
+ {applications, [compiler,kernel,stdlib]},
{env, []}]}.
View
@@ -133,7 +133,6 @@
| {'to_file',file:io_device()}
| {'on_output',output_fun()}
| 'long_result'
- | 'crypto'
| {'numtests', pos_integer()}
| pos_integer()
| {'start_size',size()}
@@ -147,7 +146,6 @@
-type user_opts() :: [user_opt()] | user_opt().
-record(opts, {output_fun = fun io:format/2 :: output_fun(),
long_result = false :: boolean(),
- crypto = false :: boolean(),
numtests = 100 :: pos_integer(),
start_size = 1 :: size(),
max_size = 42 :: size(),
@@ -270,14 +268,14 @@ global_state_init_size(Size) ->
-spec global_state_init(opts()) -> 'ok'.
global_state_init(#opts{start_size = StartSize, constraint_tries = CTries,
- crypto = Crypto, any_type = AnyType} = Opts) ->
+ any_type = AnyType} = Opts) ->
clean_garbage(),
put('$size', StartSize - 1),
put('$left', 0),
grow_size(Opts),
put('$constraint_tries', CTries),
put('$any_type',AnyType),
- proper_arith:rand_start(Crypto),
+ proper_arith:rand_start(),
proper_typeserver:start(),
ok.
@@ -467,7 +465,6 @@ parse_opt(UserOpt, Opts) ->
};
{on_output,Print} -> Opts#opts{output_fun = Print};
long_result -> Opts#opts{long_result = true};
- crypto -> Opts#opts{crypto = true};
{numtests,N} -> Opts#opts{numtests = N};
N when is_integer(N) -> Opts#opts{numtests = N};
{start_size,Size} -> Opts#opts{start_size = Size};
View
@@ -33,10 +33,10 @@
safe_any/2, safe_zip/2, tuple_map/2, cut_improper_tail/1,
head_length/1, find_first/2, filter/2, partition/2, remove/2, insert/3,
unflatten/2]).
--export([rand_start/1, rand_reseed/0, rand_stop/0,
+-export([rand_start/0, rand_reseed/0, rand_stop/0,
rand_int/1, rand_int/2, rand_non_neg_int/1,
rand_float/1, rand_float/2, rand_non_neg_float/1,
- rand_bytes/1, distribute/2, jumble/1, rand_choose/1, freq_choose/1]).
+ distribute/2, jumble/1, rand_choose/1, freq_choose/1]).
-export_type([extint/0, extnum/0]).
@@ -234,22 +234,11 @@ remove_n(N, {List,Acc}) ->
%% @doc Seeds the random number generator. This function should be run before
%% calling any random function from this module.
--spec rand_start(boolean()) -> 'ok'.
-rand_start(Crypto) ->
+-spec rand_start() -> 'ok'.
+rand_start() ->
_ = random:seed(now()),
%% TODO: read option for RNG bijections here
- case Crypto of
- true ->
- case crypto:start() of
- ok ->
- put('$crypto', true),
- ok;
- {error, _} ->
- ok
- end;
- false ->
- ok
- end.
+ ok.
-spec rand_reseed() -> 'ok'.
rand_reseed() ->
@@ -260,14 +249,6 @@ rand_reseed() ->
-spec rand_stop() -> 'ok'.
rand_stop() ->
- case get('$crypto') of
- true ->
- erase('$crypto'),
- _ = crypto:stop(),
- ok;
- _ ->
- ok
- end,
erase(random_seed),
ok.
@@ -281,12 +262,7 @@ rand_non_neg_int(Const) ->
-spec rand_int(integer(), integer()) -> integer().
rand_int(Low, High) when is_integer(Low), is_integer(High), Low =< High ->
- case get('$crypto') of
- true ->
- crypto:rand_uniform(Low, High + 1);
- _ ->
- Low + random:uniform(High - Low + 1) - 1
- end.
+ Low + random:uniform(High - Low + 1) - 1.
-spec rand_float(non_neg_integer()) -> float().
rand_float(Const) ->
@@ -314,13 +290,6 @@ rand_float(Low, High) when is_float(Low), is_float(High), Low =< High ->
zero_one_to_zero_inf(X) ->
X / math:sqrt(1 - X*X).
--spec rand_bytes(length()) -> {'ok',binary()} | 'error'.
-rand_bytes(Len) ->
- case get('$crypto') of
- true -> {ok,crypto:rand_bytes(Len)};
- _ -> error
- end.
-
-spec distribute(non_neg_integer(), non_neg_integer()) -> [non_neg_integer()].
distribute(_Credits, 0) ->
[];
View
@@ -32,15 +32,14 @@
-export([generate/1, normal_gen/1, alt_gens/1, clean_instance/1,
get_ret_type/1]).
-export([integer_gen/3, float_gen/3, atom_gen/1, atom_rev/1, binary_gen/1,
- binary_str_gen/1, binary_rev/1, binary_len_gen/1, binary_len_str_gen/1,
- bitstring_gen/1, bitstring_rev/1, bitstring_len_gen/1, list_gen/2,
- distlist_gen/3, vector_gen/2, union_gen/1, weighted_union_gen/1,
- tuple_gen/1, loose_tuple_gen/2, loose_tuple_rev/2, exactly_gen/1,
- fixed_list_gen/1, function_gen/2, any_gen/1, native_type_gen/2]).
+ binary_rev/1, binary_len_gen/1, bitstring_gen/1, bitstring_rev/1,
+ bitstring_len_gen/1, list_gen/2, distlist_gen/3, vector_gen/2,
+ union_gen/1, weighted_union_gen/1, tuple_gen/1, loose_tuple_gen/2,
+ loose_tuple_rev/2, exactly_gen/1, fixed_list_gen/1, function_gen/2,
+ any_gen/1, native_type_gen/2]).
-export_type([instance/0, imm_instance/0, sized_generator/0, nosize_generator/0,
- generator/0, straight_gen/0, reverse_gen/0, combine_fun/0,
- alt_gens/0]).
+ generator/0, reverse_gen/0, combine_fun/0, alt_gens/0]).
-include("proper_internal.hrl").
-compile({parse_transform, vararg}).
@@ -62,9 +61,6 @@
-type sized_generator() :: fun((size()) -> imm_instance()).
-type nosize_generator() :: fun(() -> imm_instance()).
-type generator() :: sized_generator() | nosize_generator().
--type sized_straight_gen() :: fun((size()) -> {'ok',instance()} | 'error').
--type nosize_straight_gen() :: fun(() -> {'ok',instance()} | 'error').
--type straight_gen() :: sized_straight_gen() | nosize_straight_gen().
-type reverse_gen() :: fun((instance()) -> imm_instance()).
-type combine_fun() :: fun((instance()) -> imm_instance()).
-type alt_gens() :: fun(() -> [imm_instance()]).
@@ -151,13 +147,8 @@ generate(Type, TriesLeft, Fallback) ->
false -> ImmInstance1
end,
{'$used',ImmParts,ImmInstance2};
- Kind ->
- ImmInstance1 =
- case Kind of
- %% TODO: should we have an option to enable this?
- wrapper -> normal_or_str_gen(Type);
- _ -> normal_gen(Type)
- end,
+ _ ->
+ ImmInstance1 = normal_gen(Type),
case proper_types:is_raw_type(ImmInstance1) of
true -> generate(ImmInstance1);
false -> ImmInstance1
@@ -249,29 +240,10 @@ contains_fun(_Term) ->
%% Utility functions
%%-----------------------------------------------------------------------------
--spec normal_or_str_gen(proper_types:type()) -> imm_instance().
-normal_or_str_gen(Type) ->
- case proper_types:find_prop(straight_gen,Type) of
- {ok,StraightGen} ->
- case call_gen(StraightGen, Type) of
- {ok,Instance} ->
- ReverseGen = proper_types:get_prop(reverse_gen, Type),
- ReverseGen(Instance);
- error ->
- normal_gen(Type)
- end;
- error ->
- normal_gen(Type)
- end.
-
%% @private
-spec normal_gen(proper_types:type()) -> imm_instance().
normal_gen(Type) ->
- call_gen(proper_types:get_prop(generator,Type),Type).
-
--spec call_gen(generator() | straight_gen(), proper_types:type()) ->
- imm_instance() | {'ok',instance()} | 'error'.
-call_gen(Gen, Type) ->
+ Gen = proper_types:get_prop(generator, Type),
if
is_function(Gen, 0) -> Gen();
is_function(Gen, 1) -> Gen(proper:get_size(Type))
@@ -357,12 +329,6 @@ binary_gen(Size) ->
list_to_binary(Bytes)).
%% @private
--spec binary_str_gen(size()) -> {'ok',binary()} | 'error'.
-binary_str_gen(Size) ->
- Len = proper_arith:rand_int(0, Size),
- binary_len_str_gen(Len).
-
-%% @private
-spec binary_rev(binary()) -> imm_instance().
binary_rev(Binary) ->
{'$used', binary_to_list(Binary), Binary}.
@@ -375,11 +341,6 @@ binary_len_gen(Len) ->
list_to_binary(Bytes)).
%% @private
--spec binary_len_str_gen(length()) -> {'ok',binary()} | 'error'.
-binary_len_str_gen(Len) ->
- proper_arith:rand_bytes(Len).
-
-%% @private
-spec bitstring_gen(size()) -> proper_types:type().
bitstring_gen(Size) ->
?LET({BytesHead, NumBits, TailByte},
View
@@ -188,7 +188,7 @@ parallel_commands(Mod, InitialState) ->
parallel_test_case().
gen_parallel_commands(Len, Mod, InitialState, InitFlag) ->
CmdList = gen_commands(Len, Mod, InitialState, InitFlag),
- LenPar = proper_arith:rand_int(?WORKERS, min(Len - 1, ?LIMIT)),
+ LenPar = proper_arith:rand_int(?WORKERS, erlang:min(Len - 1, ?LIMIT)),
{Seq, P} = lists:split(Len - LenPar, CmdList),
State = state_after(Mod, Seq),
Env = mk_env(Seq, 1),
View
@@ -101,19 +101,18 @@
-opaque type() :: {'$type', [type_prop()]}.
-type raw_type() :: type() | [raw_type()] | loose_tuple(raw_type()) | term().
--type type_prop_name() :: 'kind' | 'generator' | 'straight_gen' | 'reverse_gen'
- | 'parts_type' | 'combine' | 'alt_gens'
- | 'shrink_to_parts' | 'size_transform' | 'is_instance'
- | 'shrinkers' | 'noshrink' | 'internal_type'
- | 'internal_types' | 'get_length' | 'split' | 'join'
- | 'get_indices' | 'remove' | 'retrieve' | 'update'
- | 'constraints' | 'content' | 'default'.
+-type type_prop_name() :: 'kind' | 'generator' | 'reverse_gen' | 'parts_type'
+ | 'combine' | 'alt_gens' | 'shrink_to_parts'
+ | 'size_transform' | 'is_instance' | 'shrinkers'
+ | 'noshrink' | 'internal_type' | 'internal_types'
+ | 'get_length' | 'split' | 'join' | 'get_indices'
+ | 'remove' | 'retrieve' | 'update' | 'constraints'
+ | 'content' | 'default'.
-type type_prop_value() :: term().
-type type_prop() ::
{'kind', type_kind()}
| {'generator', proper_gen:generator()}
- | {'straight_gen', proper_gen:straight_gen()}
| {'reverse_gen', proper_gen:reverse_gen()}
| {'parts_type', type()}
| {'combine', proper_gen:combine_fun()}
@@ -485,7 +484,6 @@ atom_test(X) ->
binary() ->
?WRAPPER([
{generator, fun proper_gen:binary_gen/1},
- {straight_gen, fun proper_gen:binary_str_gen/1},
{reverse_gen, fun proper_gen:binary_rev/1},
{is_instance, fun erlang:is_binary/1}
]).
@@ -494,7 +492,6 @@ binary() ->
binary(Len) ->
?WRAPPER([
{generator, fun() -> proper_gen:binary_len_gen(Len) end},
- {straight_gen, fun() -> proper_gen:binary_len_str_gen(Len) end},
{reverse_gen, fun proper_gen:binary_rev/1},
{is_instance, fun(X) -> binary_len_test(X, Len) end}
]).
View
@@ -615,7 +615,6 @@ arguments_not_defined() ->
%% by writing to a string in the process dictionary), statistics printing,
%% standard verbose behaviour
%% TODO: fix compiler warnings
-%% TODO: how to test 'crypto' option?
%% TODO: LET and LETSHRINK testing (these need their intermediate form for
%% standalone instance testing and shrinking) - update needed after
%% fixing the internal shrinking in LETs, use recursive datatypes, like

0 comments on commit d130127

Please sign in to comment.