4
%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 1998-2011. All Rights Reserved.
6
6
%% The contents of this file are subject to the Erlang Public License,
7
7
%% Version 1.1, (the "License"); you may not use this file except in
8
8
%% compliance with the License. You should have received a copy of the
9
9
%% Erlang Public License along with this software. If not, it can be
10
10
%% retrieved online at http://www.erlang.org/.
12
12
%% Software distributed under the License is distributed on an "AS IS"
13
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
14
%% the License for the specific language governing rights and limitations
15
15
%% under the License.
19
19
-module(epp_SUITE).
20
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
21
init_per_group/2,end_per_group/2]).
22
-export([rec_1/1, predef_mac/1,
23
upcase_mac/1, upcase_mac_1/1, upcase_mac_2/1,
24
variable/1, variable_1/1, otp_4870/1, otp_4871/1, otp_5362/1,
23
-export([rec_1/1, predef_mac/1,
24
upcase_mac_1/1, upcase_mac_2/1,
25
variable_1/1, otp_4870/1, otp_4871/1, otp_5362/1,
25
26
pmod/1, not_circular/1, skip_header/1, otp_6277/1, otp_7702/1,
27
otp_8130/1, overload_mac/1, otp_8388/1, otp_8470/1, otp_8503/1,
28
otp_8562/1, otp_8665/1, otp_8911/1]).
28
30
-export([epp_parse_erl_form/2]).
52
54
init_per_testcase(_, Config) ->
53
55
?line Dog = ?t:timetrap(?default_timeout),
54
56
[{watchdog, Dog} | Config].
55
fin_per_testcase(_, Config) ->
57
end_per_testcase(_, Config) ->
56
58
Dog = ?config(watchdog, Config),
57
59
test_server:timetrap_cancel(Dog),
62
["Test cases for epp."];
64
[rec_1, upcase_mac, predef_mac, variable, otp_4870, otp_4871, otp_5362,
65
pmod, not_circular, skip_header, otp_6277, otp_7702, otp_8130].
63
suite() -> [{ct_hooks,[ts_install_cth]}].
66
[rec_1, {group, upcase_mac}, predef_mac,
67
{group, variable}, otp_4870, otp_4871, otp_5362, pmod,
68
not_circular, skip_header, otp_6277, otp_7702, otp_8130,
69
overload_mac, otp_8388, otp_8470, otp_8503, otp_8562,
73
[{upcase_mac, [], [upcase_mac_1, upcase_mac_2]},
74
{variable, [], [variable_1]}].
76
init_per_suite(Config) ->
79
end_per_suite(_Config) ->
82
init_per_group(_GroupName, Config) ->
85
end_per_group(_GroupName, Config) ->
68
89
["Recursive macros hang or crash epp (OTP-1398)."];
1031
1052
?line [] = run(Config, Ts).
1056
overload_mac(doc) ->
1057
["Advanced test on overloading macros."];
1058
overload_mac(suite) ->
1060
overload_mac(Config) when is_list(Config) ->
1062
%% '-undef' removes all definitions of a macro
1064
<<"-define(A, a).\n"
1065
"-define(A(X), X).\n"
1069
{errors,[{{4,10},epp,{undefined,'A', none}},
1070
{{5,10},epp,{undefined,'A', 1}}],[]}},
1072
%% cannot overload predefined macros
1074
<<"-define(MODULE(X), X).">>,
1075
{errors,[{{1,50},epp,{redefine_predef,'MODULE'}}],[]}},
1077
%% cannot overload macros with same arity
1079
<<"-define(A(X), X).\n"
1080
"-define(A(Y), Y).">>,
1081
{errors,[{{2,9},epp,{redefine,'A'}}],[]}},
1084
<<"-define(A, a).\n"
1085
"-define(A(X,Y), {X,Y}).\n"
1088
{errors,[{{4,9},epp,{mismatch,'A'}}],[]}}
1090
?line [] = compile(Config, Cs),
1094
<<"-define(A, 1).\n"
1095
"-define(A(X), X).\n"
1096
"-define(A(X, Y), {X, Y}).\n"
1097
"t() -> {?A, ?A(2), ?A(3, 4)}.">>,
1101
<<"-define(A, 1).\n"
1102
"-define(A(X), X).\n"
1107
<<"-define(A, ?B).\n"
1109
"-define(B(X), {b,X}).\n"
1114
?line [] = run(Config, Ts).
1118
["OTP-8388. More tests on overloaded macros."];
1121
otp_8388(Config) when is_list(Config) ->
1122
Dir = ?config(priv_dir, Config),
1123
?line File = filename:join(Dir, "otp_8388.erl"),
1124
?line ok = file:write_file(File, <<"-module(otp_8388)."
1125
"-define(LINE, a).">>),
1127
PreDefMacros = [{'LINE', a}],
1128
?line {error,{redefine_predef,'LINE'}} =
1129
epp:open(File, [], PreDefMacros)
1133
PreDefMacros = ['LINE'],
1134
?line {error,{redefine_predef,'LINE'}} =
1135
epp:open(File, [], PreDefMacros)
1140
<<"-define(m(A), A).\n"
1141
"t() -> ?m(,).\n">>,
1142
{errors,[{{2,9},epp,{arg_error,m}}],[]}},
1144
<<"-define(m(A), A).\n"
1145
"t() -> ?m(a,).\n">>,
1146
{errors,[{{2,9},epp,{arg_error,m}}],[]}},
1148
<<"-define(LINE, a).\n">>,
1149
{errors,[{{1,50},epp,{redefine_predef,'LINE'}}],[]}},
1151
<<"-define(A(B, C, D), {B,C,D}).\n"
1152
"t() -> ?A(a,,3).\n">>,
1153
{errors,[{{2,9},epp,{mismatch,'A'}}],[]}},
1155
<<"-define(Q, {?F0(), ?F1(,,4)}).\n">>,
1156
{errors,[{{1,62},epp,{arg_error,'F1'}}],[]}},
1158
<<"-define(FOO(X), ?BAR(X)).\n"
1159
"-define(BAR(X), ?FOO(X)).\n"
1161
"test() -> ?BAR(1).\n">>,
1162
{errors,[{{4,12},epp,{undefined,'FOO',1}}],[]}}
1164
?line [] = compile(Config, Ts),
1168
["OTP-8470. Bugfix (one request - two replies)."];
1171
otp_8470(Config) when is_list(Config) ->
1172
Dir = ?config(priv_dir, Config),
1173
C = <<"-file(\"erl_parse.yrl\", 486).\n"
1174
"-file(\"erl_parse.yrl\", 488).\n">>,
1175
?line File = filename:join(Dir, "otp_8470.erl"),
1176
?line ok = file:write_file(File, C),
1177
?line {ok, _List} = epp:parse_file(File, [], []),
1179
?line receive _ -> fail() after 0 -> ok end,
1183
["OTP-8503. Record with no fields is considered typed."];
1186
otp_8503(Config) when is_list(Config) ->
1187
Dir = ?config(priv_dir, Config),
1188
C = <<"-record(r, {}).">>,
1189
?line File = filename:join(Dir, "otp_8503.erl"),
1190
?line ok = file:write_file(File, C),
1191
?line {ok, List} = epp:parse_file(File, [], []),
1192
?line [_] = [F || {attribute,_,type,{{record,r},[],[]}}=F <- List],
1194
?line receive _ -> fail() after 0 -> ok end,
1198
["OTP-8503. Record with no fields is considered typed."];
1201
otp_8562(Config) when is_list(Config) ->
1203
<<"-define(P(), {a,b}.\n"
1204
"-define(P3, .\n">>,
1205
{errors,[{{1,60},epp,missing_parenthesis},
1206
{{2,13},epp,missing_parenthesis}], []}}
1208
?line [] = compile(Config, Cs),
1212
["OTP-8911. -file and file inclusion bug"];
1215
otp_8911(Config) when is_list(Config) ->
1216
?line {ok, CWD} = file:get_cwd(),
1217
?line ok = file:set_cwd(?config(priv_dir, Config)),
1220
Cont = <<"-module(i).
1221
-compile(export_all).
1222
-file(\"fil1\", 100).
1223
-include(\"i1.erl\").
1227
?line ok = file:write_file(File, Cont),
1228
Incl = <<"-file(\"fil2\", 35).
1233
?line ok = file:write_file(File1, Incl),
1235
?line {ok, i} = cover:compile(File),
1237
?line {ok,[{{i,6},1}]} = cover:analyse(i, calls, line),
1242
?line file:set_cwd(CWD),
1246
["OTP-8665. Bugfix premature end."];
1249
otp_8665(Config) when is_list(Config) ->
1251
<<"-define(A, a)\n">>,
1252
{errors,[{{1,54},epp,premature_end}],[]}}
1254
?line [] = compile(Config, Cs),
1033
1257
check(Config, Tests) ->
1034
1258
eval_tests(Config, fun check_test/2, Tests).