1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
%%
%% %CopyrightBegin%
%%
%% Copyright Ericsson AB 2004-2011. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
%% compliance with the License. You should have received a copy of the
%% Erlang Public License along with this software. If not, it can be
%% retrieved online at http://www.erlang.org/.
%%
%% Software distributed under the License is distributed on an "AS IS"
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%% the License for the specific language governing rights and limitations
%% under the License.
%%
%% %CopyrightEnd%
%%
-module(pmod_SUITE).
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
init_per_group/2,end_per_group/2,
init_per_testcase/2,end_per_testcase/2,
basic/1, otp_8447/1]).
-include_lib("test_server/include/test_server.hrl").
suite() -> [{ct_hooks,[ts_install_cth]}].
all() ->
test_lib:recompile(?MODULE),
[basic, otp_8447].
groups() ->
[].
init_per_suite(Config) ->
Config.
end_per_suite(_Config) ->
ok.
init_per_group(_GroupName, Config) ->
Config.
end_per_group(_GroupName, Config) ->
Config.
init_per_testcase(Case, Config) when is_atom(Case), is_list(Config) ->
Dog = test_server:timetrap(?t:minutes(1)),
[{watchdog,Dog}|Config].
end_per_testcase(Case, Config) when is_atom(Case), is_list(Config) ->
Dog = ?config(watchdog, Config),
?t:timetrap_cancel(Dog),
ok.
basic(Config) when is_list(Config) ->
?line basic_1(Config, []),
?line basic_1(Config, [inline]),
?line basic_1(Config, [{inline,500},inline]),
ok.
basic_1(Config, Opts) ->
io:format("Options: ~p\n", [Opts]),
?line ok = compile_load(pmod_basic, Config, Opts),
?line Prop1 = pmod_basic:new([{a,xb},{b,true},{c,false}]),
?line Prop2 = pmod_basic:new([{y,zz}]),
?line io:format("Prop1 = ~p\n", [Prop1]),
?line io:format("Prop2 = ~p\n", [Prop2]),
?line {a,xb} = Prop1:lookup(a),
?line none = Prop1:lookup(glurf),
?line false = Prop1:or_props([]),
?line true = Prop1:or_props([b,c]),
?line true = Prop1:or_props([b,d]),
?line false = Prop1:or_props([d]),
?line none = Prop2:lookup(kalle),
?line {y,zz} = Prop2:lookup(y),
?line {a,xb} = Prop1:lookup(a),
?line Prop3 = Prop1:prepend({blurf,true}),
?line io:format("Prop3 = ~p\n", [Prop3]),
?line {blurf,true} = Prop3:lookup(blurf),
Prop4 = Prop3:append(42),
?line io:format("Prop4 = ~p\n", [Prop4]),
?line {42,5} = Prop4:stupid_sum(),
%% Some record guards.
?line ok = Prop4:bar({s,0}),
?line ok = Prop4:bar_bar({s,blurf}),
?line error = Prop4:bar_bar({s,a,b}),
?line error = Prop4:bar_bar([]),
ok.
otp_8447(Config) when is_list(Config) ->
?line P = pmod_basic:new(foo),
?line [0,0,1,1,1,0,0,1] = P:bc1(),
?line <<10:4>> = P:bc2(),
ok.
compile_load(Module, Conf, Opts) ->
?line Dir = ?config(data_dir,Conf),
?line Src = filename:join(Dir, atom_to_list(Module)),
?line Out = ?config(priv_dir,Conf),
?line CompRc = compile:file(Src, [report,{outdir,Out}|Opts]),
?line {ok,Module} = CompRc,
?line code:purge(Module),
?line {module,Module} =
code:load_abs(filename:join(Out, atom_to_list(Module))),
ok.
|