~ubuntu-branches/ubuntu/trusty/erlang/trusty

« back to all changes in this revision

Viewing changes to lib/compiler/test/error_SUITE.erl

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2011-05-05 15:48:43 UTC
  • mfrom: (3.5.13 sid)
  • Revision ID: james.westby@ubuntu.com-20110505154843-0om6ekzg6m7ugj27
Tags: 1:14.b.2-dfsg-3ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Drop libwxgtk2.8-dev build dependency. Wx isn't in main, and not
    supposed to.
  - Drop erlang-wx binary.
  - Drop erlang-wx dependency from -megaco, -common-test, and -reltool, they
    do not really need wx. Also drop it from -debugger; the GUI needs wx,
    but it apparently has CLI bits as well, and is also needed by -megaco,
    so let's keep the package for now.
  - debian/patches/series: Do what I meant, and enable build-options.patch
    instead.
* Additional changes:
  - Drop erlang-wx from -et
* Dropped Changes:
  - patches/pcre-crash.patch: CVE-2008-2371: outer level option with
    alternatives caused crash. (Applied Upstream)
  - fix for ssl certificate verification in newSSL: 
    ssl_cacertfile_fix.patch (Applied Upstream)
  - debian/patches/series: Enable native.patch again, to get stripped beam
    files and reduce the package size again. (build-options is what
    actually accomplished this)
  - Remove build-options.patch on advice from upstream and because it caused
    odd build failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
%%
2
2
%% %CopyrightBegin%
3
 
%% 
4
 
%% Copyright Ericsson AB 1998-2009. All Rights Reserved.
5
 
%% 
 
3
%%
 
4
%% Copyright Ericsson AB 1998-2011. All Rights Reserved.
 
5
%%
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/.
11
 
%% 
 
11
%%
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.
16
 
%% 
 
16
%%
17
17
%% %CopyrightEnd%
18
18
%%
19
19
-module(error_SUITE).
20
20
 
21
 
-include("test_server.hrl").
22
 
 
23
 
-export([all/1,
24
 
         head_mismatch_line/1,r11b_binaries/1]).
25
 
 
26
 
all(suite) ->
27
 
    test_lib:recompile(?MODULE),
28
 
    [head_mismatch_line,r11b_binaries].
 
21
-include_lib("test_server/include/test_server.hrl").
 
22
 
 
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]).
 
26
 
 
27
suite() -> [{ct_hooks,[ts_install_cth]}].
 
28
 
 
29
all() -> 
 
30
    test_lib:recompile(error_SUITE),
 
31
    [head_mismatch_line, warnings_as_errors, bif_clashes].
 
32
 
 
33
groups() -> 
 
34
    [].
 
35
 
 
36
init_per_suite(Config) ->
 
37
    Config.
 
38
 
 
39
end_per_suite(_Config) ->
 
40
    ok.
 
41
 
 
42
init_per_group(_GroupName, Config) ->
 
43
    Config.
 
44
 
 
45
end_per_group(_GroupName, Config) ->
 
46
    Config.
 
47
 
 
48
 
 
49
bif_clashes(Config) when is_list(Config) ->
 
50
    Ts = [{bif_clashes1,
 
51
           <<"
 
52
              -export([t/0]).
 
53
              t() ->
 
54
                 length([a,b,c]).
 
55
 
 
56
              length(X) ->
 
57
               erlang:length(X).
 
58
             ">>,
 
59
           [return_warnings],
 
60
           {error,
 
61
            [{4, erl_lint,{call_to_redefined_old_bif,{length,1}}}], []} }],
 
62
    ?line [] = run(Config, Ts),
 
63
    Ts1 = [{bif_clashes2,
 
64
           <<"
 
65
              -export([t/0]).
 
66
              -import(x,[length/1]).
 
67
              t() ->
 
68
                 length([a,b,c]).
 
69
             ">>,
 
70
           [return_warnings],
 
71
            {error,
 
72
             [{3, erl_lint,{redefine_old_bif_import,{length,1}}}], []} }],
 
73
    ?line [] = run(Config, Ts1),
 
74
    Ts00 = [{bif_clashes3,
 
75
           <<"
 
76
              -export([t/0]).
 
77
              -compile({no_auto_import,[length/1]}).
 
78
              t() ->
 
79
                 length([a,b,c]).
 
80
 
 
81
              length(X) ->
 
82
               erlang:length(X).
 
83
             ">>,
 
84
           [return_warnings],
 
85
           []}],
 
86
    ?line [] = run(Config, Ts00),
 
87
    Ts11 = [{bif_clashes4,
 
88
           <<"
 
89
              -export([t/0]).
 
90
              -compile({no_auto_import,[length/1]}).
 
91
              -import(x,[length/1]).
 
92
              t() ->
 
93
                 length([a,b,c]).
 
94
             ">>,
 
95
           [return_warnings],
 
96
            []}],
 
97
    ?line [] = run(Config, Ts11),
 
98
    Ts000 = [{bif_clashes5,
 
99
           <<"
 
100
              -export([t/0]).
 
101
              t() ->
 
102
                 binary_part(<<1,2,3,4>>,1,2).
 
103
 
 
104
              binary_part(X,Y,Z) ->
 
105
               erlang:binary_part(X,Y,Z).
 
106
             ">>,
 
107
           [return_warnings],
 
108
           {warning,
 
109
            [{4, erl_lint,{call_to_redefined_bif,{binary_part,3}}}]} }],
 
110
    ?line [] = run(Config, Ts000),
 
111
    Ts111 = [{bif_clashes6,
 
112
           <<"
 
113
              -export([t/0]).
 
114
              -import(x,[binary_part/3]).
 
115
              t() ->
 
116
                  binary_part(<<1,2,3,4>>,1,2).
 
117
             ">>,
 
118
           [return_warnings],
 
119
            {warning,
 
120
             [{3, erl_lint,{redefine_bif_import,{binary_part,3}}}]} }],
 
121
    ?line [] = run(Config, Ts111),
 
122
    Ts2 = [{bif_clashes7,
 
123
           <<"
 
124
              -export([t/0]).
 
125
              -compile({no_auto_import,[length/1]}).
 
126
              -import(x,[length/1]).
 
127
              t() ->
 
128
                 length([a,b,c]).
 
129
              length(X) ->
 
130
                 erlang:length(X).
 
131
             ">>,
 
132
           [],
 
133
          {error,
 
134
           [{7,erl_lint,{define_import,{length,1}}}],
 
135
           []} }],
 
136
    ?line [] = run2(Config, Ts2),
 
137
    Ts3 = [{bif_clashes8,
 
138
           <<"
 
139
              -export([t/1]).
 
140
              -compile({no_auto_import,[length/1]}).
 
141
              t(X) when length(X) > 3 ->
 
142
                 length([a,b,c]).
 
143
              length(X) ->
 
144
                 erlang:length(X).
 
145
             ">>,
 
146
           [],
 
147
          {error,
 
148
           [{4,erl_lint,{illegal_guard_local_call,{length,1}}}],
 
149
           []} }],
 
150
    ?line [] = run2(Config, Ts3),
 
151
    Ts4 = [{bif_clashes9,
 
152
           <<"
 
153
              -export([t/1]).
 
154
              -compile({no_auto_import,[length/1]}).
 
155
              -import(x,[length/1]).
 
156
              t(X) when length(X) > 3 ->
 
157
                 length([a,b,c]).
 
158
             ">>,
 
159
           [],
 
160
          {error,
 
161
           [{5,erl_lint,{illegal_guard_local_call,{length,1}}}],
 
162
           []} }],
 
163
    ?line [] = run2(Config, Ts4),
 
164
 
 
165
    ok.
 
166
 
 
167
 
 
168
 
29
169
 
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]),
43
183
    E.
44
184
 
45
 
r11b_binaries(Config) when is_list(Config) ->
46
 
    Ts = [{r11b_binaries,
47
 
           <<"
48
 
             t1(Bin) ->
49
 
               case Bin of
50
 
                 _ when size(Bin) > 20 -> erlang:error(too_long);
51
 
                 <<_,T/binary>> -> t1(T);
52
 
                 <<>> -> ok
53
 
             end.
54
 
 
55
 
             t2(<<_,T/bytes>>) ->
56
 
               split_binary(T, 4).
57
 
 
58
 
             t3(X) ->
59
 
               <<42,X/binary>>.
60
 
 
61
 
             t4(X) ->
62
 
               <<N:32>> = X,
63
 
               N.
64
 
           ">>,
65
 
           [r11],
66
 
           {error,
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}],
72
 
            []} }],
 
185
warnings_as_errors(Config) when is_list(Config) ->
 
186
    Ts = [{warnings_as_errors,
 
187
           <<"
 
188
               t() ->
 
189
                 A = unused,
 
190
                 ok.
 
191
             ">>,
 
192
           [export_all,warnings_as_errors],
 
193
          {error,
 
194
           [],
 
195
           [{3,erl_lint,{unused_var,'A'}}]} }],
73
196
    ?line [] = run(Config, Ts),
74
197
    ok.
75
198
 
87
210
        end,
88
211
    lists:foldl(F, [], Tests).
89
212
 
 
213
run2(Config, Tests) ->
 
214
    F = fun({N,P,Ws,E}, BadL) ->
 
215
                case catch filter(run_test(Config, P, Ws)) of
 
216
                    E ->
 
217
                        BadL;
 
218
                    Bad ->
 
219
                        ?t:format("~nTest ~p failed. Expected~n  ~p~n"
 
220
                                  "but got~n  ~p~n", [N, E, Bad]),
 
221
                        fail()
 
222
                end
 
223
        end,
 
224
    lists:foldl(F, [], Tests).
 
225
 
 
226
filter({error,Es,_Ws}) ->
 
227
    {error,Es,[]};
 
228
filter(X) ->
 
229
    X.
 
230
 
90
231
 
91
232
%% Compiles a test module and returns the list of errors and warnings.
92
233
 
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),
100
241
 
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]),
103
244
 
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",
 
249
                        %         [File,Opts,Ws]),
 
250
                        {warning,Ws};
 
251
                    {ok,errors_test,_,[]} ->
 
252
                        %io:format("compile:file(~s,~p) ->~n~p~n",
 
253
                        %         [File,Opts,Ws]),
 
254
                        [];
 
255
                    {error,[{XFile,Es}],Ws} = _ZZ when is_list(XFile) ->
 
256
                        %io:format("compile:file(~s,~p) ->~n~p~n",
 
257
                        %         [File,Opts,_ZZ]),
 
258
                        {error,Es,Ws};
 
259
                    {error,Es,[{_File,Ws}]} = _ZZ->
 
260
                        %io:format("compile:file(~s,~p) ->~n~p~n",
 
261
                        %         [File,Opts,_ZZ]),
107
262
                        {error,Es,Ws}
108
263
                end,
109
264
    file:delete(File),