Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/compiler/test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ DIALYZER_ERL_FILES= $(DIALYZER_MODULES:%=%.erl)
COVER_MODULES= $(COVER:%=%_cover_SUITE)
COVER_ERL_FILES= $(COVER_MODULES:%=%.erl)

HRL_FILES= test_lib.hrl
ERL_FILES= $(MODULES:%=%.erl)
CORE_FILES= $(CORE_MODULES:%=%.core)
ERL_DUMMY_FILES= $(CORE_MODULES:%=%.erl)
Expand Down Expand Up @@ -328,6 +329,7 @@ release_tests_spec: make_emakefile
$(NO_TYPE_OPT_ERL_FILES) \
$(COVER_ERL_FILES) \
$(DIALYZER_ERL_FILES) "$(RELSYSDIR)"
$(INSTALL_DATA) $(HRL_FILES) "$(RELSYSDIR)"
$(INSTALL_DATA) $(CORE_FILES) "$(RELSYSDIR)"
for file in $(ERL_DUMMY_FILES); do \
module=`basename $$file .erl`; \
Expand Down
37 changes: 19 additions & 18 deletions lib/compiler/test/andor_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
init_per_group/2,end_per_group/2,
t_case/1,t_and_or/1,t_andalso/1,t_orelse/1,inside/1,overlap/1,
combined/1,in_case/1,slow_compilation/1]).

-include_lib("common_test/include/ct.hrl").
-include_lib("stdlib/include/assert.hrl").

suite() -> [{ct_hooks,[ts_install_cth]}].

Expand Down Expand Up @@ -57,16 +58,16 @@ t_case(Config) when is_list(Config) ->
%% generated by andalso/orelse.
less = t_case_a(1, 2),
not_less = t_case_a(2, 2),
{'EXIT',{{case_clause,false},_}} = (catch t_case_b({x,y,z}, 2)),
{'EXIT',{{case_clause,true},_}} = (catch t_case_b(a, a)),
?assertError({case_clause,false}, t_case_b({x,y,z}, 2)),
?assertError({case_clause,true}, t_case_b(a, a)),
eq = t_case_c(a, a),
ne = t_case_c(42, []),
t = t_case_d(x, x, true),
f = t_case_d(x, x, false),
f = t_case_d(x, y, true),
{'EXIT',{badarg,_}} = (catch t_case_d(x, y, blurf)),
true = (catch t_case_e({a,b}, {a,b})),
false = (catch t_case_e({a,b}, 42)),
?assertError(badarg, t_case_d(x, y, blurf)),
true = t_case_e({a,b}, {a,b}),
false = t_case_e({a,b}, 42),

{true,false} = t_case_f1(true, pos),
{false,true} = t_case_f1(true, whatever),
Expand Down Expand Up @@ -208,11 +209,11 @@ t_and_or(Config) when is_list(Config) ->
Tuple = id({a,b}),
case Tuple of
{_,_} ->
{'EXIT',{badarg,_}} = (catch true and Tuple)
?assertError(badarg, true and Tuple)
end,

%% Cover code in beam_ssa_codegen when type optimizations are disabled.
{'EXIT',{badarg,_}} = catch bad_and(true),
?assertError(badarg, bad_and(true)),

ok.

Expand Down Expand Up @@ -242,8 +243,8 @@ t_andalso(Config) when is_list(Config) ->
false = not id(true) andalso not id(false),
false = not id(true) andalso not id(true),

{'EXIT',{badarg,_}} = (catch not id(glurf) andalso id(true)),
{'EXIT',{badarg,_}} = (catch not id(false) andalso not id(glurf)),
?assertError(badarg, not id(glurf) andalso id(true)),
?assertError(badarg, not id(false) andalso not id(glurf)),
false = id(false) andalso not id(glurf),
false = false andalso not id(glurf),

Expand Down Expand Up @@ -281,8 +282,8 @@ t_orelse(Config) when is_list(Config) ->
true = not id(true) orelse not id(false),
false = not id(true) orelse not id(true),

{'EXIT',{badarg,_}} = (catch not id(glurf) orelse id(true)),
{'EXIT',{badarg,_}} = (catch not id(true) orelse not id(glurf)),
?assertError(badarg, not id(glurf) orelse id(true)),
?assertError(badarg, not id(true) orelse not id(glurf)),
true = id(true) orelse not id(glurf),
true = true orelse not id(glurf),

Expand Down Expand Up @@ -461,10 +462,10 @@ in_case(Config) when is_list(Config) ->
edge_rings = in_case_1(1, 1, 1, 1, 1),
not_loop = in_case_1(0.5, 1, 1, 1, 1),
loop = in_case_1(0.5, 0.9, 1.1, 1, 4),
{'EXIT',{badarith,_}} = (catch in_case_1(1, 1, 1, 1, 0)),
{'EXIT',{badarith,_}} = (catch in_case_1(1, 1, 1, 1, nan)),
{'EXIT',{badarg,_}} = (catch in_case_1(1, 1, 1, blurf, 1)),
{'EXIT',{badarith,_}} = (catch in_case_1([nan], 1, 1, 1, 1)),
?assertError(badarith, in_case_1(1, 1, 1, 1, 0)),
?assertError(badarith, in_case_1(1, 1, 1, 1, nan)),
?assertError(badarg, in_case_1(1, 1, 1, blurf, 1)),
?assertError(badarith, in_case_1([nan], 1, 1, 1, 1)),
ok.

in_case_1(LenUp, LenDw, LenN, Rotation, Count) ->
Expand Down Expand Up @@ -502,8 +503,8 @@ in_case_1_guard(LenUp, LenDw, LenN, Rotation, Count) ->
slow_compilation(_) ->
ok = slow_compilation_1({a}, #state{}),

{'EXIT', {function_clause,_}} = catch slow_compilation_2(#{}),
{'EXIT', {function_clause,_}} = catch slow_compilation_2(true),
?assertError(function_clause, slow_compilation_2(#{})),
?assertError(function_clause, slow_compilation_2(true)),

true = #conf{} =:= slow_compilation_3(#conf{}, #conf{}),
#conf{e1=a, e2=[], e3=[], e4=[], e5=[], e6=[]} =
Expand Down
9 changes: 5 additions & 4 deletions lib/compiler/test/apply_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
-export([foo/0,bar/1,baz/2,get_callback/0]).

-include_lib("common_test/include/ct.hrl").
-include_lib("stdlib/include/assert.hrl").

suite() -> [{ct_hooks,[ts_install_cth]}].

Expand Down Expand Up @@ -78,10 +79,10 @@ mfa(Config) when is_list(Config) ->
{[a,b]} = ?APPLY1(Mod, (id(bar)), [a,b]),
{39,{a}} = ?APPLY2(Mod, (id(baz)), 39, {a}),

{'EXIT',_} = (catch ?APPLY2(Mod, (id(bazzzzzz)), a, b)),
{'EXIT',_} = (catch ?APPLY2({}, baz, a, b)),
{'EXIT',_} = (catch ?APPLY2(?MODULE, [], a, b)),
{'EXIT',_} = (catch bad_literal_call(1)),
?assertError(_, ?APPLY2(Mod, (id(bazzzzzz)), a, b)),
?assertError(_, ?APPLY2({}, baz, a, b)),
?assertError(_, ?APPLY2(?MODULE, [], a, b)),
?assertError(_, bad_literal_call(1)),

ok = apply(Mod, foo, id([])),
{[a,b|c]} = apply(Mod, bar, id([[a,b|c]])),
Expand Down
9 changes: 5 additions & 4 deletions lib/compiler/test/beam_block_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
%% %CopyrightEnd%
%%
-module(beam_block_SUITE).
-include_lib("stdlib/include/assert.hrl").

-export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1,
init_per_group/2,end_per_group/2,
Expand Down Expand Up @@ -208,8 +209,8 @@ repro([{Temp, Slot}|Xs], TempNames, Slots0) ->

encode_wildcards3([],[],_,_) -> [];
encode_wildcards3([Level|Levels],[BitsInLevel|BitsRest],LevelNo,TotSize) ->
case (catch ?MODULE:encode_wildcard(Level,BitsInLevel,TotSize-BitsInLevel,
length(Levels))) of
case catch ?MODULE:encode_wildcard(Level,BitsInLevel,TotSize-BitsInLevel,
length(Levels)) of
{'EXIT',{Reason,Info}} ->
exit({Reason,{LevelNo,Info}});

Expand Down Expand Up @@ -317,11 +318,11 @@ coverage(Config) ->
{b,a,badarith} = coverage_3(a, b),
ok = coverage_3(0, 1),

{'EXIT',{badarg,_}} = catch coverage_4(a, b),
?assertError(badarg, coverage_4(a, b)),

~"true" = coverage_5(id(latin1), id(true)),
~"true" = coverage_5(id(utf8), id(false)),
{'EXIT',{badarg,_}} = catch coverage_5(id(42), id(42)),
?assertError(badarg, coverage_5(id(42), id(42))),

ok.

Expand Down
14 changes: 8 additions & 6 deletions lib/compiler/test/beam_bounds_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
%%

-module(beam_bounds_SUITE).
-include_lib("stdlib/include/assert.hrl").

-export([all/0, suite/0, groups/0, init_per_suite/1, end_per_suite/1,
init_per_group/2, end_per_group/2,
addition_bounds/1, subtraction_bounds/1,
Expand Down Expand Up @@ -129,7 +131,7 @@ division_bounds(_Config) ->
{2,'+inf'} = beam_bounds:bounds('div', {10,'+inf'}, {2,4}),

any = beam_bounds:bounds('div', {10,'+inf'}, {0,0}),
{'EXIT', {badarith, _}} = catch division_bounds_1([], ok),
?assertError(badarith, division_bounds_1([], ok)),

{-10,10} = beam_bounds:bounds('div', {0,10}, any),
{-50,50} = beam_bounds:bounds('div', {-50,-15}, {-10,'+inf'}),
Expand Down Expand Up @@ -236,13 +238,13 @@ bnot_bounds(_Config) ->

-1 = bnot_bounds_2(0),
-43 = bnot_bounds_2_coverage(id(42)),
{'EXIT',{badarith,_}} = catch bnot_bounds_2_coverage(id(bad)),
?assertError(badarith, bnot_bounds_2_coverage(id(bad))),

{'EXIT',{_,_}} = catch bnot_bounds_3(id(true)),
{'EXIT',{_,_}} = catch bnot_bounds_3(id(false)),
{'EXIT',{_,_}} = catch bnot_bounds_3(id(0)),
?assertError(_, bnot_bounds_3(id(true))),
?assertError(_, bnot_bounds_3(id(false))),
?assertError(_, bnot_bounds_3(id(0))),

{'EXIT',{{bad_generator,-3},_}} = catch bnot_bounds_4(),
?assertError({bad_generator,-3}, bnot_bounds_4()),

ok.

Expand Down
4 changes: 2 additions & 2 deletions lib/compiler/test/beam_debug_info_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -704,10 +704,10 @@ slim_option(_Config) ->

fixed_bugs(_Config) ->
ok = unassigned_yreg(ok),
{'EXIT',_} = catch unassigned_yreg(not_ok),
?assertError(_, unassigned_yreg(not_ok)),

~"xyz" = wrong_frame_size(id(~"xyz")),
boom = catch wrong_frame_size(id(42)),
?assertThrow(boom, wrong_frame_size(id(42))),

{ok,error} = no_function(ok),

Expand Down
101 changes: 57 additions & 44 deletions lib/compiler/test/beam_except_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
%% %CopyrightEnd%
%%
-module(beam_except_SUITE).
-include_lib("stdlib/include/assert.hrl").
-include("test_lib.hrl").

-export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1,
init_per_group/2,end_per_group/2,
Expand Down Expand Up @@ -53,10 +55,9 @@ end_per_group(_GroupName, Config) ->
Config.

multiple_allocs(_Config) ->
{'EXIT',{{badmatch,#{true:=[p]}},_}} =
(catch could(pda, 0.0, {false,true}, {p})),
{'EXIT',{{bad_generator,0},_}} = (catch place(lee)),
{'EXIT',{{badmatch,wanted},_}} = (catch conditions()),
?assertError({badmatch,#{true:=[p]}}, could(pda, 0.0, {false,true}, {p})),
?assertError({bad_generator,0}, place(lee)),
?assertError({badmatch,wanted}, conditions()),

ok.

Expand All @@ -71,17 +72,16 @@ conditions() ->

bs_get_tail(Config) ->
{<<"abc">>,0,0,Config} = bs_get_tail_1(id(<<0:32, "abc">>), 0, 0, Config),
{'EXIT',
{function_clause,
[{?MODULE,bs_get_tail_1,[<<>>,0,0,Config],_}|_]}} =
(catch bs_get_tail_1(id(<<>>), 0, 0, Config)),
?AssertErrorStack(function_clause,
[{?MODULE,bs_get_tail_1,[<<>>,0,0,Config],_}|_],
bs_get_tail_1(id(<<>>), 0, 0, Config)),

ok = bs_get_tail_2(<<"W">>, <<"X">>, <<"Z">>),
ok = bs_get_tail_2(<<"M">>, <<"X">>, <<"Z">>),
{'EXIT',
{function_clause,
[{?MODULE,do_get_bs_tail_2,[<<"A">>,<<"B">>,[],<<"C">>],_}|_]}} =
(catch bs_get_tail_2(<<"A">>, <<"B">>, <<"C">>)),
?AssertErrorStack(function_clause,
[{?MODULE,do_get_bs_tail_2,
[<<"A">>,<<"B">>,[],<<"C">>],_}|_],
bs_get_tail_2(<<"A">>, <<"B">>, <<"C">>)),

ok.

Expand All @@ -97,61 +97,74 @@ do_get_bs_tail_2(<<"M">>, <<"X">>, _, <<"Z">>) -> ok.
coverage(_) ->
File = {file,"fake.erl"},
ok = fc(a),
{'EXIT',{function_clause,
[{?MODULE,fc,[[x]],[File,{line,2}]}|_]}} =
(catch fc([x])),
{'EXIT',{function_clause,
[{?MODULE,fc,[y],[File,{line,2}]}|_]}} =
(catch fc(y)),
?AssertErrorStack(function_clause,
[{?MODULE,fc,[[x]],[File,{line,2}]}|_],
fc([x])),
?AssertErrorStack(function_clause,
[{?MODULE,fc,[y],[File,{line,2}]}|_],
fc(y)),
case ?MODULE of
beam_except_no_opt_SUITE ->
%% There will be a different stack fram in
%% unoptimized code.
ok;
_ ->
{'EXIT',{function_clause,
[{?MODULE,fc,[[a,b,c]],[File,{line,6}]}|_]}} =
(catch fc([a,b,c]))
?AssertErrorStack(function_clause,
[{?MODULE,fc,[[a,b,c]],[File,{line,6}]}|_],
fc([a,b,c]))
end,

{'EXIT',{undef,[{erlang,error,[a,b,c,d],_}|_]}} =
(catch erlang:error(a, b, c, d)),
?AssertErrorStack(undef,
[{erlang,error,[a,b,c,d],_}|_],
erlang:error(a, b, c, d)),

%% The stacktrace for operators such a '+' can vary depending on
%% whether the JIT is used or not.
case catch bar(x) of
{'EXIT',{badarith,[{erlang,'+',[x,1],[_|_]},
{?MODULE,bar,1,[File,{line,9}]}|_]}} ->
try bar(x) of
Success ->
error({unexpected_success,Success})
catch
error:badarith:Stack ->
[{erlang,'+',[x,1],[_|_]},
{?MODULE,bar,1,[File,{line,9}]}|_] = Stack,
ok;
{'EXIT',{badarith,[{?MODULE,bar,1,[File,{line,9}]}|_]}} ->
error:badarith:Stack ->
[{?MODULE,bar,1,[File,{line,9}]}|_] = Stack,
ok
end,

{'EXIT',{{case_clause,{1}},[{?MODULE,bar,1,[File,{line,9}]}|_]}} =
(catch bar(0)),
?AssertErrorStack({case_clause,{1}},

[{?MODULE,bar,1,[File,{line,9}]}|_],
bar(0)),

Self = self(),
{'EXIT',{{strange,Self},[{?MODULE,foo,[any],[File,{line,14}]}|_]}} =
(catch foo(any)),
?AssertErrorStack({strange,Self},
[{?MODULE,foo,[any],[File,{line,14}]}|_],
foo(any)),

{ok,succeed,1,2} = foobar(succeed, 1, 2),
{'EXIT',{function_clause,[{?MODULE,foobar,[[fail],1,2],
[{file,"fake.erl"},{line,16}]}|_]}} =
(catch foobar([fail], 1, 2)),
?AssertErrorStack(function_clause,
[{?MODULE,foobar,[[fail],1,2],
[{file,"fake.erl"},{line,16}]}|_],
foobar([fail], 1, 2)),

{'EXIT',{function_clause,[{?MODULE,fake_function_clause1,[{a,b},42.0],_}|_]}} =
(catch fake_function_clause1({a,b})),
?AssertErrorStack(function_clause,
[{?MODULE,fake_function_clause1,[{a,b},42.0],_}|_],
fake_function_clause1({a,b})),

{'EXIT',{function_clause,[{?MODULE,fake_function_clause2,[42|bad_tl],_}|_]}} =
(catch fake_function_clause2(42, bad_tl)),
?AssertErrorStack(function_clause,
[{?MODULE,fake_function_clause2,[42|bad_tl],_}|_],
fake_function_clause2(42, bad_tl)),

{'EXIT',{function_clause,[{?MODULE,fake_function_clause3,[x,y],_}|_]}} =
(catch fake_function_clause3(42, id([x,y]))),
?AssertErrorStack(function_clause,
[{?MODULE,fake_function_clause3,[x,y],_}|_],
fake_function_clause3(42, id([x,y]))),

{'EXIT',{{function_clause,a,b,c}, _}} = catch fake_function_clause4(),
?assertError({function_clause,a,b,c}, fake_function_clause4()),

{'EXIT',{{badmatch,0.0},_}} = (catch coverage_1(id(42))),
{'EXIT',{badarith,_}} = (catch coverage_1(id(a))),
?assertError({badmatch,0.0}, coverage_1(id(42))),
?assertError(badarith, coverage_1(id(a))),

ok.

Expand Down Expand Up @@ -182,7 +195,7 @@ do_binary_construction_allocation(Req) ->

unfold_literals(_Config) ->
a = do_unfold_literals(badarg, id({a,b})),
{'EXIT',{badarg,_}} = catch do_unfold_literals(badarg, id(a)),
?assertError(badarg, do_unfold_literals(badarg, id(a))),

ok.

Expand Down
Loading
Loading