Skip to content

Commit bbc6566

Browse files
authored
Migrate all EQC remains to proper (#97)
* Migrate all EQC remains to proper * Fix
1 parent 3412f75 commit bbc6566

File tree

3 files changed

+86
-88
lines changed

3 files changed

+86
-88
lines changed

eqc/msgpack_eqc.erl

Lines changed: 0 additions & 71 deletions
This file was deleted.

rebar.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
{require_otp_vsn, "22|23|24|25"}.
55

66
{erl_opts, [fail_on_warning, debug_info, warn_untyped_record]}.
7-
%%, {parse_transform, eqc_cover}]}.
87

98
{xref_checks, [undefined_function_calls]}.
109
{cover_enabled, true}.

test/prop_msgpack.erl

Lines changed: 86 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,100 @@
1+
%% Copyright (C) 2009-2023 UENISHI Kota
2+
%%
3+
%% Licensed under the Apache License, Version 2.0 (the "License");
4+
%% you may not use this file except in compliance with the License.
5+
%% You may obtain a copy of the License at
6+
%%
7+
%% http://www.apache.org/licenses/LICENSE-2.0
8+
%%
9+
%% Unless required by applicable law or agreed to in writing, software
10+
%% distributed under the License is distributed on an "AS IS" BASIS,
11+
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
%% See the License for the specific language governing permissions and
13+
%% limitations under the License.
14+
%%
15+
116
-module(prop_msgpack).
217
-include_lib("proper/include/proper.hrl").
318
-include("msgpack.hrl").
419

520

21+
%% -define(NUMTESTS, 16).
22+
%% -define(QC_OUT(P),
23+
%% eqc:on_output(fun(Str, Args) ->
24+
%% io:format(user, Str, Args) end, P)).
25+
%% -define(_assertProp(S),
26+
%% {timeout, ?NUMTESTS * 10,
27+
%% ?_assert(quickcheck(numtests(?NUMTESTS, ?QC_OUT(S))))}).
28+
29+
%% eqc_test_() ->
30+
%% {inparallel,
31+
%% [
32+
%% ?_assertProp(prop_msgpack()),
33+
%% ?_assertProp(prop_msgpack([{format, jiffy}])),
34+
%% ?_assertProp(prop_msgpack([{format, jsx}]))
35+
%% ]}.
36+
637
%%% Primitive Properties %%%
738
prop_uint() ->
839
?FORALL(
9-
UnsignedInt,
10-
oneof([positive_fixnum(), uint8(), uint16(), uint32(), uint64()]),
11-
pack_and_unpack(UnsignedInt)).
40+
{UnsignedInt, Opts},
41+
{oneof([positive_fixnum(), uint8(), uint16(), uint32(), uint64()]),
42+
stable_opts()},
43+
pack_and_unpack(UnsignedInt, Opts)).
1244

1345
prop_int() ->
1446
?FORALL(
15-
Int,
16-
oneof([positive_fixnum(), negative_fixnum(), int8(), int16(), int32(), int64()]),
17-
pack_and_unpack(Int)).
47+
{Int, Opts},
48+
{oneof([positive_fixnum(), negative_fixnum(), int8(), int16(), int32(), int64()]),
49+
stable_opts()},
50+
pack_and_unpack(Int, Opts)).
1851

1952
prop_binary() ->
2053
?FORALL(
21-
Binary,
22-
oneof([fix_raw(), raw16(), raw32()]),
23-
pack_and_unpack(Binary)).
54+
{Binary, Opts},
55+
{oneof([fix_raw(), raw16(), raw32()]), stable_opts()},
56+
pack_and_unpack(Binary, Opts)).
2457

2558
prop_float() ->
2659
?FORALL(
2760
Float,
2861
proper_types:float(),
29-
pack_and_unpack(Float)).
62+
pack_and_unpack(Float, [])).
3063

3164
prop_primitive() ->
3265
?FORALL(
33-
PrimObj,
34-
oneof(primitive_types()),
35-
pack_and_unpack(PrimObj)).
66+
{PrimObj, Opts},
67+
{oneof(primitive_types()), stable_opts()},
68+
pack_and_unpack(PrimObj, Opts)).
69+
70+
prop_array_primitive() ->
71+
?FORALL(
72+
{Array, Opts},
73+
{oneof([fix_array_primitive(), array16_primitive()]), stable_opts()},
74+
pack_and_unpack(Array, Opts)).
75+
76+
prop_msgpack() ->
77+
?FORALL({Obj, Opts},
78+
{msgpack_object(), stable_opts()},
79+
pack_and_unpack(Obj, Opts)).
3680

3781

3882
%%% Helpers %%%
39-
pack_and_unpack(Obj) ->
40-
Bin = msgpack:pack(Obj),
41-
{ok, Obj} = msgpack:unpack(Bin),
83+
pack_and_unpack(Obj, Opts) ->
84+
Bin = msgpack:pack(Obj, Opts),
85+
{ok, Obj} = msgpack:unpack(Bin, Opts),
4286
is_binary(Bin).
4387

88+
4489
%%% Generators %%%
90+
stable_opts() ->
91+
% TODO: build property tests on options
92+
oneof([
93+
[],
94+
[{map_format, jiffy}],
95+
[{map_format, jsx}]
96+
]).
97+
4598
null() -> null.
4699

47100
positive_fixnum() -> choose(0, 127).
@@ -80,3 +133,20 @@ primitive_types() ->
80133
proper_types:float(), proper_types:bool(),
81134
fix_raw(), raw16(), raw32()
82135
].
136+
137+
138+
container_types() ->
139+
[ fix_array_primitive(), array16_primitive() ].
140+
141+
fix_array_primitive() ->
142+
% up to 2^4-1
143+
resize(15, proper_types:list(oneof(primitive_types()))).
144+
145+
array16_primitive() ->
146+
% Up to 2^16-1, but for performance
147+
resize(128, proper_types:list(oneof(primitive_types()))).
148+
149+
150+
%% TODO: add map
151+
msgpack_object() ->
152+
oneof(container_types() ++ primitive_types()).

0 commit comments

Comments
 (0)