4
%% Copyright Ericsson AB 1997-2009. All Rights Reserved.
4
%% Copyright Ericsson AB 1997-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(compile_SUITE).
21
21
%% Tests compile:file/1 and compile:file/2 with various options.
23
-include("test_server.hrl").
23
-include_lib("test_server/include/test_server.hrl").
25
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
26
init_per_group/2,end_per_group/2,
27
28
file_1/1, module_mismatch/1, big_file/1, outdir/1,
28
binary/1, cond_and_ifdef/1, listings/1, listings_big/1,
29
binary/1, makedep/1, cond_and_ifdef/1, listings/1, listings_big/1,
29
30
other_output/1, package_forms/1, encrypted_abstr/1,
30
bad_record_use/1, bad_record_use1/1, bad_record_use2/1, strict_record/1,
31
bad_record_use1/1, bad_record_use2/1, strict_record/1,
31
32
missing_testheap/1, cover/1, env/1, core/1, asm/1]).
36
suite() -> [{ct_hooks,[ts_install_cth]}].
36
38
%% To cover the stripping of 'type' and 'spec' in beam_asm.
37
39
-type all_return_type() :: [atom()].
38
-spec all('suite' | [_]) -> all_return_type().
40
-spec all() -> all_return_type().
41
test_lib:recompile(?MODULE),
43
file_1, module_mismatch, big_file, outdir, binary,
44
cond_and_ifdef, listings, listings_big,
45
other_output, package_forms,
47
bad_record_use, strict_record,
43
test_lib:recompile(compile_SUITE),
44
[app_test, file_1, module_mismatch, big_file, outdir,
45
binary, makedep, cond_and_ifdef, listings, listings_big,
46
other_output, package_forms, encrypted_abstr,
47
{group, bad_record_use}, strict_record,
48
48
missing_testheap, cover, env, core, asm].
52
[bad_record_use1, bad_record_use2]}].
54
init_per_suite(Config) ->
57
end_per_suite(_Config) ->
60
init_per_group(_GroupName, Config) ->
63
end_per_group(_GroupName, Config) ->
51
68
%% Test that the Application file has no `basic' errors.";
52
69
app_test(Config) when is_list(Config) ->
132
149
?line test_server:timetrap_cancel(Dog),
152
%% Tests that the dependencies-Makefile-related options work.
154
makedep(Config) when is_list(Config) ->
155
?line Dog = test_server:timetrap(test_server:seconds(60)),
156
?line {Simple,Target} = files(Config, "makedep"),
157
?line DataDir = ?config(data_dir, Config),
158
?line SimpleRootname = filename:rootname(Simple),
159
?line IncludeDir = filename:join(filename:dirname(Simple), "include"),
160
?line IncludeOptions = [
163
{d,include_generated},
167
?line BasicMf1Name = SimpleRootname ++ "-basic1.mk",
168
?line {ok,BasicMf1} = file:read_file(BasicMf1Name),
169
?line {ok,_,Mf1} = compile:file(Simple, [binary,makedep]),
170
?line BasicMf1 = makedep_canonicalize_result(Mf1, DataDir),
171
%% Basic rule with one existing header.
172
?line BasicMf2Name = SimpleRootname ++ "-basic2.mk",
173
?line {ok,BasicMf2} = file:read_file(BasicMf2Name),
174
?line {ok,_,Mf2} = compile:file(Simple, [binary,makedep|IncludeOptions]),
175
?line BasicMf2 = makedep_canonicalize_result(Mf2, DataDir),
176
%% Rule with one existing header and one missing header.
177
?line MissingMfName = SimpleRootname ++ "-missing.mk",
178
?line {ok,MissingMf} = file:read_file(MissingMfName),
179
?line {ok,_,Mf3} = compile:file(Simple,
180
[binary,makedep,makedep_add_missing|IncludeOptions]),
181
?line MissingMf = makedep_canonicalize_result(Mf3, DataDir),
182
%% Rule with modified target.
183
?line TargetMf1Name = SimpleRootname ++ "-target1.mk",
184
?line {ok,TargetMf1} = file:read_file(TargetMf1Name),
185
?line {ok,_,Mf4} = compile:file(Simple,
186
[binary,makedep,{makedep_target,"$target"}|IncludeOptions]),
187
?line TargetMf1 = makedep_modify_target(
188
makedep_canonicalize_result(Mf4, DataDir), "$$target"),
189
%% Rule with quoted modified target.
190
?line TargetMf2Name = SimpleRootname ++ "-target2.mk",
191
?line {ok,TargetMf2} = file:read_file(TargetMf2Name),
192
?line {ok,_,Mf5} = compile:file(Simple,
193
[binary,makedep,{makedep_target,"$target"},makedep_quote_target|
195
?line TargetMf2 = makedep_modify_target(
196
makedep_canonicalize_result(Mf5, DataDir), "$$target"),
197
%% Basic rule written to some file.
198
?line {ok,_} = compile:file(Simple,
199
[makedep,{makedep_output,Target}|IncludeOptions]),
200
?line {ok,Mf6} = file:read_file(Target),
201
?line BasicMf2 = makedep_canonicalize_result(Mf6, DataDir),
203
?line ok = file:delete(Target),
204
?line ok = file:del_dir(filename:dirname(Target)),
205
?line test_server:timetrap_cancel(Dog),
208
makedep_canonicalize_result(Mf, DataDir) ->
209
Mf0 = binary_to_list(Mf),
210
%% Replace the Datadir by "$(srcdir)".
211
Mf1 = re:replace(Mf0, DataDir, "$(srcdir)/",
212
[global,multiline,{return,list}]),
213
%% Long lines are splitted, put back everything on one line.
214
Mf2 = re:replace(Mf1, "\\\\\n ", "", [global,multiline,{return,list}]),
217
makedep_modify_target(Mf, Target) ->
218
Mf0 = binary_to_list(Mf),
219
Mf1 = re:replace(Mf0, Target, "$target", [{return,list}]),
135
222
%% Tests that conditional compilation, defining values, including files work.
137
224
cond_and_ifdef(Config) when is_list(Config) ->
688
774
[M,Class,Error,erlang:get_stacktrace()]),
692
%% p_run(fun() -> ok|error, List) -> ok
693
%% Will fail the test case if there were any errors.
696
N = erlang:system_info(schedulers) + 1,
697
p_run_loop(Test, List, N, [], 0, 0).
699
p_run_loop(_, [], _, [], Errors, Ws) ->
704
1 -> {comment,"1 core_lint failure"};
705
N -> {comment,integer_to_list(N)++" core_lint failures"}
707
N -> ?t:fail({N,errors})
709
p_run_loop(Test, [H|T], N, Refs, Errors, Ws) when length(Refs) < N ->
710
{_,Ref} = erlang:spawn_monitor(fun() -> exit(Test(H)) end),
711
p_run_loop(Test, T, N, [Ref|Refs], Errors, Ws);
712
p_run_loop(Test, List, N, Refs0, Errors0, Ws0) ->
714
{'DOWN',Ref,process,_,Res} ->
715
{Errors,Ws} = case Res of
717
error -> {Errors0+1,Ws0};
718
warning -> {Errors0,Ws0+1}
720
Refs = Refs0 -- [Ref],
721
p_run_loop(Test, List, N, Refs, Errors, Ws)