aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib/test/erl_lint_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'lib/stdlib/test/erl_lint_SUITE.erl')
-rw-r--r--lib/stdlib/test/erl_lint_SUITE.erl150
1 files changed, 140 insertions, 10 deletions
diff --git a/lib/stdlib/test/erl_lint_SUITE.erl b/lib/stdlib/test/erl_lint_SUITE.erl
index 48ddeac478..1614a2722f 100644
--- a/lib/stdlib/test/erl_lint_SUITE.erl
+++ b/lib/stdlib/test/erl_lint_SUITE.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 1999-2013. All Rights Reserved.
+%% Copyright Ericsson AB 1999-2014. 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
@@ -48,6 +48,7 @@
unused_function/1,
unsafe_vars/1,unsafe_vars2/1,
unsafe_vars_try/1,
+ unsized_binary_in_bin_gen_pattern/1,
guard/1, otp_4886/1, otp_4988/1, otp_5091/1, otp_5276/1, otp_5338/1,
otp_5362/1, otp_5371/1, otp_7227/1, otp_5494/1, otp_5644/1, otp_5878/1,
otp_5917/1, otp_6585/1, otp_6885/1, otp_10436/1, otp_11254/1,
@@ -59,7 +60,8 @@
format_warn/1,
on_load_successful/1, on_load_failing/1,
too_many_arguments/1,
- basic_errors/1,bin_syntax_errors/1
+ basic_errors/1,bin_syntax_errors/1,
+ predef/1
]).
% Default timetrap timeout (set in init_per_testcase).
@@ -80,12 +82,13 @@ all() ->
[{group, unused_vars_warn}, export_vars_warn,
shadow_vars, unused_import, unused_function,
unsafe_vars, unsafe_vars2, unsafe_vars_try, guard,
+ unsized_binary_in_bin_gen_pattern,
otp_4886, otp_4988, otp_5091, otp_5276, otp_5338,
otp_5362, otp_5371, otp_7227, otp_5494, otp_5644,
otp_5878, otp_5917, otp_6585, otp_6885, otp_10436, otp_11254,export_all,
bif_clash, behaviour_basic, behaviour_multiple,
otp_7550, otp_8051, format_warn, {group, on_load},
- too_many_arguments, basic_errors, bin_syntax_errors].
+ too_many_arguments, basic_errors, bin_syntax_errors, predef].
groups() ->
[{unused_vars_warn, [],
@@ -573,7 +576,7 @@ unused_vars_warn_rec(Config) when is_list(Config) ->
ok.
unused_vars_warn_fun(doc) ->
- "Warnings for unused variables in records.";
+ "Warnings for unused variables in funs.";
unused_vars_warn_fun(suite) -> [];
unused_vars_warn_fun(Config) when is_list(Config) ->
Ts = [{fun1,
@@ -641,7 +644,60 @@ unused_vars_warn_fun(Config) when is_list(Config) ->
{22,erl_lint,{unused_var,'U'}},
{24,erl_lint,{unused_var,'U'}},
{26,erl_lint,{unused_var,'U'}},
- {26,erl_lint,{shadowed_var,'U','fun'}}]}}
+ {26,erl_lint,{shadowed_var,'U','fun'}}]}},
+ {named_fun,
+ <<"u() ->
+ fun U() -> foo end, % U unused.
+ U; % U unbound.
+ u() ->
+ case foo of
+ true ->
+ U = 2;
+ false ->
+ true
+ end,
+ fun U() -> foo end, % U unused.
+ U; % U unsafe.
+ u() ->
+ case foo of
+ true ->
+ U = 2;
+ false ->
+ U = 3
+ end,
+ fun U() -> foo end, % U shadowed. U unused.
+ U;
+ u() ->
+ case foo of
+ true ->
+ U = 2; % U unused.
+ false ->
+ U = 3 % U unused.
+ end,
+ fun U() -> foo end; % U shadowed. U unused.
+ u() ->
+ fun U(U) -> foo end; % U shadowed. U unused.
+ u() ->
+ fun U(1) -> U; U(U) -> foo end; % U shadowed. U unused.
+ u() ->
+ fun _(N) -> N + 1 end. % Cover handling of '_' name.
+ ">>,
+ [warn_unused_vars],
+ {error,[{3,erl_lint,{unbound_var,'U'}},
+ {12,erl_lint,{unsafe_var,'U',{'case',5}}}],
+ [{2,erl_lint,{unused_var,'U'}},
+ {11,erl_lint,{unused_var,'U'}},
+ {20,erl_lint,{unused_var,'U'}},
+ {20,erl_lint,{shadowed_var,'U','named fun'}},
+ {25,erl_lint,{unused_var,'U'}},
+ {27,erl_lint,{unused_var,'U'}},
+ {29,erl_lint,{unused_var,'U'}},
+ {29,erl_lint,{shadowed_var,'U','named fun'}},
+ {31,erl_lint,{unused_var,'U'}},
+ {31,erl_lint,{unused_var,'U'}},
+ {31,erl_lint,{shadowed_var,'U','fun'}},
+ {33,erl_lint,{unused_var,'U'}},
+ {33,erl_lint,{shadowed_var,'U','fun'}}]}}
],
?line [] = run(Config, Ts),
ok.
@@ -1127,6 +1183,35 @@ unsafe_vars_try(Config) when is_list(Config) ->
?line [] = run(Config, Ts),
ok.
+unsized_binary_in_bin_gen_pattern(doc) ->
+ "Unsized binary fields are forbidden in patterns of bit string generators";
+unsized_binary_in_bin_gen_pattern(suite) -> [];
+unsized_binary_in_bin_gen_pattern(Config) when is_list(Config) ->
+ Ts = [{unsized_binary_in_bin_gen_pattern,
+ <<"t({bc,binary,Bin}) ->
+ << <<X,Tail/binary>> || <<X,Tail/binary>> <= Bin >>;
+ t({bc,bits,Bin}) ->
+ << <<X,Tail/bits>> || <<X,Tail/bits>> <= Bin >>;
+ t({bc,bitstring,Bin}) ->
+ << <<X,Tail/bits>> || <<X,Tail/bitstring>> <= Bin >>;
+ t({lc,binary,Bin}) ->
+ [ {X,Tail} || <<X,Tail/binary>> <= Bin ];
+ t({lc,bits,Bin}) ->
+ [ {X,Tail} || <<X,Tail/bits>> <= Bin ];
+ t({lc,bitstring,Bin}) ->
+ [ {X,Tail} || <<X,Tail/bitstring>> <= Bin ].">>,
+ [],
+ {errors,
+ [{2,erl_lint,unsized_binary_in_bin_gen_pattern},
+ {4,erl_lint,unsized_binary_in_bin_gen_pattern},
+ {6,erl_lint,unsized_binary_in_bin_gen_pattern},
+ {8,erl_lint,unsized_binary_in_bin_gen_pattern},
+ {10,erl_lint,unsized_binary_in_bin_gen_pattern},
+ {12,erl_lint,unsized_binary_in_bin_gen_pattern}],
+ []}}],
+ [] = run(Config, Ts),
+ ok.
+
guard(doc) ->
"OTP-4670. Guards, is_record in particular.";
guard(suite) -> [];
@@ -2170,7 +2255,8 @@ otp_5878(Config) when is_list(Config) ->
<<"-record(r1, {t = case foo of _ -> 3 end}).
-record(r2, {a = case foo of A -> A; _ -> 3 end}).
-record(r3, {a = case foo of A -> A end}).
- t() -> {#r1{},#r2{},#r3{}}.
+ -record(r4, {a = fun _AllowedFunName() -> allowed end}).
+ t() -> {#r1{},#r2{},#r3{},#r4{}}.
">>,
[warn_unused_record],
{errors,[{2,erl_lint,{variable_in_record_def,'A'}},
@@ -2742,7 +2828,24 @@ bif_clash(Config) when is_list(Config) ->
{6,erl_lint,{illegal_guard_local_call,{is_tuple,1}}},
{7,erl_lint,{illegal_guard_local_call,{is_list,1}}},
{8,erl_lint,{illegal_guard_local_call,{is_record,3}}},
- {9,erl_lint,{illegal_guard_local_call,{is_record,3}}}],[]}}
+ {9,erl_lint,{illegal_guard_local_call,{is_record,3}}}],[]}},
+ %% We can also suppress all auto imports at once
+ {clash22,
+ <<"-export([size/1, binary_part/2]).
+ -compile(no_auto_import).
+ size([]) ->
+ 0;
+ size({N,_}) ->
+ N;
+ size([_|T]) ->
+ 1+size(T).
+ binary_part({B,_},{X,Y}) ->
+ binary_part(B,{X,Y});
+ binary_part(B,{X,Y}) ->
+ binary:part(B,X,Y).
+ ">>,
+ [],
+ []}
],
?line [] = run(Config, Ts),
@@ -2774,7 +2877,15 @@ behaviour_basic(Config) when is_list(Config) ->
stop(_) -> ok.
">>,
[],
- []}
+ []},
+
+ {behaviour4,
+ <<"-behavior(application). %% Test callbacks with export_all
+ -compile(export_all).
+ stop(_) -> ok.
+ ">>,
+ [],
+ {warnings,[{1,erl_lint,{undefined_behaviour_func,{start,2},application}}]}}
],
?line [] = run(Config, Ts),
ok.
@@ -3131,6 +3242,23 @@ bin_syntax_errors(Config) ->
[] = run(Config, Ts),
ok.
+predef(doc) ->
+ "Predefined types: array(), digraph(), and so on";
+predef(suite) -> [];
+predef(Config) when is_list(Config) ->
+ W = get_compilation_warnings(Config, "predef", []),
+ [] = W,
+ W2 = get_compilation_warnings(Config, "predef2", []),
+ [{7,erl_lint,{deprecated_type,{array,0},{array,array},"OTP 18.0"}},
+ {12,erl_lint,{deprecated_type,{dict,0},{dict,dict},"OTP 18.0"}},
+ {17,erl_lint,{deprecated_type,{digraph,0},{digraph,graph},"OTP 18.0"}},
+ {27,erl_lint,{deprecated_type,{gb_set,0},{gb_sets,set},"OTP 18.0"}},
+ {32,erl_lint,{deprecated_type,{gb_tree,0},{gb_trees,tree},"OTP 18.0"}},
+ {37,erl_lint,{deprecated_type,{queue,0},{queue,queue},"OTP 18.0"}},
+ {42,erl_lint,{deprecated_type,{set,0},{sets,set},"OTP 18.0"}},
+ {47,erl_lint,{deprecated_type,{tid,0},{ets,tid},"OTP 18.0"}}] = W2,
+ ok.
+
run(Config, Tests) ->
F = fun({N,P,Ws,E}, BadL) ->
case catch run_test(Config, P, Ws) of
@@ -3153,8 +3281,10 @@ get_compilation_warnings(Conf, Filename, Warnings) ->
FileS = binary_to_list(Bin),
{match,[{Start,Length}|_]} = re:run(FileS, "-module.*\\n"),
Test = lists:nthtail(Start+Length, FileS),
- {warnings, Ws} = run_test(Conf, Test, Warnings),
- Ws.
+ case run_test(Conf, Test, Warnings) of
+ {warnings, Ws} -> Ws;
+ [] -> []
+ end.
%% Compiles a test module and returns the list of errors and warnings.