Skip to content

Commit

Permalink
Migrate all EQC remains to proper (#97)
Browse files Browse the repository at this point in the history
* Migrate all EQC remains to proper

* Fix
  • Loading branch information
kuenishi committed Sep 17, 2023
1 parent 3412f75 commit bbc6566
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 88 deletions.
71 changes: 0 additions & 71 deletions eqc/msgpack_eqc.erl

This file was deleted.

1 change: 0 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
{require_otp_vsn, "22|23|24|25"}.

{erl_opts, [fail_on_warning, debug_info, warn_untyped_record]}.
%%, {parse_transform, eqc_cover}]}.

{xref_checks, [undefined_function_calls]}.
{cover_enabled, true}.
Expand Down
102 changes: 86 additions & 16 deletions test/prop_msgpack.erl
Original file line number Diff line number Diff line change
@@ -1,47 +1,100 @@
%% Copyright (C) 2009-2023 UENISHI Kota
%%
%% Licensed under the Apache License, Version 2.0 (the "License");
%% you may not use this file except in compliance with the License.
%% You may obtain a copy of the License at
%%
%% http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing, software
%% distributed under the License is distributed on an "AS IS" BASIS,
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%% See the License for the specific language governing permissions and
%% limitations under the License.
%%

-module(prop_msgpack).
-include_lib("proper/include/proper.hrl").
-include("msgpack.hrl").


%% -define(NUMTESTS, 16).
%% -define(QC_OUT(P),
%% eqc:on_output(fun(Str, Args) ->
%% io:format(user, Str, Args) end, P)).
%% -define(_assertProp(S),
%% {timeout, ?NUMTESTS * 10,
%% ?_assert(quickcheck(numtests(?NUMTESTS, ?QC_OUT(S))))}).

%% eqc_test_() ->
%% {inparallel,
%% [
%% ?_assertProp(prop_msgpack()),
%% ?_assertProp(prop_msgpack([{format, jiffy}])),
%% ?_assertProp(prop_msgpack([{format, jsx}]))
%% ]}.

%%% Primitive Properties %%%
prop_uint() ->
?FORALL(
UnsignedInt,
oneof([positive_fixnum(), uint8(), uint16(), uint32(), uint64()]),
pack_and_unpack(UnsignedInt)).
{UnsignedInt, Opts},
{oneof([positive_fixnum(), uint8(), uint16(), uint32(), uint64()]),
stable_opts()},
pack_and_unpack(UnsignedInt, Opts)).

prop_int() ->
?FORALL(
Int,
oneof([positive_fixnum(), negative_fixnum(), int8(), int16(), int32(), int64()]),
pack_and_unpack(Int)).
{Int, Opts},
{oneof([positive_fixnum(), negative_fixnum(), int8(), int16(), int32(), int64()]),
stable_opts()},
pack_and_unpack(Int, Opts)).

prop_binary() ->
?FORALL(
Binary,
oneof([fix_raw(), raw16(), raw32()]),
pack_and_unpack(Binary)).
{Binary, Opts},
{oneof([fix_raw(), raw16(), raw32()]), stable_opts()},
pack_and_unpack(Binary, Opts)).

prop_float() ->
?FORALL(
Float,
proper_types:float(),
pack_and_unpack(Float)).
pack_and_unpack(Float, [])).

prop_primitive() ->
?FORALL(
PrimObj,
oneof(primitive_types()),
pack_and_unpack(PrimObj)).
{PrimObj, Opts},
{oneof(primitive_types()), stable_opts()},
pack_and_unpack(PrimObj, Opts)).

prop_array_primitive() ->
?FORALL(
{Array, Opts},
{oneof([fix_array_primitive(), array16_primitive()]), stable_opts()},
pack_and_unpack(Array, Opts)).

prop_msgpack() ->
?FORALL({Obj, Opts},
{msgpack_object(), stable_opts()},
pack_and_unpack(Obj, Opts)).


%%% Helpers %%%
pack_and_unpack(Obj) ->
Bin = msgpack:pack(Obj),
{ok, Obj} = msgpack:unpack(Bin),
pack_and_unpack(Obj, Opts) ->
Bin = msgpack:pack(Obj, Opts),
{ok, Obj} = msgpack:unpack(Bin, Opts),
is_binary(Bin).


%%% Generators %%%
stable_opts() ->
% TODO: build property tests on options
oneof([
[],
[{map_format, jiffy}],
[{map_format, jsx}]
]).

null() -> null.

positive_fixnum() -> choose(0, 127).
Expand Down Expand Up @@ -80,3 +133,20 @@ primitive_types() ->
proper_types:float(), proper_types:bool(),
fix_raw(), raw16(), raw32()
].


container_types() ->
[ fix_array_primitive(), array16_primitive() ].

fix_array_primitive() ->
% up to 2^4-1
resize(15, proper_types:list(oneof(primitive_types()))).

array16_primitive() ->
% Up to 2^16-1, but for performance
resize(128, proper_types:list(oneof(primitive_types()))).


%% TODO: add map
msgpack_object() ->
oneof(container_types() ++ primitive_types()).

0 comments on commit bbc6566

Please sign in to comment.