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(error_SUITE).
21
-include("test_server.hrl").
24
head_mismatch_line/1,r11b_binaries/1]).
27
test_lib:recompile(?MODULE),
28
[head_mismatch_line,r11b_binaries].
21
-include_lib("test_server/include/test_server.hrl").
23
-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
24
init_per_group/2,end_per_group/2,
25
head_mismatch_line/1,warnings_as_errors/1, bif_clashes/1]).
27
suite() -> [{ct_hooks,[ts_install_cth]}].
30
test_lib:recompile(error_SUITE),
31
[head_mismatch_line, warnings_as_errors, bif_clashes].
36
init_per_suite(Config) ->
39
end_per_suite(_Config) ->
42
init_per_group(_GroupName, Config) ->
45
end_per_group(_GroupName, Config) ->
49
bif_clashes(Config) when is_list(Config) ->
61
[{4, erl_lint,{call_to_redefined_old_bif,{length,1}}}], []} }],
62
?line [] = run(Config, Ts),
66
-import(x,[length/1]).
72
[{3, erl_lint,{redefine_old_bif_import,{length,1}}}], []} }],
73
?line [] = run(Config, Ts1),
74
Ts00 = [{bif_clashes3,
77
-compile({no_auto_import,[length/1]}).
86
?line [] = run(Config, Ts00),
87
Ts11 = [{bif_clashes4,
90
-compile({no_auto_import,[length/1]}).
91
-import(x,[length/1]).
97
?line [] = run(Config, Ts11),
98
Ts000 = [{bif_clashes5,
102
binary_part(<<1,2,3,4>>,1,2).
104
binary_part(X,Y,Z) ->
105
erlang:binary_part(X,Y,Z).
109
[{4, erl_lint,{call_to_redefined_bif,{binary_part,3}}}]} }],
110
?line [] = run(Config, Ts000),
111
Ts111 = [{bif_clashes6,
114
-import(x,[binary_part/3]).
116
binary_part(<<1,2,3,4>>,1,2).
120
[{3, erl_lint,{redefine_bif_import,{binary_part,3}}}]} }],
121
?line [] = run(Config, Ts111),
122
Ts2 = [{bif_clashes7,
125
-compile({no_auto_import,[length/1]}).
126
-import(x,[length/1]).
134
[{7,erl_lint,{define_import,{length,1}}}],
136
?line [] = run2(Config, Ts2),
137
Ts3 = [{bif_clashes8,
140
-compile({no_auto_import,[length/1]}).
141
t(X) when length(X) > 3 ->
148
[{4,erl_lint,{illegal_guard_local_call,{length,1}}}],
150
?line [] = run2(Config, Ts3),
151
Ts4 = [{bif_clashes9,
154
-compile({no_auto_import,[length/1]}).
155
-import(x,[length/1]).
156
t(X) when length(X) > 3 ->
161
[{5,erl_lint,{illegal_guard_local_call,{length,1}}}],
163
?line [] = run2(Config, Ts4),
30
170
%% Tests that a head mismatch is reported on the correct line (OTP-2125).
31
171
head_mismatch_line(Config) when is_list(Config) ->
42
182
?line {error, [{_Name, E}|_], []} = compile:file(File, [return_errors]),
45
r11b_binaries(Config) when is_list(Config) ->
50
_ when size(Bin) > 20 -> erlang:error(too_long);
51
<<_,T/binary>> -> t1(T);
67
[{5,v3_core,no_binaries},
68
{6,v3_core,no_binaries},
69
{9,v3_core,no_binaries},
70
{13,v3_core,no_binaries},
71
{16,v3_core,no_binaries}],
185
warnings_as_errors(Config) when is_list(Config) ->
186
Ts = [{warnings_as_errors,
192
[export_all,warnings_as_errors],
195
[{3,erl_lint,{unused_var,'A'}}]} }],
73
196
?line [] = run(Config, Ts),
95
236
?line DataDir = ?config(priv_dir, Conf),
96
237
?line Test = ["-module(errors_test). ", Test0],
97
238
?line File = filename:join(DataDir, Filename),
98
?line Opts = [binary,export_all,return|Warnings],
239
?line Opts = [binary,return_errors|Warnings],
99
240
?line ok = file:write_file(File, Test),
101
242
%% Compile once just to print all errors and warnings.
102
?line compile:file(File, [binary,export_all,report|Warnings]),
243
?line compile:file(File, [binary,report|Warnings]),
104
245
%% Test result of compilation.
105
246
?line Res = case compile:file(File, Opts) of
106
{error,[{_File,Es}],Ws} ->
247
{ok,errors_test,_,[{_File,Ws}]} ->
248
%io:format("compile:file(~s,~p) ->~n~p~n",
251
{ok,errors_test,_,[]} ->
252
%io:format("compile:file(~s,~p) ->~n~p~n",
255
{error,[{XFile,Es}],Ws} = _ZZ when is_list(XFile) ->
256
%io:format("compile:file(~s,~p) ->~n~p~n",
259
{error,Es,[{_File,Ws}]} = _ZZ->
260
%io:format("compile:file(~s,~p) ->~n~p~n",
109
264
file:delete(File),