diff --git a/lib/compiler/test/Makefile b/lib/compiler/test/Makefile index c9d3851667d..b17836590b1 100644 --- a/lib/compiler/test/Makefile +++ b/lib/compiler/test/Makefile @@ -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) @@ -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`; \ diff --git a/lib/compiler/test/andor_SUITE.erl b/lib/compiler/test/andor_SUITE.erl index 147fe07c210..f31d4872feb 100644 --- a/lib/compiler/test/andor_SUITE.erl +++ b/lib/compiler/test/andor_SUITE.erl @@ -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]}]. @@ -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), @@ -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. @@ -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), @@ -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), @@ -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) -> @@ -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=[]} = diff --git a/lib/compiler/test/apply_SUITE.erl b/lib/compiler/test/apply_SUITE.erl index 120ccfec8ef..2a5e45601db 100644 --- a/lib/compiler/test/apply_SUITE.erl +++ b/lib/compiler/test/apply_SUITE.erl @@ -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]}]. @@ -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]])), diff --git a/lib/compiler/test/beam_block_SUITE.erl b/lib/compiler/test/beam_block_SUITE.erl index 12757db5985..04bde6afb59 100644 --- a/lib/compiler/test/beam_block_SUITE.erl +++ b/lib/compiler/test/beam_block_SUITE.erl @@ -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, @@ -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}}); @@ -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. diff --git a/lib/compiler/test/beam_bounds_SUITE.erl b/lib/compiler/test/beam_bounds_SUITE.erl index 803c0708f5d..b1610f893e5 100644 --- a/lib/compiler/test/beam_bounds_SUITE.erl +++ b/lib/compiler/test/beam_bounds_SUITE.erl @@ -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, @@ -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'}), @@ -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. diff --git a/lib/compiler/test/beam_debug_info_SUITE.erl b/lib/compiler/test/beam_debug_info_SUITE.erl index d6ca43e641e..adf62749eb4 100644 --- a/lib/compiler/test/beam_debug_info_SUITE.erl +++ b/lib/compiler/test/beam_debug_info_SUITE.erl @@ -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), diff --git a/lib/compiler/test/beam_except_SUITE.erl b/lib/compiler/test/beam_except_SUITE.erl index 0a36aca86d3..563131fabc7 100644 --- a/lib/compiler/test/beam_except_SUITE.erl +++ b/lib/compiler/test/beam_except_SUITE.erl @@ -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, @@ -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. @@ -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. @@ -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. @@ -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. diff --git a/lib/compiler/test/beam_jump_SUITE.erl b/lib/compiler/test/beam_jump_SUITE.erl index 8b8cf01c3cc..670cc3802d0 100644 --- a/lib/compiler/test/beam_jump_SUITE.erl +++ b/lib/compiler/test/beam_jump_SUITE.erl @@ -20,6 +20,7 @@ %% %CopyrightEnd% %% -module(beam_jump_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, @@ -58,7 +59,7 @@ end_per_group(_GroupName, Config) -> Config. undefined_label(_Config) -> - {'EXIT',{function_clause,_}} = (catch flights(0, [], [])), + ?assertError(function_clause, flights(0, [], [])), ok. %% Would lose a label when compiled with no_copt. @@ -75,15 +76,15 @@ ambiguous_catch_try_state(Config) -> {{'EXIT',{{case_clause,song},_}},{'EXIT',{{case_clause,song},_}}} = checks(42), - {'EXIT',{{try_clause,42},_}} = (catch unsafe_sharing()), + ?assertError({try_clause,42}, unsafe_sharing()), - {'EXIT',{{badmatch,b},_}} = (catch ambiguous_catch_try_state_1(<<>>)), - {'EXIT',{{badmatch,b},_}} = (catch ambiguous_catch_try_state_1(Config)), + ?assertError({badmatch,b}, ambiguous_catch_try_state_1(<<>>)), + ?assertError({badmatch,b}, ambiguous_catch_try_state_1(Config)), - {'EXIT',{{badmatch,0},_}} = (catch ambiguous_catch_try_state_2()), - {'EXIT',{{badmatch,0},_}} = (catch ambiguous_catch_try_state_3()), + ?assertError({badmatch,0}, ambiguous_catch_try_state_2()), + ?assertError({badmatch,0}, ambiguous_catch_try_state_3()), - {'EXIT',{badarg,_}} = catch ambiguous_catch_try_state_4(), + ?assertError(badarg, ambiguous_catch_try_state_4()), ok. @@ -243,7 +244,7 @@ ambiguous_catch_try_state_4() -> build_tuple(_Config) -> Message2 = #message2{}, - {'EXIT',{{badrecord,Message2},_}} = (catch do_build_tuple(#message2{})), + ?assertError({badrecord,Message2}, do_build_tuple(#message2{})), ok. do_build_tuple(Message) -> @@ -327,8 +328,8 @@ call_sharing(_Config) -> C_2 = {c, 1}, C_3 = {c, 1, 2}, - {'EXIT',_} = (catch (cs_1(id(C_2)))), - {'EXIT',_} = (catch (cs_1(id(C_3)))), + ?assertError(_, (cs_1(id(C_2)))), + ?assertError(_, (cs_1(id(C_3)))), ok. @@ -342,18 +343,18 @@ cs_1(Key) -> cs_2(I) -> I. undecided_allocation(_Config) -> - ok = catch undecided_allocation_1(<<10:(3*7)>>), - {'EXIT',{{badrecord,<<0>>},_}} = catch undecided_allocation_1(8), + ok = undecided_allocation_1(<<10:(3*7)>>), + ?assertError({badrecord,<<0>>}, undecided_allocation_1(8)), {bar,1} = undecided_allocation_2(id(<<"bar">>)), {foo,2} = undecided_allocation_2(id(<<"foo">>)), - {'EXIT',_} = catch undecided_allocation_2(id(<<"foobar">>)), - {'EXIT',{{badmatch,error},_}} = catch undecided_allocation_2(id("foo,bar")), - {'EXIT',_} = catch undecided_allocation_2(id(foobar)), - {'EXIT',_} = catch undecided_allocation_2(id(make_ref())), + ?assertError(_, undecided_allocation_2(id(<<"foobar">>))), + ?assertError({badmatch,error}, undecided_allocation_2(id("foo,bar"))), + ?assertError(_, undecided_allocation_2(id(foobar))), + ?assertError(_, undecided_allocation_2(id(make_ref()))), ok = undecided_allocation_3(id(<<0>>), gurka), - {'EXIT', {badarith, _}} = catch undecided_allocation_3(id(<<>>), gurka), + ?assertError(badarith, undecided_allocation_3(id(<<>>), gurka)), ok. diff --git a/lib/compiler/test/beam_reorder_SUITE.erl b/lib/compiler/test/beam_reorder_SUITE.erl index 583e9ff3918..2ef945e97d6 100644 --- a/lib/compiler/test/beam_reorder_SUITE.erl +++ b/lib/compiler/test/beam_reorder_SUITE.erl @@ -20,6 +20,7 @@ %% %CopyrightEnd% %% -module(beam_reorder_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, @@ -69,7 +70,7 @@ alloc_b(_U1, _U2, R) -> Res. confused_beam_validator(_Config) -> - {'EXIT',{{badmap,{any}},_}} = (catch efficient({any})), + ?assertError({badmap,{any}}, efficient({any})), ok. efficient({Var}=God) -> diff --git a/lib/compiler/test/beam_ssa_SUITE.erl b/lib/compiler/test/beam_ssa_SUITE.erl index f5e33cb0103..dfd83a87e8a 100644 --- a/lib/compiler/test/beam_ssa_SUITE.erl +++ b/lib/compiler/test/beam_ssa_SUITE.erl @@ -20,6 +20,8 @@ %% %CopyrightEnd% %% -module(beam_ssa_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, @@ -74,13 +76,13 @@ calls(Config) -> Ret = fun_call(fun(42) -> ok end, Ret), Ret = apply_fun(fun(a, b) -> ok end, [a,b], Ret), Ret = apply_mfa(test_lib, id, [anything], Ret), - {'EXIT',{badarg,_}} = (catch call_error()), - {'EXIT',{badarg,_}} = (catch call_error(42)), + ?assertError(badarg, call_error()), + ?assertError(badarg, call_error(42)), 5 = start_it([erlang,length,1,2,3,4,5]), {_,ok} = cover_call(id(true)), {_,ok} = cover_call(id(false)), - {'EXIT',{{case_clause,ok},_}} = catch cover_call(id(ok)), + ?assertError({case_clause,ok}, cover_call(id(ok))), ok. @@ -462,7 +464,7 @@ recv_coverage_2() -> end. maps(_Config) -> - {'EXIT',{{badmatch,#{}},_}} = (catch maps_1(any)), + ?assertError({badmatch,#{}}, maps_1(any)), {jkl,nil,nil} = maps_2(#{abc => 0, jkl => 0}), {def,ghi,abc} = maps_2(#{abc => 0, def => 0}), @@ -473,7 +475,7 @@ maps(_Config) -> [] = maps_3(), - {'EXIT',{{badmap,true},_}} = catch maps_4(id(true), id(true)), + ?assertError({badmap,true}, maps_4(id(true), id(true))), error = maps_4(id(#{}), id(true)), error = maps_4(id(#{}), id(#{})), @@ -610,7 +612,7 @@ cover_ssa_dead(_Config) -> 40.0 = percentage(4.0, 10.0), 60.0 = percentage(6, 10), - {'EXIT',{{badmatch,42},_}} = (catch #{key => abs(("a" = id(42)) /= teacher)}), + ?assertError({badmatch,42}, #{key => abs(("a" = id(42)) /= teacher)}), <<>> = id(<< V || V <- [], V andalso false >>), @@ -904,12 +906,13 @@ fast_mapfoldl(F, Acc0, [Hd|Tail]) -> fast_mapfoldl(F, Acc, []) when is_function(F, 2) -> {[],Acc}. grab_bag(_Config) -> - {'EXIT',_} = (catch grab_bag_1()), - {'EXIT',_} = (catch grab_bag_2()), - {'EXIT',_} = (catch grab_bag_3()), - {'EXIT',_} = (catch grab_bag_4()), - {'EXIT',{function_clause,[{?MODULE,grab_bag_5,[a,17],_}|_]}} = - (catch grab_bag_5(a, 17)), + ?assertError(_, grab_bag_1()), + ?assertError(_, grab_bag_2()), + ?assertError(_, grab_bag_3()), + ?assertError(_, grab_bag_4()), + ?AssertErrorStack(function_clause, + [{?MODULE,grab_bag_5,[a,17],_}|_], + grab_bag_5(a, 17)), way = grab_bag_6(face), no_match = grab_bag_6("ABC"), no_match = grab_bag_6(any), @@ -918,26 +921,26 @@ grab_bag(_Config) -> ok = grab_bag_9(), whatever = grab_bag_10(ignore, whatever), other = grab_bag_11(), - {'EXIT',_} = (catch grab_bag_12()), - {'EXIT',{{badmatch,[]},_}} = (catch grab_bag_13()), + ?assertError(_, grab_bag_12()), + ?assertError({badmatch,[]}, grab_bag_13()), timeout = grab_bag_14(), ?MODULE = grab_bag_15(?MODULE), error = grab_bag_16a(timeout_value), - {'EXIT',{timeout_value,_}} = (catch grab_bag_16a(whatever)), - {'EXIT',{timeout_value,_}} = (catch grab_bag_16b(whatever)), + ?assertError(timeout_value, grab_bag_16a(whatever)), + ?assertError(timeout_value, grab_bag_16b(whatever)), timeout_value = grab_bag_16b(error), fact = grab_bag_17(), - {'EXIT',{{try_clause,[]},[_|_]}} = catch grab_bag_18(), + ?assertError({try_clause,[]}, grab_bag_18()), - {'EXIT',{{badmatch,[whatever]},[_|_]}} = catch grab_bag_19(), + ?assertError({badmatch,[whatever]}, grab_bag_19()), - {'EXIT',{if_clause,[_|_]}} = catch grab_bag_20(), + ?assertError(if_clause, grab_bag_20()), 6 = grab_bag_21(id(64)), - {'EXIT',{badarith,_}} = catch grab_bag_21(id(a)), + ?assertError(badarith, grab_bag_21(id(a))), false = grab_bag_22(), @@ -1254,7 +1257,7 @@ grab_bag_23(#{page_title := unset} = State1) -> %% GH-8818: The CSE pass in beam_ssa_opt failed to intersect candidates on %% the failure path, crashing the type optimization pass. grab_bag_24() -> - {'EXIT', _} = catch do_grab_bag_24(id(0), id(0), id(0), id(0)), + ?assertError(_, do_grab_bag_24(id(0), id(0), id(0), id(0))), ok. do_grab_bag_24(A, B, C, D) -> @@ -1294,12 +1297,12 @@ coverage(_Config) -> <<$f:1.7>> -> ok; _ -> no_match end, - {'EXIT',{{badmatch,$T},_}} = (catch coverage_1()), + ?assertError({badmatch,$T}, coverage_1()), error = coverage_2(), ok = coverage_3(), #coverage{name=whatever} = coverage_4(), - {'EXIT',{{badrecord,ok},_}} = catch coverage_5(), + ?assertError({badrecord,ok}, coverage_5()), ok. @@ -1481,21 +1484,21 @@ gh_6599(_Config) -> ok = gh_6599_1(id(42), id(42)), #{ok := ok} = gh_6599_1(id(#{ok => 0}), id(#{ok => 0})), - {'EXIT',{{try_clause,#{ok:=ok}},_}} = - catch gh_6599_2(id(whatever), id(#{0 => whatever})), + ?assertError({try_clause,#{ok:=ok}}, + gh_6599_2(id(whatever), id(#{0 => whatever}))), ok = gh_6599_3(id(true), id(true)), - {'EXIT',{function_clause,_}} = catch gh_6599_3(id(false), id(false)), + ?assertError(function_clause, gh_6599_3(id(false), id(false))), 0.0 = gh_6599_3(id(0.0), id(0.0)), - {'EXIT',{{badmatch,true},_}} = catch gh_6599_4(id(false)), + ?assertError({badmatch,true}, gh_6599_4(id(false))), - {'EXIT',{{badmatch,ok},_}} = catch gh_6599_5(id([a]), id(#{0 => [a]}), id([a])), + ?assertError({badmatch,ok}, gh_6599_5(id([a]), id(#{0 => [a]}), id([a]))), #{ok := ok} = gh_6599_6(id(#{}), id(#{})), - {'EXIT',{{badmap,a},_}} = catch gh_6599_6(id(a), id(a)), + ?assertError({badmap,a}, gh_6599_6(id(a), id(a))), - {'EXIT',{{badarg,ok},_}} = catch gh_6599_7(id([a]), id([a])), + ?assertError({badarg,ok}, gh_6599_7(id([a]), id([a]))), ok. diff --git a/lib/compiler/test/beam_type_SUITE.erl b/lib/compiler/test/beam_type_SUITE.erl index 33437fc74de..13780241374 100644 --- a/lib/compiler/test/beam_type_SUITE.erl +++ b/lib/compiler/test/beam_type_SUITE.erl @@ -20,6 +20,7 @@ %% %CopyrightEnd% %% -module(beam_type_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, @@ -104,7 +105,7 @@ integers(_Config) -> b = do_integers_1(2#11001), a = do_integers_2(<<0:1>>), - {'EXIT',{{case_clause,-1},_}} = (catch do_integers_2(<<1:1>>)), + ?assertError({case_clause,-1}, do_integers_2(<<1:1>>)), college = do_integers_3(), @@ -117,27 +118,27 @@ integers(_Config) -> two = do_integers_5(0, 2), three = do_integers_5(0, 3), - {'EXIT',{badarith,_}} = (catch do_integers_6()), + ?assertError(badarith, do_integers_6()), house = do_integers_7(), - {'EXIT',{badarith,_}} = (catch do_integers_8()), + ?assertError(badarith, do_integers_8()), -693 = do_integers_9(id(7), id(1)), 3 = do_integers_10(1, 2), 10 = do_integers_10(-2, -5), - {'EXIT',{badarith,_}} = catch do_integers_11(42), - {'EXIT',{badarith,_}} = catch do_integers_11({a,b}), + ?assertError(badarith, do_integers_11(42)), + ?assertError(badarith, do_integers_11({a,b})), - {'EXIT',{system_limit,_}} = catch do_integers_12(42), - {'EXIT',{system_limit,_}} = catch do_integers_12([]), + ?assertError(system_limit, do_integers_12(42)), + ?assertError(system_limit, do_integers_12([])), - {'EXIT',{{badmatch,42},_}} = catch do_integers_13(-43), - {'EXIT',{{badmatch,0},_}} = catch do_integers_13(-1), - {'EXIT',{{badmatch,-1},_}} = catch do_integers_13(0), - {'EXIT',{{badmatch,-18},_}} = catch do_integers_13(17), + ?assertError({badmatch,42}, do_integers_13(-43)), + ?assertError({badmatch,0}, do_integers_13(-1)), + ?assertError({badmatch,-1}, do_integers_13(0)), + ?assertError({badmatch,-18}, do_integers_13(17)), ok. @@ -313,12 +314,12 @@ fcmp(F1, F2) when (F1 - F2) / F2 < 0.0000001 -> ok; fcmp(_, _) -> error. coverage(Config) -> - {'EXIT',{badarith,_}} = (catch id(1) bsl 0.5), - {'EXIT',{badarith,_}} = (catch id(2.0) bsl 2), - {'EXIT',{badarith,_}} = (catch a + 0.5), - {'EXIT',{badarith,_}} = (catch 2.0 * b), + ?assertError(badarith, id(1) bsl 0.5), + ?assertError(badarith, id(2.0) bsl 2), + ?assertError(badarith, a + 0.5), + ?assertError(badarith, 2.0 * b), - {'EXIT',{badarith,_}} = (catch id(42.0) / (1 bsl 2000)), + ?assertError(badarith, id(42.0) / (1 bsl 2000)), id(id(42) band 387439739874298734983787934283479243879), id(-1 band id(13)), @@ -348,16 +349,16 @@ coverage(Config) -> end, %% Cover beam_type:verified_type(none). - {'EXIT',{badarith,_}} = (catch (id(2) / id(1)) band 16#ff), + ?assertError(badarith, (id(2) / id(1)) band 16#ff), false = fun lot:life/147 == #{}, - {'EXIT',{badarith,_}} = catch coverage_1(), + ?assertError(badarith, coverage_1()), - {'EXIT',{badarith,_}} = catch coverage_2(), + ?assertError(badarith, coverage_2()), - {'EXIT',{function_clause,_}} = catch coverage_3("a"), - {'EXIT',{function_clause,_}} = catch coverage_3("b"), + ?assertError(function_clause, coverage_3("a")), + ?assertError(function_clause, coverage_3("b")), Number = id(1), if @@ -368,18 +369,18 @@ coverage(Config) -> 30 = coverage_4(2, Number) end, - {'EXIT',{badarg,_}} = catch false ++ true, - {'EXIT',{badarg,_}} = catch false -- true, + ?assertError(badarg, false ++ true), + ?assertError(badarg, false -- true), ok = coverage_5(id(0)), - {'EXIT',{function_clause,_}} = catch coverage_5(id(0.0)), + ?assertError(function_clause, coverage_5(id(0.0))), ok = coverage_5(id(16)), - {'EXIT',{{case_clause,false},_}} = catch coverage_5(id(-1)), + ?assertError({case_clause,false}, coverage_5(id(-1))), ok = coverage_6(id(0)), ok = catch coverage_6(id(0.0)), ok = coverage_6(id(16)), - {'EXIT',{{case_clause,false},_}} = catch coverage_6(id(-1)), + ?assertError({case_clause,false}, coverage_6(id(-1))), ok. @@ -421,7 +422,7 @@ coverage_6(A) -> booleans(_Config) -> - {'EXIT',{{case_clause,_},_}} = (catch do_booleans_1(42)), + ?assertError({case_clause,_}, do_booleans_1(42)), ok = do_booleans_2(42, 41), error = do_booleans_2(42, 42), @@ -451,17 +452,17 @@ booleans(_Config) -> end, false = is_boolean(NotBool), - {'EXIT',{{case_clause,false},_}} = catch do_booleans_4(42), - {'EXIT',{{case_clause,true},_}} = catch do_booleans_4(a), - {'EXIT',{{case_clause,true},_}} = catch do_booleans_4(false), - {'EXIT',{{badmatch,true},_}} = catch do_booleans_4(true), + ?assertError({case_clause,false}, do_booleans_4(42)), + ?assertError({case_clause,true}, do_booleans_4(a)), + ?assertError({case_clause,true}, do_booleans_4(false)), + ?assertError({badmatch,true}, do_booleans_4(true)), true = do_booleans_5(id(0), id(<<0>>), id(0)), - {'EXIT',{function_clause,_}} = catch do_booleans_6(id(0), id(0), id(0)), + ?assertError(function_clause, do_booleans_6(id(0), id(0), id(0))), - {'EXIT',{{bad_filter,_},_}} = catch do_booleans_7(id(0)), - {'EXIT',{function_clause,_}} = catch do_booleans_8(id(0)), - {'EXIT',{{try_clause,_},_}} = catch do_booleans_9(id(0)), + ?assertError({bad_filter,_}, do_booleans_7(id(0))), + ?assertError(function_clause, do_booleans_8(id(0))), + ?assertError({try_clause,_}, do_booleans_9(id(0))), ok. @@ -562,29 +563,29 @@ setelement(_Config) -> 0 -> 4; 1 -> 5 end, - {'EXIT',{badarg,_}} = catch setelement(Index1, {a,b,c}, y), + ?assertError(badarg, setelement(Index1, {a,b,c}, y)), %% Cover some edge cases in beam_call_types:will_succeed/3 and %% beam_call_types:types/3 {y} = setelement(1, tuple_or_integer(0), y), {y} = setelement(1, record_or_integer(0), y), - {'EXIT',{badarg,_}} = catch setelement(2, tuple_or_integer(id(0)), y), - {'EXIT',{badarg,_}} = catch setelement(2, tuple_or_integer(id(1)), y), - {'EXIT',{badarg,_}} = catch setelement(2, record_or_integer(id(0)), y), - {'EXIT',{badarg,_}} = catch setelement(2, record_or_integer(id(1)), y), - {'EXIT',{badarg,_}} = catch setelement(id(2), not_a_tuple, y), + ?assertError(badarg, setelement(2, tuple_or_integer(id(0)), y)), + ?assertError(badarg, setelement(2, tuple_or_integer(id(1)), y)), + ?assertError(badarg, setelement(2, record_or_integer(id(0)), y)), + ?assertError(badarg, setelement(2, record_or_integer(id(1)), y)), + ?assertError(badarg, setelement(id(2), not_a_tuple, y)), %% Cover some edge cases in beam_types:update_tuple/2 - {'EXIT',{badarg,_}} = catch setelement(2, not_a_tuple, y), - {'EXIT',{badarg,_}} = catch setelement(not_an_index, {a,b,c}, y), - {'EXIT',{badarg,_}} = catch setelement(8, {out_of_range}, y), + ?assertError(badarg, setelement(2, not_a_tuple, y)), + ?assertError(badarg, setelement(not_an_index, {a,b,c}, y)), + ?assertError(badarg, setelement(8, {out_of_range}, y)), {y,_,_} = update_tuple_1(#update_tuple_a{}, y), {y,_,_,_} = update_tuple_1(#update_tuple_b{}, y), #update_tuple_a{a=y} = update_tuple_2(#update_tuple_a{}, y), #update_tuple_b{a=y} = update_tuple_2(#update_tuple_b{}, y), - {'EXIT',{badarg,_}} = catch update_tuple_3(id(#update_tuple_a{}), y), - {'EXIT',{badarg,_}} = catch update_tuple_3(id(#update_tuple_b{}), y), - {'EXIT',{badarg,_}} = catch update_tuple_4(id(#update_tuple_a{}), y), + ?assertError(badarg, update_tuple_3(id(#update_tuple_a{}), y)), + ?assertError(badarg, update_tuple_3(id(#update_tuple_b{}), y)), + ?assertError(badarg, update_tuple_4(id(#update_tuple_a{}), y)), #update_tuple_b{c=y} = update_tuple_4(id(#update_tuple_b{}), y), ok. @@ -653,8 +654,8 @@ cons(_Config) -> {$a,"bc"} = cons_hdtl(true), {$d,"ef"} = cons_hdtl(false), - {'EXIT',{badarg,_}} = catch hd(ok), - {'EXIT',{badarg,_}} = catch tl(ok), + ?assertError(badarg, hd(ok)), + ?assertError(badarg, tl(ok)), ok. @@ -694,7 +695,7 @@ cons_hdtl(B) -> -record(bird, {a=a,b=id(42)}). tuple(_Config) -> - {'EXIT',{{badmatch,{necessary}},_}} = (catch do_tuple()), + ?assertError({badmatch,{necessary}}, do_tuple()), [] = [X || X <- [], #bird{a = a} == {r,X,foo}], [] = [X || X <- [], #bird{b = b} == {bird,X}], @@ -702,8 +703,8 @@ tuple(_Config) -> 1 = do_literal_tuple_1(1), 1 = do_literal_tuple_1(20), - {'EXIT', _} = catch do_literal_tuple_1(id(0)), - {'EXIT', _} = catch do_literal_tuple_1(id(bad)), + ?assertError(_, do_literal_tuple_1(id(0))), + ?assertError(_, do_literal_tuple_1(id(bad))), 2 = do_literal_tuple_2(1), 2 = do_literal_tuple_2(15), @@ -716,15 +717,15 @@ tuple(_Config) -> Counters10 = {id(0),id(0),id(0)}, %Exact size. {0,-1,0} = decrement_element(2, Counters10), {0,0,-1} = decrement_element(3, Counters10), - {'EXIT',{badarg,_}} = catch decrement_element(4, Counters10), + ?assertError(badarg, decrement_element(4, Counters10)), [] = gh_6458(id({true})), - {'EXIT',{function_clause,_}} = catch gh_6458(id({false})), - {'EXIT',{function_clause,_}} = catch gh_6458(id({42})), - {'EXIT',{function_clause,_}} = catch gh_6458(id(a)), + ?assertError(function_clause, gh_6458(id({false}))), + ?assertError(function_clause, gh_6458(id({42}))), + ?assertError(function_clause, gh_6458(id(a))), - {'EXIT',{badarg,_}} = catch gh_6927(id({a,b})), - {'EXIT',{badarg,_}} = catch gh_6927(id([])), + ?assertError(badarg, gh_6927(id({a,b}))), + ?assertError(badarg, gh_6927(id([]))), ok. @@ -771,9 +772,9 @@ gh_6927(X) -> record_float(_Config) -> 17.0 = record_float(#x{a={0}}, 1700), 23.0 = record_float(#x{a={0}}, 2300.0), - {'EXIT',{if_clause,_}} = (catch record_float(#x{a={1}}, 88)), - {'EXIT',{if_clause,_}} = (catch record_float(#x{a={}}, 88)), - {'EXIT',{if_clause,_}} = (catch record_float(#x{}, 88)), + ?assertError(if_clause, record_float(#x{a={1}}, 88)), + ?assertError(if_clause, record_float(#x{a={}}, 88)), + ?assertError(if_clause, record_float(#x{}, 88)), ok. record_float(R, N0) -> @@ -784,7 +785,7 @@ record_float(R, N0) -> binary_float(_Config) -> <<-1/float>> = binary_negate_float(<<1/float>>), - {'EXIT',{badarg,_}} = catch binary_float_1(id(64.0), id(0)), + ?assertError(badarg, binary_float_1(id(64.0), id(0))), ok. binary_negate_float(<>) -> @@ -821,7 +822,7 @@ float_overflow(_Config) -> Res2 = id((-1 bsl 1023) * two()), Res2 = float_overflow_2(), - {'EXIT',{{bad_filter,[0]},_}} = catch float_overflow_3(), + ?assertError({bad_filter,[0]}, float_overflow_3()), ok. @@ -956,19 +957,19 @@ do_test_size(Term) when is_binary(Term) -> cover_lists_functions(Config) -> foo = lists:foldl(id(fun(_, _) -> foo end), foo, Config), foo = lists:foldl(fun(_, _) -> foo end, foo, Config), - {'EXIT',_} = catch lists:foldl(not_a_fun, foo, Config), + ?assertError(_, lists:foldl(not_a_fun, foo, Config)), foo = lists:foldr(id(fun(_, _) -> foo end), foo, Config), foo = lists:foldr(fun(_, _) -> foo end, foo, Config), - {'EXIT',_} = catch lists:foldr(not_a_fun, foo, Config), + ?assertError(_, lists:foldr(not_a_fun, foo, Config)), {data_dir,_DataDir} = lists:keyfind(data_dir, id(1), Config), - {'EXIT',_} = catch lists:keyfind(data_dir, not_a_position, Config), - {'EXIT',_} = catch lists:keyfind(data_dir, 1, not_a_list), + ?assertError(_, lists:keyfind(data_dir, not_a_position, Config)), + ?assertError(_, lists:keyfind(data_dir, 1, not_a_list)), - {'EXIT',_} = catch lists:map(not_a_fun, Config), - {'EXIT',_} = catch lists:map(not_a_fun, []), - {'EXIT',_} = catch lists:map(fun id/1, not_a_list), + ?assertError(_, lists:map(not_a_fun, Config)), + ?assertError(_, lists:map(not_a_fun, [])), + ?assertError(_, lists:map(fun id/1, not_a_list)), Config = lists:map(id(fun id/1), Config), case lists:suffix([no|Config], Config) of @@ -979,7 +980,7 @@ cover_lists_functions(Config) -> end, [] = lists:zip([], []), - {'EXIT',_} = (catch lists:zip(not_list, [b])), + ?assertError(_, lists:zip(not_list, [b])), Zipper = fun(A, B) -> {A,B} end, @@ -995,17 +996,17 @@ cover_lists_functions(Config) -> Zipped), [{zip_zip,{zip,_}}|_] = DoubleZip, - {'EXIT',_} = (catch lists:zipwith(not_a_fun, [a], [b])), - {'EXIT',{bad,_}} = (catch lists:zipwith(fun(_A, _B) -> error(bad) end, + ?assertError(_, lists:zipwith(not_a_fun, [a], [b])), + ?assertError(bad, lists:zipwith(fun(_A, _B) -> error(bad) end, [a], [b])), - {'EXIT',_} = (catch lists:zipwith(fun(_A, _B) -> error(bad) end, + ?assertError(_, lists:zipwith(fun(_A, _B) -> error(bad) end, not_list, [b])), - {'EXIT',{bad,_}} = (catch lists:zipwith(fun(_A, _B) -> error(bad) end, + ?assertError(bad, lists:zipwith(fun(_A, _B) -> error(bad) end, lists:duplicate(length(Zipped), zip_zip), Zipped)), - {'EXIT',_} = catch lists:unzip(not_a_list), - {'EXIT',_} = catch lists:unzip([not_a_tuple]), + ?assertError(_, lists:unzip(not_a_list)), + ?assertError(_, lists:unzip([not_a_tuple])), {[_|_],[_|_]} = lists:unzip(Zipped), ok. @@ -1109,9 +1110,9 @@ type_subtraction(Config) when is_list(Config) -> ok = type_subtraction_2(id(true)), <<"aaaa">> = type_subtraction_2(id(false)), - {'EXIT', _} = catch type_subtraction_3(id(false)), + ?assertError(_, type_subtraction_3(id(false))), ok = catch type_subtraction_4(id(ok)), - {'EXIT', _} = catch type_subtraction_4(id(false)), + ?assertError(_, type_subtraction_4(id(false))), ok. @@ -1199,7 +1200,7 @@ is_list_opt(_Config) -> ok = is_list_opt_3(id([])), true = is_list_opt_3(id([a])), - {'EXIT',{badarg,_}} = catch is_list_opt_3(id(no_list)), + ?assertError(badarg, is_list_opt_3(id(no_list))), ok. @@ -1345,9 +1346,9 @@ sfi_send_return_value({412}) -> error. failures(_Config) -> - {'EXIT',{function_clause,_}} = catch failures_1(id(a), id(b), id(c)), - {'EXIT',{badarith,_}} = catch failures_1([], 2, 3), - {'EXIT',{badarith,_}} = catch failures_1([], x, y), + ?assertError(function_clause, failures_1(id(a), id(b), id(c))), + ?assertError(badarith, failures_1([], 2, 3)), + ?assertError(badarith, failures_1([], x, y)), ok. failures_1([] = V1, V2, V3) -> @@ -1361,61 +1362,61 @@ failures_1([] = V1, V2, V3) -> %% Covers various edge cases in beam_call_types:types/3 relating to maps cover_maps_functions(_Config) -> - {'EXIT',_} = catch maps:filter(fun(_, _) -> true end, not_a_map), - {'EXIT',_} = catch maps:filter(not_a_predicate, #{}), + ?assertError(_, maps:filter(fun(_, _) -> true end, not_a_map)), + ?assertError(_, maps:filter(not_a_predicate, #{})), error = maps:find(key_not_present, #{}), - {'EXIT',_} = catch maps:fold(fun(_, _, _) -> true end, init, not_a_map), - {'EXIT',_} = catch maps:fold(not_a_fun, init, #{}), + ?assertError(_, maps:fold(fun(_, _, _) -> true end, init, not_a_map)), + ?assertError(_, maps:fold(not_a_fun, init, #{})), #{} = maps:from_keys([], gurka), #{ hello := gurka } = maps:from_keys([hello], gurka), - {'EXIT',_} = catch maps:from_keys(not_a_list, gurka), + ?assertError(_, maps:from_keys(not_a_list, gurka)), #{} = catch maps:from_list([]), - {'EXIT',_} = catch maps:from_list([not_a_tuple]), + ?assertError(_, maps:from_list([not_a_tuple])), default = maps:get(key_not_present, #{}, default), - {'EXIT',_} = catch maps:get(key_not_present, #{}), + ?assertError(_, maps:get(key_not_present, #{})), [] = maps:keys(#{}), - {'EXIT',_} = catch maps:keys(not_a_map), + ?assertError(_, maps:keys(not_a_map)), #{ a := ok } = catch maps:map(fun(_, _) -> ok end, #{ a => a }), - {'EXIT',_} = catch maps:map(fun(_, _) -> error(crash) end, #{ a => a }), - {'EXIT',_} = catch maps:map(not_a_fun, #{}), - {'EXIT',_} = catch maps:map(fun(_, _) -> ok end, not_a_map), + ?assertError(_, maps:map(fun(_, _) -> error(crash) end, #{ a => a })), + ?assertError(_, maps:map(not_a_fun, #{})), + ?assertError(_, maps:map(fun(_, _) -> ok end, not_a_map)), - {'EXIT',_} = catch maps:merge(not_a_map, #{}), + ?assertError(_, maps:merge(not_a_map, #{})), #{} = maps:new(), - {'EXIT',_} = catch maps:put(key, value, not_a_map), + ?assertError(_, maps:put(key, value, not_a_map)), #{} = maps:remove(a, #{ a => a }), - {'EXIT',_} = catch maps:remove(gurka, not_a_map), + ?assertError(_, maps:remove(gurka, not_a_map)), error = maps:take(key_not_present, #{}), - {'EXIT',_} = catch maps:take(key, not_a_map), + ?assertError(_, maps:take(key, not_a_map)), - {'EXIT',_} = catch maps:to_list(not_a_map), + ?assertError(_, maps:to_list(not_a_map)), #{ a := ok } = maps:update_with(a, fun(_) -> ok end, #{ a => a }), - {'EXIT',_} = catch maps:update_with(a, fun(_) -> error(a) end, #{ a => a }), - {'EXIT',_} = catch maps:update_with(key_not_present, fun(_) -> ok end, #{}), - {'EXIT',_} = catch maps:update_with(key, not_a_fun, not_a_map), + ?assertError(_, maps:update_with(a, fun(_) -> error(a) end, #{ a => a })), + ?assertError(_, maps:update_with(key_not_present, fun(_) -> ok end, #{})), + ?assertError(_, maps:update_with(key, not_a_fun, not_a_map)), [] = maps:values(#{}), - {'EXIT',_} = catch maps:values(not_a_map), + ?assertError(_, maps:values(not_a_map)), #{} = maps:with([key_not_present], #{}), - {'EXIT',_} = catch maps:with(not_a_list, #{}), - {'EXIT',_} = catch maps:with([], not_a_map), - {'EXIT',_} = catch maps:with([foobar], not_a_map), + ?assertError(_, maps:with(not_a_list, #{})), + ?assertError(_, maps:with([], not_a_map)), + ?assertError(_, maps:with([foobar], not_a_map)), - {'EXIT',_} = catch maps:without(not_a_list, #{}), - {'EXIT',_} = catch maps:without([], not_a_map), + ?assertError(_, maps:without(not_a_list, #{})), + ?assertError(_, maps:without([], not_a_map)), ok. @@ -1445,10 +1446,10 @@ min_max_mixed_types(_Config) -> not_equal(_Config) -> true = do_not_equal(true), - {'EXIT',{function_clause,_}} = catch do_not_equal(false), - {'EXIT',{function_clause,_}} = catch do_not_equal(0), - {'EXIT',{function_clause,_}} = catch do_not_equal(42), - {'EXIT',{function_clause,_}} = catch do_not_equal(self()), + ?assertError(function_clause, do_not_equal(false)), + ?assertError(function_clause, do_not_equal(0)), + ?assertError(function_clause, do_not_equal(42)), + ?assertError(function_clause, do_not_equal(self())), ok. @@ -1457,9 +1458,9 @@ do_not_equal(V) when (V / V < (V orelse true)); V; V -> infer_relops(_Config) -> - {'EXIT',{badarith,_}} = catch infer_relops_1(), - {'EXIT',{badarith,_}} = catch infer_relops_2(), - {'EXIT',{badarith,_}} = catch infer_relops_3(id(0)), + ?assertError(badarith, infer_relops_1()), + ?assertError(badarith, infer_relops_2()), + ?assertError(badarith, infer_relops_3(id(0))), infer_relops_4(), ok. @@ -1533,10 +1534,10 @@ pm_concretization_3(_) -> ok. pm_concretization_4(_) -> ok. funs(_Config) -> - {'EXIT',{badarg,_}} = catch gh_7179(), + ?assertError(badarg, gh_7179()), false = is_function(id(fun() -> ok end), 1024), - {'EXIT',{badarg,_}} = catch gh_7197(), + ?assertError(badarg, gh_7197()), ok. @@ -1569,11 +1570,11 @@ will_succeed_1(_, _) -> float_confusion(_Config) -> ok = float_confusion_1(catch (true = ok), -0.0), ok = float_confusion_1(ok, 0.0), - {'EXIT', _} = catch float_confusion_2(), - {'EXIT', _} = catch float_confusion_3(id(0.0)), + ?assertError(_, float_confusion_2()), + ?assertError(_, float_confusion_3(id(0.0))), ok = float_confusion_4(id(1)), - {'EXIT', _} = catch float_confusion_5(), - {'EXIT', _} = catch float_confusion_6(), + ?assertError(_, float_confusion_5()), + ?assertError(_, float_confusion_6()), ok. float_confusion_1(_, _) -> diff --git a/lib/compiler/test/beam_utils_SUITE.erl b/lib/compiler/test/beam_utils_SUITE.erl index 223c8fd77f0..51df252f8c2 100644 --- a/lib/compiler/test/beam_utils_SUITE.erl +++ b/lib/compiler/test/beam_utils_SUITE.erl @@ -20,6 +20,7 @@ %% %CopyrightEnd% %% -module(beam_utils_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, @@ -90,12 +91,12 @@ do_apply_fun(X, Y) -> apply_mf(_Config) -> ok = do_apply_mf_used({a,b}, ?MODULE, id), error = do_apply_mf_used([a], ?MODULE, id), - {'EXIT',{{case_clause,{[],b}},_}} = (catch do_apply_mf_used({[],b}, ?MODULE, id)), + ?assertError({case_clause,{[],b}}, do_apply_mf_used({[],b}, ?MODULE, id)), error = do_apply_mf_killed({error,[a]}, ?MODULE, id), ok = do_apply_mf_killed([b], ?MODULE, id), - {'EXIT',{{case_clause,{a,[b]}},_}} = (catch do_apply_mf_killed({a,[b]}, ?MODULE, id)), - {'EXIT',{{case_clause,{error,[]}},_}} = (catch do_apply_mf_killed({error,[]}, ?MODULE, id)), + ?assertError({case_clause,{a,[b]}}, do_apply_mf_killed({a,[b]}, ?MODULE, id)), + ?assertError({case_clause,{error,[]}}, do_apply_mf_killed({error,[]}, ?MODULE, id)), ok. @@ -125,9 +126,9 @@ bs_init(_Config) -> <<>> = do_bs_init_2([]), <<0:32,((1 bsl 32)-1):32>> = do_bs_init_2([0,(1 bsl 32)-1]), - {'EXIT',{badarg,_}} = (catch do_bs_init_2([0.5])), - {'EXIT',{badarg,_}} = (catch do_bs_init_2([-1])), - {'EXIT',{badarg,_}} = (catch do_bs_init_2([1 bsl 32])), + ?assertError(badarg, do_bs_init_2([0.5])), + ?assertError(badarg, do_bs_init_2([-1])), + ?assertError(badarg, do_bs_init_2([1 bsl 32])), <<>> = do_bs_init_3({tag,0}, 0, 0), <<0>> = do_bs_init_3({tag,0}, 2, 1), @@ -141,10 +142,8 @@ bs_init(_Config) -> Domain = -8798798, [<<10,1:16,Id:16/signed>>,<<8,2:16,Domain:32/signed>>] = do_bs_init_5(#{tag=>value,id=>Id,domain=>Domain}), - {'EXIT',{{required,id},[_|_]}} = - (catch do_bs_init_5(#{tag=>value,id=>nil,domain=>Domain})), - {'EXIT',{{required,domain},[_|_]}} = - (catch do_bs_init_5(#{tag=>value,id=>Id,domain=>nil})), + ?assertError({required,id}, do_bs_init_5(#{tag=>value,id=>nil,domain=>Domain})), + ?assertError({required,domain}, do_bs_init_5(#{tag=>value,id=>Id,domain=>nil})), ok. @@ -322,7 +321,7 @@ do_y_catch_2(_) -> {a,b,c}. otp_8949_b(_Config) -> self() ! something, value = otp_8949_b([], false), - {'EXIT',_} = (catch otp_8949_b([], true)), + ?assertError(_, otp_8949_b([], true)), ok. %% Would cause an endless loop in beam_utils. @@ -374,13 +373,13 @@ liveopt_guard_bif({#alarmInfo{cause=F}=R, X}=A) -> coverage(_Config) -> 42+7 = merchant([[],7,false]), - {'EXIT',{{try_clause,0},_}} = (catch resulting([0], stone)), + ?assertError({try_clause,0}, resulting([0], stone)), 0.0 = resulting([true], stone), - {'EXIT',{if_clause,_}} = (catch clinic(false)), - {'EXIT',{{try_clause,"trials"},_}} = (catch clinic(true)), + ?assertError(if_clause, clinic(false)), + ?assertError({try_clause,"trials"}, clinic(true)), - {'EXIT',{function_clause,_}} = (catch town(overall, {{abc},alcohol})), + ?assertError(function_clause, town(overall, {{abc},alcohol})), self() ! junk_message, {"url",#{true:="url"}} = appointment(#{"resolution" => "url"}), @@ -416,10 +415,10 @@ clinic(Damage) -> carefully. y_registers(_Config) -> - {'EXIT',{{badfun,0},_}} = (catch economic(0.0, jim)), - {'EXIT',{{badmatch,apartments},_}} = (catch louisiana()), + ?assertError({badfun,0}, economic(0.0, jim)), + ?assertError({badmatch,apartments}, louisiana()), {a,b} = (boxes(true))({a,b}), - {'EXIT',{{case_clause,webmaster},_}} = (catch yellow(true)), + ?assertError({case_clause,webmaster}, yellow(true)), ok. economic(0.0 = Serves, Existence) -> @@ -577,7 +576,7 @@ is_used_fr(X, Y) -> unsafe_is_function(_Config) -> {undefined,any} = unsafe_is_function(undefined, any), {ok,any} = unsafe_is_function(fun() -> ok end, any), - {'EXIT',{{case_clause,_},_}} = (catch unsafe_is_function(fun(_) -> ok end, any)), + ?assertError({case_clause,_}, unsafe_is_function(fun(_) -> ok end, any)), ok. unsafe_is_function(F, M) -> diff --git a/lib/compiler/test/beam_validator_SUITE.erl b/lib/compiler/test/beam_validator_SUITE.erl index d9227d1998a..fce61f9e832 100644 --- a/lib/compiler/test/beam_validator_SUITE.erl +++ b/lib/compiler/test/beam_validator_SUITE.erl @@ -49,6 +49,7 @@ bif_inference/1,too_many_arguments/1,ensure_bits/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). init_per_testcase(Case, Config) when is_atom(Case), is_list(Config) -> Config. @@ -906,7 +907,7 @@ beam_val(M) -> val_dsetel(_Config) -> self() ! 13, - {'EXIT',{{try_clause,participating},_}} = (catch night(0)), + ?assertError({try_clause,participating}, night(0)), ok. night(Turned) -> @@ -1048,14 +1049,14 @@ infer_relops_false(_, _) -> ge. %% OTP-18365: A brainfart in inference for '=/=' inverted the results. not_equal_inference(_Config) -> - {'EXIT', {function_clause, _}} = (catch not_equal_inference_1(id([0]))), + ?assertError(function_clause, not_equal_inference_1(id([0]))), ok. not_equal_inference_1(X) when (X /= []) /= is_port(0 div 0) -> [X || _ <- []]. bad_bin_unit(_Config) -> - {'EXIT', {function_clause,_}} = catch bad_bin_unit_1(<<1:1>>), + ?assertError(function_clause, bad_bin_unit_1(<<1:1>>)), [] = bad_bin_unit_2(), ok. diff --git a/lib/compiler/test/bs_bincomp_SUITE.erl b/lib/compiler/test/bs_bincomp_SUITE.erl index 967ba0ba130..b974aa57623 100644 --- a/lib/compiler/test/bs_bincomp_SUITE.erl +++ b/lib/compiler/test/bs_bincomp_SUITE.erl @@ -23,6 +23,7 @@ %% -module(bs_bincomp_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, @@ -152,14 +153,14 @@ mixed(Config) when is_list(Config) -> <<4,5,6>> = cs_default(match_context_2(<<4,5,6>>)), <<255>> = over_complex_generator(), - {'EXIT',_} = catch float_segment_size(), + ?assertError(_, float_segment_size()), <<>> = inconsistent_types_1([]), - {'EXIT',{{bad_generator,42},_}} = catch inconsistent_types_1(42), + ?assertError({bad_generator,42}, inconsistent_types_1(42)), Self = self(), - {'EXIT',{{bad_generator,Self},_}} = catch inconsistent_types_1(Self), + ?assertError({bad_generator,Self}, inconsistent_types_1(Self)), - {'EXIT',{{bad_filter,<<>>},_}} = catch inconsistent_types_2(), + ?assertError({bad_filter,<<>>}, inconsistent_types_2()), %% Cover some code in beam_ssa_pre_codegen. [] = fun(A) -> @@ -374,7 +375,7 @@ nomatch(Config) when is_list(Config) -> <<>> = id(<< <> || C <- [], _ <- ok >>), <<>> = id(<<0 || _ <- [], _ <- ok, false>>), - {'EXIT',{{bad_generator,false},_}} = catch << [] || <<0:0>> <= false >>, + ?assertError({bad_generator,false}, << [] || <<0:0>> <= false >>), ok. @@ -503,13 +504,13 @@ sizes(Config) when is_list(Config) -> <<"Foundation"/utf8>> = Fun15(<<"Foundation"/utf32>>), <<"Основание"/utf8>> = Fun15(<<"Основание"/utf32>>), - {'EXIT',_} = (catch << <> || <> <= {1,2,3} >>), + ?assertError(_, << <> || <> <= {1,2,3} >>), cs_end(), ok. --define(BAD(E), {'EXIT',{badarg,_}} = (catch << (E) || _ <- [1,2,3] >>)). --define(BAD_V(E), {'EXIT',{badarg,_}} = (catch << (E) || I <- [1,2,3] >>)). +-define(BAD(E), ?assertError(badarg, << (E) || _ <- [1,2,3] >>)). +-define(BAD_V(E), ?assertError(badarg, << (E) || I <- [1,2,3] >>)). general_expressions(_) -> cs_init(), @@ -580,7 +581,7 @@ no_generator(_Config) -> {<<>>} = {<<(id(<<"abc">>)) || false >>}, %% Would crash the compiler when compiled with +no_type_opt. - {'EXIT',{badarg,_}} = (catch << (catch "\001") || true >>), + ?assertError(badarg, << (catch "\001") || true >>), ok. @@ -643,12 +644,12 @@ do_multiple_segments_2(Gen) -> List. grab_bag(_Config) -> - {'EXIT',{function_clause,_}} = catch grab_bag_gh_6553(<<>>), - {'EXIT',{function_clause,_}} = catch grab_bag_gh_6553(a), - {'EXIT',{{badmatch,<<>>},_}} = catch grab_bag_gh_6553(<<42>>), + ?assertError(function_clause, grab_bag_gh_6553(<<>>)), + ?assertError(function_clause, grab_bag_gh_6553(a)), + ?assertError({badmatch,<<>>}, grab_bag_gh_6553(<<42>>)), %% Cover a line v3_kernel:get_line/1. - _ = catch << ok || <<>> <= ok, ok >>, + ?assertError(_, << ok || <<>> <= ok, ok >>), [] = grab_bag_gh_8617(<<>>), [0] = grab_bag_gh_8617(<<1:1>>), @@ -679,13 +680,13 @@ strict_generators(_Config) -> <<12>> = << <<(X*Y)>> || X := Y <:- #{1 => 2, 3 => 4}, X > 1 >>, %% Non-matching elements cause a badmatch error for strict generators - {'EXIT',{{badmatch,2},_}} = (catch << <> || {ok, X} <:- [{ok,1},2,{ok,3}] >>), - {'EXIT',{{badmatch,<<128,2>>},_}} = (catch << <> || <<0:1, X:7>> <:= <<1,128,2>> >>), - {'EXIT',{{badmatch,{2,error}},_}} = (catch << <> || X := ok <:- #{1 => ok, 2 => error, 3 => ok} >>), + ?assertError({badmatch,2}, << <> || {ok, X} <:- [{ok,1},2,{ok,3}] >>), + ?assertError({badmatch,<<128,2>>}, << <> || <<0:1, X:7>> <:= <<1,128,2>> >>), + ?assertError({badmatch,{2,error}}, << <> || X := ok <:- #{1 => ok, 2 => error, 3 => ok} >>), %% Extra bits cannot be skipped at the end of the binary either - {'EXIT',{{badmatch,<<0:2>>},_}} = (catch [X || <> <:= <<0>>]), - {'EXIT',{{badmatch,<<9,2>>},_}} = (catch [Y || <> <:= <<8,1,9,2>>]), + ?assertError({badmatch,<<0:2>>}, [X || <> <:= <<0>>]), + ?assertError({badmatch,<<9,2>>}, [Y || <> <:= <<8,1,9,2>>]), ok. diff --git a/lib/compiler/test/bs_construct_SUITE.erl b/lib/compiler/test/bs_construct_SUITE.erl index 7afad7528d8..78d42450272 100644 --- a/lib/compiler/test/bs_construct_SUITE.erl +++ b/lib/compiler/test/bs_construct_SUITE.erl @@ -35,6 +35,7 @@ strings/1,bad_size/1,private_append/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -88,7 +89,7 @@ id(I) -> I. -define(T(B, L), {B, ??B, L}). -define(N(B), {B, ??B, unknown}). --define(FAIL(Expr), {'EXIT',{badarg,_}} = (catch Expr)). +-define(FAIL(Expr), ?assertError(badarg, Expr)). l(I_13, I_big1, I_16, Bin) -> [ @@ -205,12 +206,14 @@ evaluate(Str, Vars) -> eval_list([], _Vars) -> []; eval_list([{C_bin, Str, Bytes} | Rest], Vars) -> - case catch evaluate(Str, Vars) of - {'EXIT', Error} -> - io:format("Evaluation error: ~p, ~p, ~p~n", [Str, Vars, Error]), - exit(Error); + try evaluate(Str, Vars) of E_bin -> [{C_bin, E_bin, Str, Bytes} | eval_list(Rest, Vars)] + catch + error:Error:Stack -> + io:format("Evaluation error: ~p, ~p, ~p\n~p~n", + [Str, Vars, Error, Stack]), + erlang:raise(error, Error, Stack) end. one_test({C_bin, E_bin, Str, Bytes}) when is_list(Bytes) -> @@ -300,62 +303,62 @@ fail(Config) when is_list(Config) -> %% One negative field size, but the sum of field sizes will be 1 byte. %% Make sure that we reject that properly. - {'EXIT',{badarg,_}} = (catch <>), %% Same thing, but use literals. - {'EXIT',{badarg,_}} = (catch <>), %% Not numbers. - {'EXIT',{badarg,_}} = (catch <<45:(i(not_a_number))>>), - {'EXIT',{badarg,_}} = (catch <<13:8,45:(i(not_a_number))>>), + ?assertError(badarg, <<45:(i(not_a_number))>>), + ?assertError(badarg, <<13:8,45:(i(not_a_number))>>), %% Unaligned sizes. BadSz = i(7), Bitstr = i(<<42:17>>), - {'EXIT',{badarg,_}} = (catch <>), - {'EXIT',{badarg,_}} = (catch <>), + ?assertError(badarg, <>), + ?assertError(badarg, <>), [] = [X || {X} <- [], X == <>], [] = [X || {X} <- [], X == <>], %% Literals with incorrect type. - {'EXIT',{badarg,_}} = (catch <<42.0/integer>>), - {'EXIT',{badarg,_}} = (catch <<42/binary>>), - {'EXIT',{badarg,_}} = (catch <>), + ?assertError(badarg, <<42.0/integer>>), + ?assertError(badarg, <<42/binary>>), + ?assertError(badarg, <>), %% Bad literal sizes Bin = i(<<>>), - {'EXIT',{badarg,_}} = (catch <<0:(-1)>>), - {'EXIT',{badarg,_}} = (catch <>), - {'EXIT',{badarg,_}} = (catch <<0:(-(1 bsl 100))>>), - {'EXIT',{badarg,_}} = (catch <>), + ?assertError(badarg, <<0:(-1)>>), + ?assertError(badarg, <>), + ?assertError(badarg, <<0:(-(1 bsl 100))>>), + ?assertError(badarg, <>), %% Unaligned sizes with literal binaries. - {'EXIT',{badarg,_}} = (catch <<0,(<<7777:17>>)/binary>>), + ?assertError(badarg, <<0,(<<7777:17>>)/binary>>), %% Make sure that variables are bound even if binary %% construction fails. - {'EXIT',{badarg,_}} = (catch case <> of + ?assertError(badarg, case <> of _Any -> V0 end), - {'EXIT',{badarg,_}} = (catch case <> of + ?assertError(badarg, case <> of a when V1 -> office end), - {'EXIT',{badarg,_}} = (catch <<13:(put(?FUNCTION_NAME, 17))>>), + ?assertError(badarg, <<13:(put(?FUNCTION_NAME, 17))>>), 17 = erase(?FUNCTION_NAME), - {'EXIT',{badarg,_}} = (catch fail_1()), + ?assertError(badarg, fail_1()), %% Size exceeds length of binary. 'native' is redundant for %% binaries, but when it was present sys_core_fold would not %% detect the overlong binary and beam_ssa_opt would crash. - {'EXIT',{badarg,_}} = (catch << <<$t/little-signed>>:42/native-bytes >>), - {'EXIT',{badarg,_}} = (catch << <<$t/little-signed>>:42/bytes >>), + ?assertError(badarg, << <<$t/little-signed>>:42/native-bytes >>), + ?assertError(badarg, << <<$t/little-signed>>:42/bytes >>), - {'EXIT',{badarg,_}} = catch fail_2(true), + ?assertError(badarg, fail_2(true)), ok. @@ -402,7 +405,7 @@ in_guard(Config) when is_list(Config) -> ok = in_guard_4(<<15:4>>, 255), nope = in_guard_4(<<15:8>>, 255), - nope = catch in_guard_5(), + nope = in_guard_5(), ok. @@ -502,8 +505,16 @@ nasty_literals(Config) when is_list(Config) -> %% GH-6643: Excessively large literals could cause the compiler to run out %% of memory. - catch id(<<0:16777216/big-integer-unit:1>>), - catch id(<<0:(16777216*2)/big-integer-unit:1>>), + try + id(<<0:16777216/big-integer-unit:1>>) + catch + error:_ -> ok + end, + try + id(<<0:(16777216*2)/big-integer-unit:1>>) + catch + error:_ -> ok + end, ok. @@ -550,8 +561,8 @@ coerce_to_float(Config) when is_list(Config) -> ok. side_effect(Config) when is_list(Config) -> - {'EXIT',{badarg,_}} = (catch side_effect_1(a)), - {'EXIT',{badarg,_}} = (catch side_effect_1(<<>>)), + ?assertError(badarg, side_effect_1(a)), + ?assertError(badarg, side_effect_1(<<>>)), ok = side_effect_1(42), ok. @@ -575,15 +586,15 @@ opt(Config) when is_list(Config) -> <<1,2,3,4,5,19>> = id(<>), <<1,2,3,42>> = id(<>), - {'EXIT',_} = (catch <<<<23,56,0,2>>:(2.5)/binary>>), - {'EXIT',_} = (catch <<<<23,56,0,2>>:(-16)/binary>>), - {'EXIT',_} = (catch <<<<23,56,0,2>>:(anka)>>), - {'EXIT',_} = (catch <<<<23,56,0,2>>:64/float>>), - {'EXIT',_} = (catch <<<<23,56,0,2:7>>/binary>>), + ?assertError(_, <<<<23,56,0,2>>:(2.5)/binary>>), + ?assertError(_, <<<<23,56,0,2>>:(-16)/binary>>), + ?assertError(_, <<<<23,56,0,2>>:(anka)>>), + ?assertError(_, <<<<23,56,0,2>>:64/float>>), + ?assertError(_, <<<<23,56,0,2:7>>/binary>>), %% Test constant propagation - there should be a warning. BadSz = 2.5, - {'EXIT',_} = (catch <<<>:BadSz/binary>>), + ?assertError(_, <<<>:BadSz/binary>>), case id(false) of true -> opt_dont_call_me(); @@ -666,10 +677,10 @@ strings(Config) -> <> = Bin, %% Bad sizes for empty strings. - {'EXIT',{badarg,_}} = (catch <<"":(-42)>>), - {'EXIT',{badarg,_}} = (catch <<"":bad_size>>), - {'EXIT',{badarg,_}} = (catch bad_empty_string_1()), - {'EXIT',{badarg,_}} = (catch bad_empty_string_2()), + ?assertError(badarg, <<"":(-42)>>), + ?assertError(badarg, <<"":bad_size>>), + ?assertError(badarg, bad_empty_string_1()), + ?assertError(badarg, bad_empty_string_2()), error = bad_empty_string_3(), error = bad_empty_string_4(true), error = bad_empty_string_4(false), @@ -691,15 +702,15 @@ bad_empty_string_4(V) when <<"","eFN"/utf8-native>>, V -> ok; bad_empty_string_4(_) -> error. bad_size(_Config) -> - {'EXIT',{badarg,_}} = (catch bad_float_size()), - {'EXIT',{badarg,_}} = (catch bad_float_size(<<"abc">>)), - {'EXIT',{badarg,_}} = (catch bad_integer_size()), - {'EXIT',{badarg,_}} = (catch bad_integer_size(<<"xyz">>)), - {'EXIT',{badarg,_}} = (catch bad_integer_size2()), - {'EXIT',{badarg,_}} = (catch bad_binary_size()), - {'EXIT',{badarg,_}} = (catch bad_binary_size(<<"xyz">>)), - {'EXIT',{badarg,_}} = (catch bad_binary_size2()), - {'EXIT',{badarg,_}} = (catch bad_binary_size3(id(<<"abc">>))), + ?assertError(badarg, bad_float_size()), + ?assertError(badarg, bad_float_size(<<"abc">>)), + ?assertError(badarg, bad_integer_size()), + ?assertError(badarg, bad_integer_size(<<"xyz">>)), + ?assertError(badarg, bad_integer_size2()), + ?assertError(badarg, bad_binary_size()), + ?assertError(badarg, bad_binary_size(<<"xyz">>)), + ?assertError(badarg, bad_binary_size2()), + ?assertError(badarg, bad_binary_size3(id(<<"abc">>))), ok. bad_float_size() -> @@ -739,7 +750,7 @@ private_append(_Config) -> <<"beta">> => <<"beta">> }), <<>> = private_append_2(false), - {'EXIT', _} = catch private_append_2(true), + ?assertError(_, private_append_2(true)), {ok,<<>>} = private_append_3(id(<<>>)), {error,<<"wrong parity">>} = private_append_3(id(<<1>>)), diff --git a/lib/compiler/test/bs_match_SUITE.erl b/lib/compiler/test/bs_match_SUITE.erl index 4dcc7222e08..ae65e58a96d 100644 --- a/lib/compiler/test/bs_match_SUITE.erl +++ b/lib/compiler/test/bs_match_SUITE.erl @@ -66,6 +66,8 @@ -include_lib("stdlib/include/assert.hrl"). -include_lib("syntax_tools/include/merl.hrl"). +-define(FC1(Expr), do_fc(fun() -> Expr end)). +-define(FC3(Name, Args, Call), do_fc(Name, Args, fun() -> Call end)). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -136,8 +138,7 @@ size_shadow(Config) when is_list(Config) -> {7777,Any,42,whatever} = (size_shadow_6(Any, 13))(42, <<7777:13>>, whatever), {<<45>>,<<>>} = size_shadow_7({int,1}, <<1:16,45>>), - {'EXIT',{function_clause,_}} = - (catch size_shadow_7({int,42}, <<1:16,45>>)), + ?assertError(function_clause, size_shadow_7({int,42}, <<1:16,45>>)), ok. size_shadow_1() -> @@ -317,16 +318,16 @@ bin_tail(Config) when is_list(Config) -> $a = bin_tail_c(S, 0), $c = bin_tail_c(S, 2), $e = bin_tail_c(S, 4), - {'EXIT',_} = (catch bin_tail_c(S, 5)), - {'EXIT',_} = (catch bin_tail_c_var(S, 5)), + ?assertError(_, bin_tail_c(S, 5)), + ?assertError(_, bin_tail_c_var(S, 5)), $a = bin_tail_d(S, 0), $b = bin_tail_d(S, 8), $d = bin_tail_d(S, 3*8), - {'EXIT',_} = (catch bin_tail_d_dead(S, 1)), - {'EXIT',_} = (catch bin_tail_d_dead(S, 9)), - {'EXIT',_} = (catch bin_tail_d_dead(S, 5*8)), - {'EXIT',_} = (catch bin_tail_d_var(S, 1)), + ?assertError(_, bin_tail_d_dead(S, 1)), + ?assertError(_, bin_tail_d_dead(S, 9)), + ?assertError(_, bin_tail_d_dead(S, 5*8)), + ?assertError(_, bin_tail_d_var(S, 1)), ok = bin_tail_e(<<2:2,0:1,1:5>>), ok = bin_tail_e(<<2:2,1:1,1:5,42:64>>), @@ -336,7 +337,7 @@ bin_tail(Config) when is_list(Config) -> MD5 = erlang:md5(<<42>>), <<"abc">> = bin_tail_f(<>, MD5, 3), error = bin_tail_f(<>, MD5, 999), - {'EXIT',{_,_}} = (catch bin_tail_f(<<0:16/unit:8>>, MD5, 0)), + ?assertError(_, bin_tail_f(<<0:16/unit:8>>, MD5, 0)), ok. @@ -468,21 +469,23 @@ multiple_matches(<<_:8>>, <<_:16>>) -> d. bad_float_unpack_match(<>) -> F; bad_float_unpack_match(<>) -> I. - partitioned_bs_match(Config) when is_list(Config) -> <<1,2,3>> = partitioned_bs_match(blurf, <<42,1,2,3>>), error = partitioned_bs_match(10, <<7,8,15,13>>), error = partitioned_bs_match(100, {a,tuple,is,'not',a,binary}), ok = partitioned_bs_match(0, <<>>), - fc(partitioned_bs_match, [-1,blurf], - catch partitioned_bs_match(-1, blurf)), - fc(partitioned_bs_match, [-1,<<1,2,3>>], - catch partitioned_bs_match(-1, <<1,2,3>>)), + ?FC3(partitioned_bs_match, + [-1,blurf], + partitioned_bs_match(-1, blurf)), + ?FC3(partitioned_bs_match, + [-1,<<1,2,3>>], + partitioned_bs_match(-1, <<1,2,3>>)), {17,<<1,2,3>>} = partitioned_bs_match_2(1, <<17,1,2,3>>), {7,<<1,2,3>>} = partitioned_bs_match_2(7, <<17,1,2,3>>), - fc(partitioned_bs_match_2, [4,<<0:17>>], - catch partitioned_bs_match_2(4, <<0:17>>)), + ?FC3(partitioned_bs_match_2, + [4,<<0:17>>], + partitioned_bs_match_2(4, <<0:17>>)), anything = partitioned_bs_match_3(anything, <<42>>), ok = partitioned_bs_match_3(1, 2), @@ -506,18 +509,18 @@ partitioned_bs_match_3(1, 2) -> ok. function_clause(Config) when is_list(Config) -> ok = function_clause_1(<<0,7,0,7,42>>), - fc(function_clause_1, [<<0,1,2,3>>], - catch function_clause_1(<<0,1,2,3>>)), - fc(function_clause_1, [<<0,1,2,3>>], - catch function_clause_1(<<0,7,0,1,2,3>>)), + ?FC3(function_clause_1, [<<0,1,2,3>>], + function_clause_1(<<0,1,2,3>>)), + ?FC3(function_clause_1, [<<0,1,2,3>>], + function_clause_1(<<0,7,0,1,2,3>>)), ok = function_clause_2(<<0,7,0,7,42>>), ok = function_clause_2(<<255>>), ok = function_clause_2(<<13:4>>), - fc(function_clause_2, [<<0,1,2,3>>], - catch function_clause_2(<<0,1,2,3>>)), - fc(function_clause_2, [<<0,1,2,3>>], - catch function_clause_2(<<0,7,0,1,2,3>>)), + ?FC3(function_clause_2, [<<0,1,2,3>>], + function_clause_2(<<0,1,2,3>>)), + ?FC3(function_clause_2, [<<0,1,2,3>>], + function_clause_2(<<0,7,0,1,2,3>>)), ok. @@ -542,25 +545,25 @@ unit(Config) when is_list(Config) -> 99 = peek8(<<99>>), 100 = peek8(<<100,101>>), - fc(peek8, [<<100,101,0:1>>], catch peek8(<<100,101,0:1>>)), + ?FC3(peek8, [<<100,101,0:1>>], peek8(<<100,101,0:1>>)), 37484 = peek16(<<37484:16>>), 37489 = peek16(<<37489:16,5566:16>>), - fc(peek16, [<<8>>], catch peek16(<<8>>)), - fc(peek16, [<<42:15>>], catch peek16(<<42:15>>)), - fc(peek16, [<<1,2,3,4,5>>], catch peek16(<<1,2,3,4,5>>)), + ?FC3(peek16, [<<8>>], peek16(<<8>>)), + ?FC3(peek16, [<<42:15>>], peek16(<<42:15>>)), + ?FC3(peek16, [<<1,2,3,4,5>>], peek16(<<1,2,3,4,5>>)), 127 = peek7(<<127:7>>), 100 = peek7(<<100:7,19:7>>), - fc(peek7, [<<1,2>>], catch peek7(<<1,2>>)), + ?FC3(peek7, [<<1,2>>], peek7(<<1,2>>)), 1 = unit_opt(1, -1), 8 = unit_opt(8, -1), <<1:32,"abc">> = unit_opt_2(<<1:32,"abc">>), <<"def">> = unit_opt_2(<<2:32,"def">>), - {'EXIT',_} = (catch unit_opt_2(<<1:32,33:7>>)), - {'EXIT',_} = (catch unit_opt_2(<<2:32,55:7>>)), + ?assertError(_, unit_opt_2(<<1:32,33:7>>)), + ?assertError(_, unit_opt_2(<<2:32,55:7>>)), <<0:64>> = unit_opt_3(<<1:128>>), <<1:64>> = unit_opt_3(<<1:64>>), @@ -713,8 +716,8 @@ wfbm(Config) when is_list(Config) -> {ok,<<"2007/10/23/blurf">>} = get_tail(<<"200x/2007/10/23/blurf ">>), {skip,?DATELEN+5} = get_tail(<<"200x/2007/10/23/blurf.">>), nomatch = get_tail(<<"200y.2007.10.23.blurf ">>), - {'EXIT',_} = (catch get_tail({no,binary,at,all})), - {'EXIT',_} = (catch get_tail(no_binary)), + ?assertError(_, get_tail({no,binary,at,all})), + ?assertError(_, get_tail(no_binary)), ok. check_for_dot_or_space(Bin) -> @@ -782,13 +785,13 @@ bs_sum(Config) when is_list(Config) -> 6 = bs_sum_1([1,2,3|0]), 7 = bs_sum_1([1,2,3|one]), - fc(catch bs_sum_1({too,big,tuple})), - fc(catch bs_sum_1([1,2,3|{too,big,tuple}])), + ?FC1(bs_sum_1({too,big,tuple})), + ?FC1(bs_sum_1([1,2,3|{too,big,tuple}])), [] = sneaky_alias(<<>>), [559,387655] = sneaky_alias(id(<<559:32,387655:32>>)), - fc(sneaky_alias, [<<1>>], catch sneaky_alias(id(<<1>>))), - fc(sneaky_alias, [[1,2,3,4]], catch sneaky_alias(lists:seq(1, 4))), + ?FC3(sneaky_alias, [<<1>>], sneaky_alias(id(<<1>>))), + ?FC3(sneaky_alias, [[1,2,3,4]], sneaky_alias(lists:seq(1, 4))), ok. bs_sum_1(<>) -> H+bs_sum_1(T); @@ -806,9 +809,9 @@ sneaky_alias(<>) -> [From|sneaky_alias(L)]. coverage(Config) when is_list(Config) -> 0 = coverage_fold(fun(B, A) -> A+B end, 0, <<>>), 6 = coverage_fold(fun(B, A) -> A+B end, 0, <<1,2,3>>), - fc(catch coverage_fold(fun(B, A) -> - A+B - end, 0, [a,b,c])), + ?FC1(coverage_fold(fun(B, A) -> + A+B + end, 0, [a,b,c])), {<<42.0:64/float>>,float} = coverage_build(<<>>, <<42>>, float), {<<>>,not_a_tuple} = coverage_build(<<>>, <<>>, not_a_tuple), @@ -824,8 +827,8 @@ coverage(Config) when is_list(Config) -> do_coverage_bin_to_term_list([]), do_coverage_bin_to_term_list([lists:seq(0, 10),{a,b,c},<<23:42>>]), - fc(coverage_bin_to_term_list, [<<0,0,0,7>>], - catch do_coverage_bin_to_term_list_1(<<7:32>>)), + ?FC3(coverage_bin_to_term_list, [<<0,0,0,7>>], + do_coverage_bin_to_term_list_1(<<7:32>>)), <<>> = coverage_per_key(<<4:32>>), <<$a,$b,$c>> = coverage_per_key(<<7:32,"abc">>), @@ -856,10 +859,10 @@ coverage(Config) when is_list(Config) -> ok = coverage_beam_ssa_codegen(<<2>>), %% Cover code in beam_ssa_pre_codegen. - {'EXIT',{function_clause,_}} = catch coverage_beam_ssa_pre_codegen(<<>>), + ?assertError(function_clause, coverage_beam_ssa_pre_codegen(<<>>)), %% Cover code in beam_ssa_bsm. - {'EXIT',{{badarg,<<>>},_}} = catch coverage_beam_ssa_bsm_error(id(<<>>)), + ?assertError({badarg,<<>>}, coverage_beam_ssa_bsm_error(id(<<>>))), %% Cover code for merging registers in beam_validator. 42 = coverage_beam_validator(id(fun() -> 42 end)), @@ -1115,8 +1118,8 @@ matching_meets_construction(Config) when is_list(Config) -> <<_:Len/binary,Tail/binary>> = Tail0, Res = <>, <<3,4,5,"abc">> = Res, - {'EXIT',{badarg,_}} = (catch matching_meets_construction_1(<<"Abc">>)), - {'EXIT',{badarg,_}} = (catch matching_meets_construction_2(<<"Abc">>)), + ?assertError(badarg, matching_meets_construction_1(<<"Abc">>)), + ?assertError(badarg, matching_meets_construction_2(<<"Abc">>)), <<"Bbc">> = matching_meets_construction_3(<<"Abc">>), <<1,2>> = encode_octet_string(<<1,2,3>>, 2), @@ -1134,12 +1137,12 @@ encode_octet_string(<>, Len) -> simon(Config) when is_list(Config) -> one = simon(blurf, <<>>), two = simon(0, <<42>>), - fc(simon, [17,<<1>>], catch simon(17, <<1>>)), - fc(simon, [0,<<1,2,3>>], catch simon(0, <<1,2,3>>)), + ?FC3(simon, [17,<<1>>], simon(17, <<1>>)), + ?FC3(simon, [0,<<1,2,3>>], simon(0, <<1,2,3>>)), one = simon2(blurf, <<9>>), two = simon2(0, <<9,1>>), - fc(simon2, [0,<<9,10,11>>], catch simon2(0, <<9,10,11>>)), + ?FC3(simon2, [0,<<9,10,11>>], simon2(0, <<9,10,11>>)), ok. simon(_, <<>>) -> one; @@ -1152,9 +1155,9 @@ simon2(0, <<_:16>>) -> two. %% OTP-7113: Crash in v3_codegen. matching_and_andalso(Config) when is_list(Config) -> ok = matching_and_andalso_1(<<1,2,3>>, 3), - {'EXIT',{function_clause,_}} = (catch matching_and_andalso_1(<<1,2,3>>, -8)), - {'EXIT',{function_clause,_}} = (catch matching_and_andalso_1(<<1,2,3>>, blurf)), - {'EXIT',{function_clause,_}} = (catch matching_and_andalso_1(<<1,2,3>>, 19)), + ?assertError(function_clause, matching_and_andalso_1(<<1,2,3>>, -8)), + ?assertError(function_clause, matching_and_andalso_1(<<1,2,3>>, blurf)), + ?assertError(function_clause, matching_and_andalso_1(<<1,2,3>>, 19)), {"abc",<<"xyz">>} = matching_and_andalso_23("abc", <<"-xyz">>), {"abc",<<"">>} = matching_and_andalso_23("abc", <<($a-1)>>), @@ -1420,27 +1423,27 @@ bad_size(Config) when is_list(Config) -> Atom = an_atom, NaN = <<(-1):32>>, - {'EXIT',{{badmatch,<<>>},_}} = (catch <<32:Tuple>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<32:Binary>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<32:Atom>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<32:3.14>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<32:"ZJV">> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<32:(-1)>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<32:Tuple>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<32:Binary>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<32:Atom>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<32:3.14>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<32:"ZJV">> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<32:(-1)>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<42.0:Tuple/float>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<42.0:Binary/float>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<42.0:Atom/float>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<42.0:2.5/float>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<42.0:1/float>> = id(<<>>)), - {'EXIT',{{badmatch,NaN},_}} = (catch <<42.0:32/float>> = id(NaN)), + ?assertError({badmatch,<<>>}, <<42.0:Tuple/float>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<42.0:Binary/float>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<42.0:Atom/float>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<42.0:2.5/float>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<42.0:1/float>> = id(<<>>)), + ?assertError({badmatch,NaN}, <<42.0:32/float>> = id(NaN)), %% Matched out value is ignored. - {'EXIT',{{badmatch,<<>>},_}} = (catch <<_:Binary>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<_:Tuple>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<_:Atom>> = id(<<>>)), - {'EXIT',{{badmatch,<<>>},_}} = (catch <<_:2.5>> = id(<<>>)), - {'EXIT',{{badmatch,<<1:1>>},_}} = (catch <<_:1/float>> = id(<<1:1>>)), - {'EXIT',{{badmatch,NaN},_}} = (catch <<_:32/float>> = id(NaN)), + ?assertError({badmatch,<<>>}, <<_:Binary>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<_:Tuple>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<_:Atom>> = id(<<>>)), + ?assertError({badmatch,<<>>}, <<_:2.5>> = id(<<>>)), + ?assertError({badmatch,<<1:1>>}, <<_:1/float>> = id(<<1:1>>)), + ?assertError({badmatch,NaN}, <<_:32/float>> = id(NaN)), no_match = bad_all_size(<<>>), no_match = bad_all_size(<<1,2,3>>), @@ -1450,7 +1453,7 @@ bad_size(Config) when is_list(Config) -> [] = bad_size_2([a]), [] = bad_size_2([<<1,2,3>>]), - {'EXIT',{{bad_generator,no_list},_}} = catch bad_size_2(no_list), + ?assertError({bad_generator,no_list}, bad_size_2(no_list)), error = bad_size_3(<<>>), error = bad_size_3(<<0>>), @@ -1552,15 +1555,6 @@ haystack_2(Haystack) -> B end || {X,Y} <- Subs ]. -fc({'EXIT',{function_clause,_}}) -> ok; -fc({'EXIT',{{case_clause,_},_}}) when ?MODULE =:= bs_match_inline_SUITE -> ok. - -fc(Name, Args, {'EXIT',{function_clause,[{?MODULE,Name,Args,_}|_]}}) -> - ok; -fc(Name, Args, {'EXIT',{function_clause,[{?MODULE,_,Args,_}|_]}}) - when ?MODULE =:= bs_match_inline_SUITE -> - ok. - %% Cover the clause handling bs_context to binary in %% beam_block:initialized_regs/2. cover_beam_bool(Config) when is_list(Config) -> @@ -1836,8 +1830,8 @@ no_partition_2(42.0, a6) -> calling_a_binary(Config) when is_list(Config) -> [] = call_binary(<<>>, []), - {'EXIT',{badarg,_}} = (catch call_binary(<<1>>, [])), - {'EXIT',{badarg,_}} = (catch call_binary(<<1,2,3>>, [])), + ?assertError(badarg, call_binary(<<1>>, [])), + ?assertError(badarg, call_binary(<<1,2,3>>, [])), ok. call_binary(<<>>, Acc) -> @@ -1847,14 +1841,14 @@ call_binary(<>, Acc) -> binary_in_map(Config) when is_list(Config) -> ok = match_binary_in_map(#{key => <<42:8>>}), - {'EXIT',{{badmatch,#{key := 1}},_}} = - (catch match_binary_in_map(#{key => 1})), - {'EXIT',{{badmatch,#{key := <<1023:16>>}},_}} = - (catch match_binary_in_map(#{key => <<1023:16>>})), - {'EXIT',{{badmatch,#{key := <<1:8>>}},_}} = - (catch match_binary_in_map(#{key => <<1:8>>})), - {'EXIT',{{badmatch,not_a_map},_}} = - (catch match_binary_in_map(not_a_map)), + ?assertError({badmatch,#{key := 1}}, + match_binary_in_map(#{key => 1})), + ?assertError({badmatch,#{key := <<1023:16>>}}, + match_binary_in_map(#{key => <<1023:16>>})), + ?assertError({badmatch,#{key := <<1:8>>}}, + match_binary_in_map(#{key => <<1:8>>})), + ?assertError({badmatch,not_a_map}, + match_binary_in_map(not_a_map)), ok. match_binary_in_map(Map) -> @@ -1876,9 +1870,9 @@ select_on_integer(Config) when is_list(Config) -> 42 = do_select_on_integer(<<42>>), <<"abc">> = do_select_on_integer(<<128,"abc">>), - {'EXIT',_} = (catch do_select_on_integer(<<0:1>>)), - {'EXIT',_} = (catch do_select_on_integer(<<1:1>>)), - {'EXIT',_} = (catch do_select_on_integer(<<0:1,0:15>>)), + ?assertError(_, do_select_on_integer(<<0:1>>)), + ?assertError(_, do_select_on_integer(<<1:1>>)), + ?assertError(_, do_select_on_integer(<<0:1,0:15>>)), ok. %% The ASN.1 compiler frequently generates code like this. @@ -1954,7 +1948,7 @@ bad_literals(_Config) -> no_match = bad_literals_2(<<"abc">>), Sz = id(8), - {'EXIT',{{badmatch,_},_}} = (catch <<-1:Sz>> = <<-1>>), + ?assertError({badmatch,_}, <<-1:Sz>> = <<-1>>), ok. bad_literals_1() -> @@ -2031,7 +2025,7 @@ good_literals(_Config) -> constant_propagation(_Config) -> <<5>> = constant_propagation_a(a, <<5>>), - {'EXIT',{{case_clause,b},_}} = (catch constant_propagation_a(b, <<5>>)), + ?assertError({case_clause,b}, constant_propagation_a(b, <<5>>)), 258 = constant_propagation_b(<<1,2>>), F = constant_propagation_c(), 259 = F(<<1,3>>), @@ -2081,7 +2075,7 @@ is_next_char_whitespace(<>) -> get_payload(_Config) -> <<3445:48>> = do_get_payload(#ext_header{ext_hdr_opts = <<3445:48>>}), - {'EXIT',_} = (catch do_get_payload(#ext_header{})), + ?assertError(_, do_get_payload(#ext_header{})), ok. do_get_payload(ExtHdr) -> @@ -2116,10 +2110,10 @@ num_slots_different(_Config) -> {<<"de">>, <<"navigation">>, <<"Resources">>, <<"Ressourcen">>}], _ = [{ok,Res} = lgettext(A, B, C) || {A,B,C,Res} <- Ts], - {'EXIT',_} = (catch lgettext(<<"d">>, <<"default">>, <<"Remove">>)), - {'EXIT',_} = (catch lgettext("", <<"default">>, <<"Remove">>)), - {'EXIT',_} = (catch lgettext(<<"de">>, <<"def">>, <<"Remove">>)), - {'EXIT',_} = (catch lgettext(<<"de">>, <<"default">>, <<"Res">>)), + ?assertError(_, lgettext(<<"d">>, <<"default">>, <<"Remove">>)), + ?assertError(_, lgettext("", <<"default">>, <<"Remove">>)), + ?assertError(_, lgettext(<<"de">>, <<"def">>, <<"Remove">>)), + ?assertError(_, lgettext(<<"de">>, <<"default">>, <<"Res">>)), ok. @@ -2205,8 +2199,8 @@ is_ascii(_Config) -> true = do_is_ascii(<<>>), true = do_is_ascii(<<"string">>), false = do_is_ascii(<<1024/utf8>>), - {'EXIT',{function_clause,_}} = (catch do_is_ascii(<<$A,0:3>>)), - {'EXIT',{function_clause,_}} = (catch do_is_ascii(<<16#80,0:3>>)), + ?assertError(function_clause, do_is_ascii(<<$A,0:3>>)), + ?assertError(function_clause, do_is_ascii(<<16#80,0:3>>)), ok. do_is_ascii(<<>>) -> @@ -2443,7 +2437,7 @@ do_matching_meets_apply(_Bin, {Handler, State}) -> %% Exception handling was broken on the failure path of bs_start_match as %% beam_ssa_bsm accidentally cloned and renamed the ?BADARG_BLOCK. exceptions_after_match_failure(_Config) -> - {'EXIT', {badarith, _}} = (catch do_exceptions_after_match_failure(atom)), + ?assertError(badarith, do_exceptions_after_match_failure(atom)), ok = do_exceptions_after_match_failure(<<0, 1, "gurka">>), ok = do_exceptions_after_match_failure(2.0). @@ -2513,9 +2507,9 @@ empty_matches(Config) when is_list(Config) -> 0 = id(Zero), ok = em_4(<<>>, <<>>), - {'EXIT',{function_clause,[_|_]}} = catch em_4(<<>>, <<0:1>>), - {'EXIT',{function_clause,[_|_]}} = catch em_4(<<0:1>>, <<>>), - {'EXIT',{function_clause,[_|_]}} = catch em_4(<<0:1>>, <<0:1>>), + ?assertError(function_clause, em_4(<<>>, <<0:1>>)), + ?assertError(function_clause, em_4(<<0:1>>, <<>>)), + ?assertError(function_clause, em_4(<<0:1>>, <<0:1>>)), ok = em_5(), @@ -2767,9 +2761,9 @@ one_clause(I) -> %% GH-6410: Fix crash in beam_ssa_bsm. gh_6410(_Config) -> 0 = do_gh_6410(<<42>>), - {'EXIT',{{case_clause,<<>>},[_|_]}} = catch do_gh_6410(<<>>), - {'EXIT',{{case_clause,a},[_|_]}} = catch do_gh_6410(a), - {'EXIT',{badarith,[_|_]}} = catch do_gh_6410([]), + ?assertError({case_clause,<<>>}, do_gh_6410(<<>>)), + ?assertError({case_clause,a}, do_gh_6410(a)), + ?assertError(badarith, do_gh_6410([])), ok. @@ -2788,7 +2782,7 @@ bs_match(_Config) -> <<1,1>> = do_bs_match_1(whatever, <<1,1>>), {a,b,c} = do_bs_match_1(whatever, {a,b,c}), - {'EXIT',{badarg,_}} = catch do_bs_match_gh_6551a(<<>>), + ?assertError(badarg, do_bs_match_gh_6551a(<<>>)), false = do_bs_match_gh_6551a(<<42>>), {0,0} = do_bs_match_gh_6551b(0), @@ -2798,11 +2792,11 @@ bs_match(_Config) -> <<0,0>> = do_bs_match_gh_6613(<<0,0>>), <<"abc">> = do_bs_match_gh_6660(id(<<"abc">>)), - {'EXIT', {{try_clause,abc},_}} = catch do_bs_match_gh_6660(id(abc)), + ?assertError({try_clause,abc}, do_bs_match_gh_6660(id(abc))), - {'EXIT',{{case_clause,_},_}} = catch do_bs_match_gh_6755(id(<<"1000">>)), + ?assertError({case_clause,_}, do_bs_match_gh_6755(id(<<"1000">>))), - {'EXIT',{{badmatch,<<>>},_}} = catch do_bs_match_gh_7467(<<>>), + ?assertError({badmatch,<<>>}, do_bs_match_gh_7467(<<>>)), {0,<<1,2,3>>} = do_bs_match_gh_8280(), @@ -2947,7 +2941,7 @@ binary_aliases(_Config) -> {A,B,X} end, {0,0,<<0>>} = F7(id(<<0>>)), - {'EXIT',{{badmatch,<<1>>},_}} = catch F7(<<1>>), + ?assertError({badmatch,<<1>>}, F7(<<1>>)), F8 = fun(Val) -> (<> = X) = (Y = <>) = Val, @@ -2965,7 +2959,7 @@ binary_aliases(_Config) -> <<>> = (<<>> = X) end, <<>> = F10(id(<<>>)), - {'EXIT',{{badmatch,42},_}} = catch F10(id(42)), + ?assertError({badmatch,42}, F10(id(42))), F11 = fun(Bin) -> <> = <> = <> = Bin, @@ -2993,8 +2987,8 @@ binary_aliases(_Config) -> end, ok = F14([<<>>|0]), ok = F14([<<-1:32>>|32]), - {'EXIT',{{badmatch,[<<0:16>>|0]},_}} = catch F14([<<0:16>>|0]), - {'EXIT',{{badmatch,[<<0:16>>|atom]},_}} = catch F14([<<0:16>>|atom]), + ?assertError({badmatch,[<<0:16>>|0]}, F14([<<0:16>>|0])), + ?assertError({badmatch,[<<0:16>>|atom]}, F14([<<0:16>>|atom])), F15 = fun(Bin) -> {<<_:Y>>, _} = {_, Y} = id(Bin), @@ -3002,8 +2996,8 @@ binary_aliases(_Config) -> end, 0 = F15({<<>>, 0}), 32 = F15({<<-1:32>>, 32}), - {'EXIT',{{badmatch,{<<0:16>>,0}},_}} = catch F15({<<0:16>>, 0}), - {'EXIT',{{badmatch,{<<0:16>>,atom}},_}} = catch F15({<<0:16>>, atom}), + ?assertError({badmatch,{<<0:16>>,0}}, F15({<<0:16>>, 0})), + ?assertError({badmatch,{<<0:16>>,atom}}, F15({<<0:16>>, atom})), F16 = fun(Bin) -> [{<<_:Y>>, _}] = [{_, Y}] = id(Bin), @@ -3011,13 +3005,13 @@ binary_aliases(_Config) -> end, 0 = F16([{<<>>, 0}]), 32 = F16([{<<-1:32>>, 32}]), - {'EXIT',{{badmatch,[{<<0:16>>,0}]},_}} = catch F16([{<<0:16>>, 0}]), - {'EXIT',{{badmatch,[{<<0:16>>,atom}]},_}} = catch F16([{<<0:16>>, atom}]), + ?assertError({badmatch,[{<<0:16>>,0}]}, F16([{<<0:16>>, 0}])), + ?assertError({badmatch,[{<<0:16>>,atom}]}, F16([{<<0:16>>, atom}])), F17 = fun(#{[] := <<_>>, [] := <<_>>}) -> ok end, ok = F17(id(#{[] => <<42>>})), - {'EXIT',{function_clause,_}} = catch F17(id(#{[] => <<>>})), - {'EXIT',{function_clause,_}} = catch F17(id(atom)), + ?assertError(function_clause, F17(id(#{[] => <<>>}))), + ?assertError(function_clause, F17(id(atom))), F18 = fun(<<_>> = Bin) -> case Bin of @@ -3034,16 +3028,16 @@ binary_aliases(_Config) -> F19 = fun(B) -> <<42:Sz>> = Sz = <<_>> = B end, - {'EXIT',{{badmatch,<<0>>},_}} = catch F19(<<0>>), - {'EXIT',{{badmatch,<<>>},_}} = catch F19(<<>>), - {'EXIT',{{badmatch,0},_}} = catch F19(0), + ?assertError({badmatch,<<0>>}, F19(<<0>>)), + ?assertError({badmatch,<<>>}, F19(<<>>)), + ?assertError({badmatch,0}, F19(0)), F20 = fun([<<>>] = [<<>>]) -> ok end, ok = F20([<<>>]), a = gh_6467(id(0), id(<<0>>), id(0)), - {'EXIT',{{badmatch,0},_}} = catch gh_6467(id(0), id(<<0>>), id([])), - {'EXIT',{{badmatch,<<7>>},_}} = catch gh_6467(id(<<7>>), id(<<33>>), id([])), + ?assertError({badmatch,0}, gh_6467(id(0), id(<<0>>), id([]))), + ?assertError({badmatch,<<7>>}, gh_6467(id(<<7>>), id(<<33>>), id([]))), F21 = fun(<<_:(true andalso 0)>> = <<>>) -> ok; (_) -> error @@ -3084,26 +3078,26 @@ binary_aliases(_Config) -> error = gh6415_nomatch(an_atom), 42 = gh6415_match_a(id(<<42>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_a(id(<<>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_a(id(a)), + ?assertError(function_clause, gh6415_match_a(id(<<>>))), + ?assertError(function_clause, gh6415_match_a(id(a))), {42,<<>>} = gh6415_match_b(id(<<42>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_b(id(<<1,2>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_b(id(<<>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_b(id(a)), + ?assertError(function_clause, gh6415_match_b(id(<<1,2>>))), + ?assertError(function_clause, gh6415_match_b(id(<<>>))), + ?assertError(function_clause, gh6415_match_b(id(a))), - {'EXIT',{_,_}} = catch gh6415_match_c(), + ?assertError(_, gh6415_match_c()), ok = gh6415_match_d(id(<<163>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_d(id(<<>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_d(id(a)), + ?assertError(function_clause, gh6415_match_d(id(<<>>))), + ?assertError(function_clause, gh6415_match_d(id(a))), ok = gh6415_match_e(id(<<163,0>>)), ok = gh6415_match_e(id(<<99,8,42>>)), ok = gh6415_match_e(id(<<99,17,-1:17>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_e(id(<<163>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_e(id(<<>>)), - {'EXIT',{function_clause,_}} = catch gh6415_match_e(id(a)), + ?assertError(function_clause, gh6415_match_e(id(<<163>>))), + ?assertError(function_clause, gh6415_match_e(id(<<>>))), + ?assertError(function_clause, gh6415_match_e(id(a))), 7777 = gh6415_match_f(id(<<17,7777:17>>)), 1234 = gh6415_match_f(id(<<17,1234:17>>)), @@ -3136,10 +3130,10 @@ gh6415_c(_, _) -> error. gh6415_case_clause(X) -> - {'EXIT',{{case_clause,0},_}} = catch gh6415_case_clause_a(X), - {'EXIT',{{case_clause,0},_}} = catch gh6415_case_clause_b(X), - {'EXIT',{{case_clause,0},_}} = catch gh6415_case_clause_c(X), - {'EXIT',{{case_clause,0},_}} = catch gh6415_case_clause_d(X), + ?assertError({case_clause,0}, gh6415_case_clause_a(X)), + ?assertError({case_clause,0}, gh6415_case_clause_b(X)), + ?assertError({case_clause,0}, gh6415_case_clause_c(X)), + ?assertError({case_clause,0}, gh6415_case_clause_d(X)), ok. gh6415_case_clause_a(X) -> @@ -3315,10 +3309,10 @@ bs_test_tail(Config) -> "abc" = bs_test_tail_int(<<(id(<<"abc">>))/binary>>), [2.0,3.0] = bs_test_tail_float(<<(id(2.0)):64/float,(id(3.0)):64/float>>), - {'EXIT',{function_clause,_}} = catch bs_test_tail_float(<<(id(-1)):128>>), + ?assertError(function_clause, bs_test_tail_float(<<(id(-1)):128>>)), ok = bs_test_partial_tail(<<(id(0))>>), - {'EXIT',{function_clause,_}} = catch bs_test_partial_tail(<<(id(1))>>), + ?assertError(function_clause, bs_test_partial_tail(<<(id(1))>>)), ok. @@ -3364,3 +3358,30 @@ do_otp_19019(A) -> %%% Utilities. id(I) -> I. + +do_fc(ExprFun) -> + try + ExprFun() + of + Result -> + error({unexpected,success}) + catch + error:function_clause -> ok; + error:{case_clause,_} when ?MODULE =:= bs_match_inline_SUITE -> ok + end. + +do_fc(Name, Args, CallFun) -> + try + CallFun() + of + Result -> + error({unexpected,success}) + catch + error:function_clause:Stack -> + case Stack of + [{?MODULE,Name,Args,_}|_] -> + ok; + [{?MODULE,_,Args,_}|_] when ?MODULE =:= bs_match_inline_SUITE -> + ok + end + end. diff --git a/lib/compiler/test/bs_utf_SUITE.erl b/lib/compiler/test/bs_utf_SUITE.erl index 6cf3d6e1293..c68908878ed 100644 --- a/lib/compiler/test/bs_utf_SUITE.erl +++ b/lib/compiler/test/bs_utf_SUITE.erl @@ -29,6 +29,9 @@ literals/1,coverage/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). + +-define(FC(Expr), do_fc(fun() -> Expr end)). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -273,23 +276,23 @@ literals(Config) when is_list(Config) -> %% Invalid literals. I = 0, - {'EXIT',{badarg,_}} = (catch <<(-1)/utf8,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<(-1)/utf16,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<(-1)/little-utf16,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<(-1)/utf32,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<(-1)/little-utf32,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<16#D800/utf8,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<16#D800/utf16,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<16#D800/little-utf16,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<16#D800/utf32,I/utf8>>), - {'EXIT',{badarg,_}} = (catch <<16#D800/little-utf32,I/utf8>>), + ?assertError(badarg, <<(-1)/utf8,I/utf8>>), + ?assertError(badarg, <<(-1)/utf16,I/utf8>>), + ?assertError(badarg, <<(-1)/little-utf16,I/utf8>>), + ?assertError(badarg, <<(-1)/utf32,I/utf8>>), + ?assertError(badarg, <<(-1)/little-utf32,I/utf8>>), + ?assertError(badarg, <<16#D800/utf8,I/utf8>>), + ?assertError(badarg, <<16#D800/utf16,I/utf8>>), + ?assertError(badarg, <<16#D800/little-utf16,I/utf8>>), + ?assertError(badarg, <<16#D800/utf32,I/utf8>>), + ?assertError(badarg, <<16#D800/little-utf32,I/utf8>>), B = 16#10FFFF+1, - {'EXIT',{badarg,_}} = (catch <>), - {'EXIT',{badarg,_}} = (catch <>), - {'EXIT',{badarg,_}} = (catch <>), - {'EXIT',{badarg,_}} = (catch <>), - {'EXIT',{badarg,_}} = (catch <>), + ?assertError(badarg, <>), + ?assertError(badarg, <>), + ?assertError(badarg, <>), + ?assertError(badarg, <>), + ?assertError(badarg, <>), %% Matching of bad literals. error = bad_literal_match(<<237,160,128>>), %16#D800 in UTF-8 @@ -330,7 +333,7 @@ coverage(Config) when is_list(Config) -> 0 = coverage_2(<<4096/utf8,65536/utf8,0>>), 1 = coverage_2(<<1024/utf8,1025/utf8,1>>), - fc(catch coverage_3(1)), + ?FC(coverage_3(1)), %% Cover beam_flatten (combining the heap allocation in %% a subsequent test_heap instruction into the bs_init2 @@ -409,8 +412,17 @@ utf32_data() -> 16#0391/little-utf32,16#002E/little-utf32>>, <<16#41:32/little,NotIdentical:32/little, 16#0391:32/little,16#2E:32/little>>}. - -fc({'EXIT',{function_clause,_}}) -> ok; -fc({'EXIT',{{case_clause,_},_}}) when ?MODULE =:= bs_utf_inline_SUITE -> ok. + +%% Common utilities. +do_fc(ExprFun) -> + try + ExprFun() + of + Result -> + error({unexpected,success}) + catch + error:function_clause -> ok; + error:{case_clause,_} when ?MODULE =:= bs_utf_inline_SUITE -> ok + end. id(I) -> I. diff --git a/lib/compiler/test/compilation_SUITE.erl b/lib/compiler/test/compilation_SUITE.erl index a3a5a5af717..3857b672781 100644 --- a/lib/compiler/test/compilation_SUITE.erl +++ b/lib/compiler/test/compilation_SUITE.erl @@ -64,6 +64,7 @@ use_nifs/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -435,7 +436,7 @@ do_otp_8949_a() -> split_cases(_) -> dummy1 = do_split_cases(x), - {'EXIT',{{badmatch,b},_}} = (catch do_split_cases(y)), + ?assertError({badmatch,b}, do_split_cases(y)), ok. do_split_cases(A) -> diff --git a/lib/compiler/test/compile_SUITE.erl b/lib/compiler/test/compile_SUITE.erl index 7e448dd8ef2..b27809b31f4 100644 --- a/lib/compiler/test/compile_SUITE.erl +++ b/lib/compiler/test/compile_SUITE.erl @@ -25,6 +25,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("stdlib/include/erl_compile.hrl"). +-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, @@ -659,7 +660,10 @@ encrypted_abstr(Config) when is_list(Config) -> OldPath = code:get_path(), try NewPath = OldPath -- [filename:dirname(code:which(crypto))], - (catch application:stop(crypto)), + try + application:stop(crypto) + catch _:_ -> ok + end, code:delete(crypto), code:purge(crypto), code:set_path(NewPath), @@ -902,10 +906,12 @@ get_files(Config, Module, OutputName) -> run(Target, Func, Args) -> Module = list_to_atom(filename:rootname(filename:basename(Target))), {module, Module} = code:load_abs(filename:rootname(Target)), - Result = (catch apply(Module, Func, Args)), - true = code:delete(Module), - false = code:purge(Module), - Result. + try + apply(Module, Func, Args) + after + true = code:delete(Module), + false = code:purge(Module) + end. exists(Name) -> case file:read_file_info(Name) of @@ -1026,16 +1032,16 @@ tuple_calls(Config) when is_list(Config) -> TupleCallsFalse = [{attribute,Anno,module,tuple_calls_false}|Forms], {ok,_,TupleCallsFalseBinary} = compile_forms(TupleCallsFalse, [binary]), code:load_binary(tuple_calls_false, "compile_SUITE.erl", TupleCallsFalseBinary), - {'EXIT',{badarg,_}} = (catch tuple_calls_false:store(dict())), - {'EXIT',{badarg,_}} = (catch tuple_calls_false:size(dict())), - {'EXIT',{badarg,_}} = (catch tuple_calls_false:size(empty_tuple())), + ?assertError(badarg, tuple_calls_false:store(dict())), + ?assertError(badarg, tuple_calls_false:size(dict())), + ?assertError(badarg, tuple_calls_false:size(empty_tuple())), TupleCallsTrue = [{attribute,Anno,module,tuple_calls_true}|Forms], {ok,_,TupleCallsTrueBinary} = compile_forms(TupleCallsTrue, [binary,tuple_calls]), code:load_binary(tuple_calls_true, "compile_SUITE.erl", TupleCallsTrueBinary), Dict = tuple_calls_true:store(dict()), 1 = tuple_calls_true:size(Dict), - {'EXIT',{badarg,_}} = (catch tuple_calls_true:size(empty_tuple())), + ?assertError(badarg, tuple_calls_true:size(empty_tuple())), ok. @@ -2381,23 +2387,24 @@ get_unique_beam_files() -> run(Config, Tests) -> F = fun({N,P,Env,Ws,Run}, _BadL) when is_function(Run, 1) -> - case catch run_test(Config, P, Env, Ws, Run) of + try run_test(Config, P, Env, Ws, Run) of ok -> - ok; - Bad -> + ok + catch + error:Bad:Stack -> io:format("~nTest ~p failed. Expected~n ~p~n" - "but got~n ~p~n", [N, ok, Bad]), + "but got~n ~p ~p~n", [N, ok, Bad, Stack]), fail() end; ({N,P,Env,Ws,Expected}, BadL) when is_list(Expected); is_tuple(Expected) -> io:format("### ~s\n", [N]), - case catch run_test(Config, P, Env, Ws, none) of + try run_test(Config, P, Env, Ws, none) of Expected -> - BadL; - Bad -> + BadL + catch errore:Bad:Stack -> io:format("~nTest ~p failed. Expected~n ~p~n" - "but got~n ~p~n", [N, Expected, Bad]), + "but got~n ~p ~p~n", [N, Expected, Bad, Stack]), fail() end end, diff --git a/lib/compiler/test/core_fold_SUITE.erl b/lib/compiler/test/core_fold_SUITE.erl index c60e533a618..8cb22c9575b 100644 --- a/lib/compiler/test/core_fold_SUITE.erl +++ b/lib/compiler/test/core_fold_SUITE.erl @@ -37,6 +37,7 @@ -export([foo/0,foo/1,foo/2,foo/3]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -90,17 +91,17 @@ t_element(Config) when is_list(Config) -> z = id(element(Pos, Tuple)), %% Calls that will fail. - {'EXIT',{badarg,_}} = (catch element(5, {a,b,c,d})), - {'EXIT',{badarg,_}} = (catch element(5, {a,b,X,d})), - {'EXIT',{badarg,_}} = (catch element(5.0, {a,b,X,d})), - {'EXIT',{badarg,_}} = (catch element(2, not_a_tuple)), - {'EXIT',{badarg,_}} = (catch element(2, [])), - {'EXIT',{badarg,_}} = (catch element(2, Tuple == 3)), + ?assertError(badarg, element(5, {a,b,c,d})), + ?assertError(badarg, element(5, {a,b,X,d})), + ?assertError(badarg, element(5.0, {a,b,X,d})), + ?assertError(badarg, element(2, not_a_tuple)), + ?assertError(badarg, element(2, [])), + ?assertError(badarg, element(2, Tuple == 3)), case id({a,b,c}) of {_,_,_}=Tup -> - {'EXIT',{badarg,_}} = (catch element(4, Tup)) + ?assertError(badarg, element(4, Tup)) end, - {'EXIT',{badarg,_}} = (catch element(1, tuple_size(Tuple))), + ?assertError(badarg, element(1, tuple_size(Tuple))), ok. @@ -117,11 +118,11 @@ setelement(Config) when is_list(Config) -> {{d,c,b,a,x}, {z,c,b,a,x}} = setelement_cover(erlang:make_tuple(5, x)), - {'EXIT',{badarg,_}} = (catch setelement_crash({a,b,c,d,e,f})), + ?assertError(badarg, setelement_crash({a,b,c,d,e,f})), error = setelement_crash_2({a,b,c,d,e,f}, <<42>>), - {'EXIT',{badarg,_}} = (catch setelement(1, not_a_tuple, New)), - {'EXIT',{badarg,_}} = (catch setelement(3, {a,b}, New)), + ?assertError(badarg, setelement(1, not_a_tuple, New)), + ?assertError(badarg, setelement(3, {a,b}, New)), ok. @@ -163,9 +164,9 @@ t_length(Config) when is_list(Config) -> 5 = id(length([x|Tail])), %% Will fail. - {'EXIT',{badarg,_}} = (catch id(length([a,b|c]))), - {'EXIT',{badarg,_}} = (catch id(length([a,Blurf|c]))), - {'EXIT',{badarg,_}} = (catch id(length(atom))), + ?assertError(badarg, id(length([a,b|c]))), + ?assertError(badarg, id(length([a,Blurf|c]))), + ?assertError(badarg, id(length(atom))), ok. @@ -180,7 +181,7 @@ append(Config) when is_list(Config) -> [a,b,c,d,e,f,g,h,i,j,k] = id(?APPEND([a,b,c,d,e,f],[g,h,i,j,k])), [a,b,c,d,e] = id(?APPEND([a,b,c],id([d,e]))), [0,1,2,3,4,5,6] = id(?APPEND([A,1,2,3],[4,5,6])), - {'EXIT',{badarg,_}} = (catch id(?APPEND([A|blurf],[4,5,6]))), + ?assertError(badarg, id(?APPEND([A|blurf],[4,5,6]))), ok. t_apply(Config) when is_list(Config) -> @@ -198,13 +199,13 @@ t_apply(Config) when is_list(Config) -> 16.0 = apply(M, foo, [12.0,4]), %% Will fail. - {'EXIT',{badarg,_}} = (catch apply([a,b,c], foo, [])), - {'EXIT',{badarg,_}} = (catch apply(42, foo, [])), - {'EXIT',{badarg,_}} = (catch apply(?MODULE, 45, [xx])), - {'EXIT',{badarg,_}} = (catch apply(?MODULE, foo, {a,b})), - {'EXIT',{badarg,_}} = (catch apply(M, M, [1009|10010])), - {'EXIT',{badarg,_}} = (catch apply(?MODULE, foo, [10000|9999])), - {'EXIT',{badarg,_}} = (catch apply(?MODULE, foo, a)), + ?assertError(badarg, apply([a,b,c], foo, [])), + ?assertError(badarg, apply(42, foo, [])), + ?assertError(badarg, apply(?MODULE, 45, [xx])), + ?assertError(badarg, apply(?MODULE, foo, {a,b})), + ?assertError(badarg, apply(M, M, [1009|10010])), + ?assertError(badarg, apply(?MODULE, foo, [10000|9999])), + ?assertError(badarg, apply(?MODULE, foo, a)), ok. @@ -266,7 +267,7 @@ nested_call_in_case(Config) when is_list(Config) -> {ok,Mod} = c:c(Core, Opts), yes = Mod:a([1,2,3], 2), no = Mod:a([1,2,3], 4), - {'EXIT',_} = (catch Mod:a(not_a_list, 42)), + ?assertError(_, Mod:a(not_a_list, 42)), _ = code:delete(Mod), _ = code:purge(Mod), ok. @@ -324,7 +325,7 @@ coverage(Config) when is_list(Config) -> end, %% Cover is literal_fun/1. - {'EXIT',{{case_clause,42},_}} = (catch cover_is_literal_fun()), + ?assertError({case_clause,42}, cover_is_literal_fun()), %% Cover core_lib. ok = cover_core_lib([ok,nok]), @@ -524,11 +525,11 @@ do_unnecessary_building_2({a,_,_}=T) -> %% sys_core_fold will have proper filenames and line numbers. Thus, no %% "no_file" warnings. no_no_file(_Config) -> - {'EXIT',{{case_clause,0},_}} = (catch source(true, any)), + ?assertError({case_clause,0}, source(true, any)), surgery = (tim(#{reduction => any}))(), false = soul(#{[] => true}), - {'EXIT',{{case_clause,true},_}} = (catch soul(#{[] => false})), + ?assertError({case_clause,true}, soul(#{[] => false})), ok = experiment(), ok. @@ -565,7 +566,7 @@ experiment() -> %% Make sure we don't try to move a fun into a guard. configuration(_Config) -> - {'EXIT',_} = (catch configuration()), + ?assertError(_, configuration()), ok. configuration() -> @@ -582,9 +583,9 @@ supplies(_Config) -> %% Other error behaviour when inlined. ok; _ -> - {'EXIT',{function_clause,_}} = (catch do_supplies(#{1 => <<1,2,3>>})), - {'EXIT',{function_clause,_}} = (catch do_supplies(#{1 => a})), - {'EXIT',{function_clause,_}} = (catch do_supplies(42)), + ?assertError(function_clause, do_supplies(#{1 => <<1,2,3>>})), + ?assertError(function_clause, do_supplies(#{1 => a})), + ?assertError(function_clause, do_supplies(42)), ok end. @@ -592,8 +593,8 @@ do_supplies(#{1 := Value}) when byte_size(Value), byte_size(kg) -> working. redundant_stack_frame(_Config) -> {1,2} = do_redundant_stack_frame(#{x=>1,y=>2}), - {'EXIT',{{badkey,_,x},_}} = (catch do_redundant_stack_frame(#{y=>2})), - {'EXIT',{{badkey,_,y},_}} = (catch do_redundant_stack_frame(#{x=>1})), + ?assertError({badkey,_,x}, do_redundant_stack_frame(#{y=>2})), + ?assertError({badkey,_,y}, do_redundant_stack_frame(#{x=>1})), ok. do_redundant_stack_frame(Map) -> @@ -648,9 +649,9 @@ export_from_case_2(Bool, Rec) -> empty_values(_Config) -> case ?MODULE of core_fold_inline_SUITE -> - {'EXIT',_} = (catch do_empty_values()); + ?assertError(_, do_empty_values()); _ -> - {'EXIT',{function_clause,_}} = (catch do_empty_values()) + ?assertError(function_clause, do_empty_values()) end, ok. @@ -711,12 +712,12 @@ do_receive_effect() -> {} = receive _ -> {} = {} end. nested_lets(_Config) -> - {'EXIT',{{case_clause,ok},_}} = catch nested_lets_1(<<42>>), - {'EXIT',{badarith,_}} = catch nested_lets_2(id(0), id(0)), - {'EXIT',{badarith,_}} = catch nested_lets_3(), - {'EXIT',{undef,_}} = catch nested_lets_4(), - {'EXIT',{{case_clause,_},_}} = catch nested_lets_5(), - {'EXIT',{badarith,_}} = catch nested_lets_6(), + ?assertError({case_clause,ok}, nested_lets_1(<<42>>)), + ?assertError(badarith, nested_lets_2(id(0), id(0))), + ?assertError(badarith, nested_lets_3()), + ?assertError(undef, nested_lets_4()), + ?assertError({case_clause,_}, nested_lets_5()), + ?assertError(badarith, nested_lets_6()), ok. @@ -859,10 +860,10 @@ nested_lets_6() -> end. map_effect(_Config) -> - {'EXIT',{{badkey,key},_}} = catch map_effect_1(), + ?assertError({badkey,key}, map_effect_1()), - {'EXIT',{{badkey,key},_}} = catch map_effect_2(#{}), - {'EXIT',{{badmap,no_map},_}} = catch map_effect_2(no_map), + ?assertError({badkey,key}, map_effect_2(#{})), + ?assertError({badmap,no_map}, map_effect_2(no_map)), ok. diff --git a/lib/compiler/test/error_SUITE.erl b/lib/compiler/test/error_SUITE.erl index 5273d94dd00..c06e69e5a7d 100644 --- a/lib/compiler/test/error_SUITE.erl +++ b/lib/compiler/test/error_SUITE.erl @@ -428,12 +428,13 @@ run(Config, Tests) -> run(Tests, File, WriteBeam) -> F = fun({N,P,Ws,E}, BadL) -> - case catch run_test(P, File, Ws, WriteBeam) of - E -> - BadL; - Bad -> + try run_test(P, File, Ws, WriteBeam) of + E -> + BadL + catch + error:Bad:Stack -> io:format("~nTest ~p failed. Expected~n ~p~n" - "but got~n ~p~n", [N, E, Bad]), + "but got~n ~p ~p~n", [N, E, Bad, Stack]), fail() end end, @@ -445,12 +446,13 @@ run2(Config, Tests) -> run2(Tests, File, WriteBeam) -> F = fun({N,P,Ws,E}, BadL) -> - case catch filter(run_test(P, File, Ws, WriteBeam)) of + try filter(run_test(P, File, Ws, WriteBeam)) of E -> - BadL; - Bad -> + BadL + catch + error:Bad:Stack -> io:format("~nTest ~p failed. Expected~n ~p~n" - "but got~n ~p~n", [N, E, Bad]), + "but got~n ~p ~p~n", [N, E, Bad, Stack]), fail() end end, diff --git a/lib/compiler/test/float_SUITE.erl b/lib/compiler/test/float_SUITE.erl index aa2f0cd6ce9..ae877ab96c7 100644 --- a/lib/compiler/test/float_SUITE.erl +++ b/lib/compiler/test/float_SUITE.erl @@ -27,6 +27,7 @@ fconv_line_numbers/1,float_zero/1,exception_signals/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -63,10 +64,7 @@ match_on_zero_and_to_binary(X) when X == 0.0 -> <>. %% Shows the effect of pending exceptions on the x86. pending(Config) when is_list(Config) -> - case catch float_mul(1, 1.1e300, 3.14e300) of - {'EXIT',{badarith,_}} -> ok; - Other -> ct:fail({expected_exception,Other}) - end, + ?assertError(badarith, float_mul(1, 1.1e300, 3.14e300)), 0.0 = float_sub(2.0). float_sub(A)-> @@ -81,11 +79,11 @@ float_mul(Iter, A, B) when is_float(A), is_float(B) -> %% Thanks to Mikael Pettersson and Tobias Lindahl (HiPE). bif_calls(Config) when is_list(Config) -> - {'EXIT',{badarith,_}} = (catch bad_arith(2.0, 1.7)), - {'EXIT',{badarith,_}} = (catch bad_arith_again(2.0, [])), - {'EXIT',{badarith,_}} = (catch bad_arith_xor(2.0, [])), - {'EXIT',{badarith,_}} = (catch bad_arith_hd(2.0, [])), - {'EXIT',{badarith,_}} = (catch bad_negate(2.0, 1.7)), + ?assertError(badarith, bad_arith(2.0, 1.7)), + ?assertError(badarith, bad_arith_again(2.0, [])), + ?assertError(badarith, bad_arith_xor(2.0, [])), + ?assertError(badarith, bad_arith_hd(2.0, [])), + ?assertError(badarith, bad_negate(2.0, 1.7)), ok. bad_arith(X, Y) when is_float(X) -> @@ -172,20 +170,20 @@ math_functions(Config) when is_list(Config) -> -1.0 = math:fmod(-4.0, 1.5), -0.375 = math:fmod(-3.0, -0.875), 0.125 = math:fmod(8.125, -4), - {'EXIT',{badarith,_}} = (catch math:fmod(5.0, 0.0)), + ?assertError(badarith, math:fmod(5.0, 0.0)), %% Only for coverage (of beam_type.erl). - {'EXIT',{undef,_}} = (catch math:fnurfla(0)), - {'EXIT',{undef,_}} = (catch math:fnurfla(0, 0)), - {'EXIT',{badarg,_}} = (catch float(kalle)), - {'EXIT',{badarith,_}} = (catch name/1), + ?assertError(undef, math:fnurfla(0)), + ?assertError(undef, math:fnurfla(0, 0)), + ?assertError(badarg, float(kalle)), + ?assertError(badarith, name/1), ok. mixed_float_and_int(Config) when is_list(Config) -> 129.0 = pc(77, 23, 5), - {'EXIT',{badarith,_}} = catch mixed_1(id({a,b,c})), - {'EXIT',{{badarg,1/42},_}} = catch mixed_1(id(42)), + ?assertError(badarith, mixed_1(id({a,b,c}))), + ?assertError({badarg,1/42}, mixed_1(id(42))), ok. diff --git a/lib/compiler/test/fun_SUITE.erl b/lib/compiler/test/fun_SUITE.erl index 5984484ad82..02ee102bcfe 100644 --- a/lib/compiler/test/fun_SUITE.erl +++ b/lib/compiler/test/fun_SUITE.erl @@ -32,6 +32,7 @@ -export([call_me/1,dup1/0,dup2/0]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -86,12 +87,14 @@ evaluate(Str, Vars) -> eval_list([], _Vars) -> []; eval_list([{C_bin, Str, Bytes} | Rest], Vars) -> - case catch evaluate(Str, Vars) of - {'EXIT', Error} -> - io:format("Evaluation error: ~p, ~p, ~p~n", [Str, Vars, Error]), - exit(Error); + try evaluate(Str, Vars) of E_bin -> [{C_bin, E_bin, Str, Bytes} | eval_list(Rest, Vars)] + catch + error:Error:Stack -> + io:format("Evaluation error: ~p, ~p~n ~p ~p~n", + [Str, Vars, Error, Stack]), + erlang:raise(error, Error, Stack) end. one_test({C, E, Str, Correct}) -> @@ -211,12 +214,12 @@ external(Config) when is_list(Config) -> 6 = (id(fun lists:sum/1))([1,2,3]), 6 = id(fun lists:sum/1)([1,2,3]), - {'EXIT',{{badarity,_},_}} = (catch (fun lists:sum/1)(1, 2, 3)), - {'EXIT',{{badarity,_},_}} = (catch (id(fun lists:sum/1))(1, 2, 3)), - {'EXIT',{{badarity,_},_}} = (catch id(fun lists:sum/1)(1, 2, 3)), - {'EXIT',{{badarity,_},_}} = (catch apply(fun lists:sum/1, [1,2,3])), + ?assertError({badarity,_}, (fun lists:sum/1)(1, 2, 3)), + ?assertError({badarity,_}, (id(fun lists:sum/1))(1, 2, 3)), + ?assertError({badarity,_}, id(fun lists:sum/1)(1, 2, 3)), + ?assertError({badarity,_}, apply(fun lists:sum/1, [1,2,3])), - {'EXIT',{badarg,_}} = (catch bad_external_fun()), + ?assertError(badarg, bad_external_fun()), ok. @@ -296,23 +299,23 @@ eep37_gh6515_2() -> end]. badarity(Config) when is_list(Config) -> - {'EXIT',{{badarity,{_,[]}},_}} = (catch (fun badarity/1)()), - {'EXIT',{{badarity,_},_}} = (catch fun() -> 42 end(0)), + ?assertError({badarity,{_,[]}}, (fun badarity/1)()), + ?assertError({badarity,_}, fun() -> 42 end(0)), ok. badfun(_Config) -> X = not_a_fun, - expect_badfun(42, catch 42()), - expect_badfun(42.0, catch 42.0(1)), - expect_badfun(X, catch X()), - expect_badfun(X, catch X(1)), + ?assertError({badfun, 42}, 42()), + ?assertError({badfun, 42.0}, 42.0(1)), + ?assertError({badfun, X}, X()), + ?assertError({badfun, X}, X(1)), Len = length(atom_to_list(X)), - expect_badfun(Len, catch begin length(atom_to_list(X)) end(1)), + ?assertError({badfun, Len}, begin length(atom_to_list(X)) end(1)), - expect_badfun(42, catch 42(put(?FUNCTION_NAME, yes))), + ?assertError({badfun, 42}, 42(put(?FUNCTION_NAME, yes))), yes = erase(?FUNCTION_NAME), - expect_badfun(X, catch X(put(?FUNCTION_NAME, of_course))), + ?assertError({badfun, X}, X(put(?FUNCTION_NAME, of_course))), of_course = erase(?FUNCTION_NAME), %% A literal as a Fun used to crash the code generator. This only happened @@ -320,13 +323,9 @@ badfun(_Config) -> Literal = fun(literal = Fun) -> Fun() end, - expect_badfun(literal, catch Literal(literal)), - + ?assertError({badfun, literal}, Literal(literal)), ok. -expect_badfun(Term, Exit) -> - {'EXIT',{{badfun,Term},_}} = Exit. - duplicated_fun(_Config) -> try %% The following code used to crash the compiler before @@ -353,61 +352,61 @@ unused_fun(_Config) -> parallel_scopes(_Config) -> 1 = parallel_scopes_1a(), 1 = parallel_scopes_1b(), - {'EXIT',{{badmatch,99},_}} = catch parallel_scopes_1c(), + ?assertError({badmatch,99}, parallel_scopes_1c()), 10 = parallel_scopes_2a(), - {'EXIT',{{badmatch,15},_}} = catch parallel_scopes_2b(), + ?assertError({badmatch,15}, parallel_scopes_2b()), 500 = parallel_scopes_2c(500, 500), - {'EXIT',{{badmatch,1000},_}} = catch parallel_scopes_2c(500, 1000), + ?assertError({badmatch,1000}, parallel_scopes_2c(500, 1000)), 600 = parallel_scopes_2d(600, 600), - {'EXIT',{{badmatch,1000},_}} = catch parallel_scopes_2d(600, 1000), + ?assertError({badmatch,1000}, parallel_scopes_2d(600, 1000)), {a,20} = parallel_scopes_2e(20, 20), - {'EXIT',{{badmatch,{a,25}},_}} = catch parallel_scopes_2e(20, 25), + ?assertError({badmatch,{a,25}}, parallel_scopes_2e(20, 25)), {[42,2],42,a} = parallel_scopes_3(a), 42 = parallel_scopes_4a(id(42), id(42)), - {'EXIT',{{badmatch,77},_}} = catch parallel_scopes_4a(42, 77), + ?assertError({badmatch,77}, parallel_scopes_4a(42, 77)), 42 = parallel_scopes_4b(id(42), id(42)), - {'EXIT',{{badmatch,77},_}} = catch parallel_scopes_4b(42, 77), + ?assertError({badmatch,77}, parallel_scopes_4b(42, 77)), [same,2,same,2] = parallel_scopes_4c(id(same), id(same)), - {'EXIT',{{badmatch,55},_}} = catch parallel_scopes_4c(42, 55), + ?assertError({badmatch,55}, parallel_scopes_4c(42, 55)), 33 = parallel_scopes_5(id(33), id(33)), - {'EXIT',{{badmatch,44},_}} = catch parallel_scopes_5(33, 44), + ?assertError({badmatch,44}, parallel_scopes_5(33, 44)), 99 = parallel_scopes_6(id(99), id(99)), - {'EXIT',{{badmatch,88},_}} = catch parallel_scopes_6(77, 88), + ?assertError({badmatch,88}, parallel_scopes_6(77, 88)), 99 = parallel_scopes_7(id(99), id(99)), - {'EXIT',{{badmatch,88},_}} = catch parallel_scopes_7(77, 88), + ?assertError({badmatch,88}, parallel_scopes_7(77, 88)), 199 = parallel_scopes_8(id(199), id(199)), - {'EXIT',{{badmatch,200},_}} = catch parallel_scopes_8(id(199), id(200)), + ?assertError({badmatch,200}, parallel_scopes_8(id(199), id(200))), {299,299+299} = parallel_scopes_9(id(299), id(299), id(299+299)), - {'EXIT',{{badmatch,300},_}} = catch parallel_scopes_9(id(299), id(300), id(0)), - {'EXIT',{{badmatch,0},_}} = catch parallel_scopes_9(id(299), id(299), id(0)), + ?assertError({badmatch,300}, parallel_scopes_9(id(299), id(300), id(0))), + ?assertError({badmatch,0}, parallel_scopes_9(id(299), id(299), id(0))), 999 = parallel_scopes_10(false, 999, ignored, 999), - {'EXIT',{{badmatch,999},_}} = catch parallel_scopes_10(false, 700, ignored, 700), - {'EXIT',{{badmatch,1000},_}} = catch parallel_scopes_10(false, 999, ignored, 1000), + ?assertError({badmatch,999}, parallel_scopes_10(false, 700, ignored, 700)), + ?assertError({badmatch,1000}, parallel_scopes_10(false, 999, ignored, 1000)), 999 = parallel_scopes_10(true, 999, 999, ignored), 333 = parallel_scopes_10(true, 333, 333, ignored), - {'EXIT',{{badmatch,901},_}} = catch parallel_scopes_10(true, 900, 901, ignored), + ?assertError({badmatch,901}, parallel_scopes_10(true, 900, 901, ignored)), 889 = parallel_scopes_11(889, 889, 889), - {'EXIT',{{badmatch,800},_}} = catch parallel_scopes_11(889, 800, 889), - {'EXIT',{{badmatch,810},_}} = catch parallel_scopes_11(889, 889, 810), - {'EXIT',{{badmatch,889},_}} = catch parallel_scopes_11(a, a, a), + ?assertError({badmatch,800}, parallel_scopes_11(889, 800, 889)), + ?assertError({badmatch,810}, parallel_scopes_11(889, 889, 810)), + ?assertError({badmatch,889}, parallel_scopes_11(a, a, a)), 333 = parallel_scopes_12(333, 333, 333), - {'EXIT',{{badmatch,other},_}} = catch parallel_scopes_12(333, other, 333), - {'EXIT',{{badmatch,nope},_}} = catch parallel_scopes_12(333, 333, nope), + ?assertError({badmatch,other}, parallel_scopes_12(333, other, 333)), + ?assertError({badmatch,nope}, parallel_scopes_12(333, 333, nope)), [1,100] = parallel_scopes_13(99, 100), - {'EXIT',{{badmatch,no},_}} = catch parallel_scopes_13(no, 100), - {'EXIT',{{badmatch,nope},_}} = catch parallel_scopes_13(99, nope), + ?assertError({badmatch,no}, parallel_scopes_13(no, 100)), + ?assertError({badmatch,nope}, parallel_scopes_13(99, nope)), ok. @@ -605,7 +604,7 @@ coverage_3({[], A}) -> leaky_environment(_Config) -> G = fun(X, Y) -> X + Y end, F = fun(A) -> G(A, 0) end, - {'EXIT', {{badarity, {_, [1, flurb]}}, _}} = catch F(1, flurb), + ?assertError({badarity, {_, [1, flurb]}}, F(1, flurb)), ok. id(I) -> diff --git a/lib/compiler/test/guard_SUITE.erl b/lib/compiler/test/guard_SUITE.erl index 3656672e36e..fc5fa9887b8 100644 --- a/lib/compiler/test/guard_SUITE.erl +++ b/lib/compiler/test/guard_SUITE.erl @@ -28,6 +28,8 @@ -include_lib("syntax_tools/include/merl.hrl"). -include_lib("stdlib/include/assert.hrl"). +-define(AssertFunctionClause(E), ?assertError(function_clause, (E))). + -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, misc/1,const_cond/1,basic_not/1,complex_not/1,nested_nots/1, @@ -134,7 +136,7 @@ misc(Config) when is_list(Config) -> error = if abs(Zero > One) -> ok; true -> error end, ok = if is_integer(Zero) >= is_integer(One) -> ok end, - {'EXIT',{function_clause,_}} = catch misc_4(), + ?AssertFunctionClause(misc_4()), ok. @@ -1020,7 +1022,7 @@ and_guard(Config) when is_list(Config) -> ok = relprod({'Set',a,b}, {'Set',a,b}), ok = and_same_var(42), - {'EXIT',{if_clause,_}} = (catch and_same_var(x)), + ?assertError(if_clause, and_same_var(x)), ok. and_same_var(V) -> @@ -1307,10 +1309,8 @@ is_function_2(Config) when is_list(Config) -> true = is_function(id(fun() -> ok end), 0), false = is_function(id(fun ?MODULE:all/1), 0), false = is_function(id(fun() -> ok end), 1), - {'EXIT',{badarg,_}} = - (catch is_function(id(fun() -> ok end), -1) orelse error), - {'EXIT',{badarg,_}} = - (catch is_function(id(fun() -> ok end), '') orelse error), + ?assertError(badarg, is_function(id(fun() -> ok end), -1) orelse error), + ?assertError(badarg, is_function(id(fun() -> ok end), '') orelse error), F = fun(_) -> ok end, if @@ -1359,9 +1359,9 @@ tricky(Config) when is_list(Config) -> error = tricky_3(#{}), error = tricky_3({a,b}), - {'EXIT',_} = (catch tricky_4(x)), - {'EXIT',_} = (catch tricky_4(42)), - {'EXIT',_} = (catch tricky_4(true)), + ?assertError(_, tricky_4(x)), + ?assertError(_, tricky_4(42)), + ?assertError(_, tricky_4(true)), ok. @@ -2328,19 +2328,19 @@ cqlc(M, F, As, St) -> andalso_semi(Config) when is_list(Config) -> ok = andalso_semi_foo(0), ok = andalso_semi_foo(1), - fc(catch andalso_semi_foo(2)), + ?AssertFunctionClause(andalso_semi_foo(2)), ok = andalso_semi_bar([a,b,c]), ok = andalso_semi_bar(1), - fc(catch andalso_semi_bar([a,b])), + ?AssertFunctionClause(andalso_semi_bar([a,b])), ok = andalso_semi_dispatch(name, fun andalso_semi/1), ok = andalso_semi_dispatch(name, fun ?MODULE:andalso_semi/1), ok = andalso_semi_dispatch(name, {?MODULE,andalso_semi,1}), - fc(catch andalso_semi_dispatch(42, fun andalso_semi/1)), - fc(catch andalso_semi_dispatch(name, not_fun)), - fc(catch andalso_semi_dispatch(name, fun andalso_semi_dispatch/2)), - fc(catch andalso_semi_dispatch(42, {a,b})), + ?AssertFunctionClause(andalso_semi_dispatch(42, fun andalso_semi/1)), + ?AssertFunctionClause(andalso_semi_dispatch(name, not_fun)), + ?AssertFunctionClause(andalso_semi_dispatch(name, fun andalso_semi_dispatch/2)), + ?AssertFunctionClause(andalso_semi_dispatch(42, {a,b})), ok. @@ -2357,8 +2357,8 @@ andalso_semi_dispatch(Registry, MFAOrFun) when t_tuple_size(Config) when is_list(Config) -> 10 = do_tuple_size({1,2,3,4}), - fc(catch do_tuple_size({1,2,3})), - fc(catch do_tuple_size(42)), + ?AssertFunctionClause(do_tuple_size({1,2,3})), + ?AssertFunctionClause(do_tuple_size(42)), error = ludicrous_tuple_size({a,b,c}), error = ludicrous_tuple_size([a,b,c]), @@ -2397,11 +2397,15 @@ validate_ip(_) -> %% %% The binary_part/2,3 guard BIFs %% --define(MASK_ERROR(EXPR),mask_error((catch (EXPR)))). -mask_error({'EXIT',{Err,_}}) -> - Err; -mask_error(Else) -> - Else. +-define(MASK_ERROR(EXPR), mask_error(fun() -> EXPR end)). +mask_error(ExprFun) -> + try ExprFun() of + Result -> + Result + catch + error:Error -> + Error + end. %% Test the binary_part/2,3 guard (GC) BIFs. binary_part(Config) when is_list(Config) -> @@ -2563,21 +2567,21 @@ bad_constants(Config) when is_list(Config) -> bad_guards(Config) when is_list(Config) -> if erlang:float(self()); true -> ok end, - fc(catch bad_guards_1(1, [])), - fc(catch bad_guards_1(1, [2])), - fc(catch bad_guards_1(atom, [2])), + ?AssertFunctionClause(bad_guards_1(1, [])), + ?AssertFunctionClause(bad_guards_1(1, [2])), + ?AssertFunctionClause(bad_guards_1(atom, [2])), - fc(catch bad_guards_2(#{a=>0,b=>0}, [])), - fc(catch bad_guards_2(#{a=>0,b=>0}, [x])), - fc(catch bad_guards_2(not_a_map, [x])), - fc(catch bad_guards_2(42, [x])), + ?AssertFunctionClause(bad_guards_2(#{a=>0,b=>0}, [])), + ?AssertFunctionClause(bad_guards_2(#{a=>0,b=>0}, [x])), + ?AssertFunctionClause(bad_guards_2(not_a_map, [x])), + ?AssertFunctionClause(bad_guards_2(42, [x])), - fc(catch bad_guards_3(#{a=>0,b=>0}, [])), - fc(catch bad_guards_3(#{a=>0,b=>0}, [x])), - fc(catch bad_guards_3(not_a_map, [x])), - fc(catch bad_guards_3(42, [x])), + ?AssertFunctionClause(bad_guards_3(#{a=>0,b=>0}, [])), + ?AssertFunctionClause(bad_guards_3(#{a=>0,b=>0}, [x])), + ?AssertFunctionClause(bad_guards_3(not_a_map, [x])), + ?AssertFunctionClause(bad_guards_3(42, [x])), - fc(catch bad_guards_4()), + ?AssertFunctionClause(bad_guards_4()), {0,undefined} = bad_guards_5(id(<<>>), id(undefined)), @@ -2624,7 +2628,7 @@ guard_in_catch(_Config) -> {'EXIT',{if_clause,_}} = do_guard_in_catch_map_2(#{a=>b}), {'EXIT',{if_clause,_}} = do_guard_in_catch_map_2(atom), - {'EXIT',{if_clause,_}} = (catch do_guard_in_catch_map_3()), + ?assertError(if_clause, do_guard_in_catch_map_3()), {'EXIT',{if_clause,_}} = do_guard_in_catch_bin(42), {'EXIT',{if_clause,_}} = do_guard_in_catch_bin(<<1,2,3>>), @@ -2762,9 +2766,9 @@ before_and_inside_if_2(XDo1, XDo2, Do3) -> scotland() -> million = do_scotland(placed), - {'EXIT',{{badmatch,placed},_}} = (catch do_scotland(false)), - {'EXIT',{{badmatch,placed},_}} = (catch do_scotland(true)), - {'EXIT',{{badmatch,placed},_}} = (catch do_scotland(echo)), + ?assertError({badmatch,placed}, do_scotland(false)), + ?assertError({badmatch,placed}, do_scotland(true)), + ?assertError({badmatch,placed}, do_scotland(echo)), ok. do_scotland(Echo) -> @@ -2781,8 +2785,8 @@ found(_, _) -> million. %% ERL-143: beam_bool could not handle Y registers as a destination. y_registers() -> - {'EXIT',{badarith,[_|_]}} = (catch baker(valentine)), - {'EXIT',{badarith,[_|_]}} = (catch baker(clementine)), + ?assertError(badarith, baker(valentine)), + ?assertError(badarith, baker(clementine)), {not_ok,true} = potter([]), {ok,false} = potter([{encoding,any}]), @@ -2809,10 +2813,10 @@ potter(Modes) -> {Final,Raw}. protected() -> - {'EXIT',{if_clause,_}} = (catch photographs({1, surprise, true}, opinions)), + ?assertError(if_clause, photographs({1, surprise, true}, opinions)), {{true}} = welcome({perfect, true}), - {'EXIT',{if_clause,_}} = (catch welcome({perfect, false})), + ?assertError(if_clause, welcome({perfect, false})), ok. photographs({_Violation, surprise, Deep}, opinions) -> @@ -3178,7 +3182,7 @@ gh4788() -> ok = do_gh4788(id(0)), ok = do_gh4788(id(1)), ok = do_gh4788(id(undefined)), - lt_0_or_undefined = catch do_gh4788(id(-1)), + ?assertThrow(lt_0_or_undefined, do_gh4788(id(-1))), ok. do_gh4788(N) -> @@ -3270,7 +3274,7 @@ beam_ssa_bool_coverage_6(_) -> gh_6164() -> true = do_gh_6164(id([])), - {'EXIT',{{case_clause,42},_}} = catch do_gh_6164(id(0)), + ?assertError({case_clause,42}, do_gh_6164(id(0))), ok. @@ -3286,9 +3290,9 @@ do_gh_6164(V1) -> end. gh_6184() -> - {'EXIT',{function_clause,_}} = catch do_gh_6184(id(true), id({a,b,c})), - {'EXIT',{function_clause,_}} = catch do_gh_6184(true, true), - {'EXIT',{function_clause,_}} = catch do_gh_6184({a,b,c}, {x,y,z}), + ?AssertFunctionClause(do_gh_6184(id(true), id({a,b,c}))), + ?AssertFunctionClause(do_gh_6184(true, true)), + ?AssertFunctionClause(do_gh_6184({a,b,c}, {x,y,z})), ok. @@ -3353,10 +3357,10 @@ gh_7370(_) -> b. gh_7517() -> - ok = catch do_gh_7517([]), - ok = catch do_gh_7517([a,b,c]), - {'EXIT',{function_clause,_}} = catch do_gh_7517(ok), - {'EXIT',{function_clause,_}} = catch do_gh_7517(<<>>), + ok = do_gh_7517([]), + ok = do_gh_7517([a,b,c]), + ?AssertFunctionClause(do_gh_7517(ok)), + ?AssertFunctionClause(do_gh_7517(<<>>)), ok. do_gh_7517(A) when (ok /= A) or is_float(is_list(A) orelse ok andalso ok) -> @@ -3519,5 +3523,3 @@ check(F, Result) -> io:format(" Got: ~p\n", [Other]), ct:fail(check_failed) end. - -fc({'EXIT',{function_clause,_}}) -> ok. diff --git a/lib/compiler/test/inline_SUITE.erl b/lib/compiler/test/inline_SUITE.erl index 0f830ca4a72..584291fa5f8 100644 --- a/lib/compiler/test/inline_SUITE.erl +++ b/lib/compiler/test/inline_SUITE.erl @@ -24,6 +24,8 @@ -module(inline_SUITE). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). +-include("test_lib.hrl"). -compile(export_all). -compile({inline,[badarg/2]}). @@ -266,50 +268,70 @@ lists(Config) when is_list(Config) -> %% Cleanup. erase(?MODULE), - {'EXIT',{function_clause,[{?MODULE,_,[_,not_a_list],_}|_]}} = - (catch lists:map(fun (X) -> X end, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,not_a_list],_}|_]}} = - (catch lists:flatmap(fun (X) -> X end, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,not_a_list],_}|_]}} = - (catch lists:foreach(fun (X) -> X end, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,not_a_list],_}|_]}} = - (catch lists:filter(fun (_) -> true end, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,not_a_list],_}|_]}} = - (catch lists:any(fun (_) -> false end, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,not_a_list],_}|_]}} = - (catch lists:all(fun (_) -> true end, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,acc,not_a_list],_}|_]}} = - (catch lists:foldl(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,acc,not_a_list],_}|_]}} = - (catch lists:foldr(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,acc,not_a_list],_}|_]}} = - (catch lists:mapfoldl(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), - {'EXIT',{function_clause,[{?MODULE,_,[_,acc,not_a_list],_}|_]}} = - (catch lists:mapfoldr(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), - - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,[]],_}|_]}} = - (catch lists:map(not_a_function, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,[]],_}|_]}} = - (catch lists:flatmap(not_a_function, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,[]],_}|_]}} = - (catch lists:foreach(not_a_function, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,[]],_}|_]}} = - (catch lists:filter(not_a_function, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,[]],_}|_]}} = - (catch lists:any(not_a_function, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,[]],_}|_]}} = - (catch lists:all(not_a_function, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,acc,[]],_}|_]}} = - (catch lists:foldl(not_a_function, acc, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,acc,[]],_}|_]}} = - (catch lists:foldr(not_a_function, acc, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,acc,[]],_}|_]}} = - (catch lists:mapfoldl(not_a_function, acc, [])), - {'EXIT',{function_clause,[{?MODULE,_,[not_a_function,acc,[]],_}|_]}} = - (catch lists:mapfoldr(not_a_function, acc, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,not_a_list],_}|_], + lists:map(fun (X) -> X end, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,not_a_list],_}|_], + lists:flatmap(fun (X) -> X end, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,not_a_list],_}|_], + lists:foreach(fun (X) -> X end, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,not_a_list],_}|_], + lists:filter(fun (_) -> true end, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,not_a_list],_}|_], + lists:any(fun (_) -> false end, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,not_a_list],_}|_], + lists:all(fun (_) -> true end, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,acc,not_a_list],_}|_], + lists:foldl(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,acc,not_a_list],_}|_], + lists:foldr(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,acc,not_a_list],_}|_], + lists:mapfoldl(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[_,acc,not_a_list],_}|_], + lists:mapfoldr(fun (X, Acc) -> {X,Acc} end, acc, not_a_list)), + + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,[]],_}|_], + lists:map(not_a_function, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,[]],_}|_], + lists:flatmap(not_a_function, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,[]],_}|_], + lists:foreach(not_a_function, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,[]],_}|_], + lists:filter(not_a_function, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,[]],_}|_], + lists:any(not_a_function, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,[]],_}|_], + lists:all(not_a_function, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,acc,[]],_}|_], + lists:foldl(not_a_function, acc, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,acc,[]],_}|_], + lists:foldr(not_a_function, acc, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,acc,[]],_}|_], + lists:mapfoldl(not_a_function, acc, [])), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[not_a_function,acc,[]],_}|_], + lists:mapfoldr(not_a_function, acc, [])), ok. - + my_apply(M, F, A, Init) -> put(?MODULE, Init), Res = apply(M, F, A), @@ -317,8 +339,9 @@ my_apply(M, F, A, Init) -> really_inlined(Config) when is_list(Config) -> %% Make sure that badarg/2 really gets inlined. - {'EXIT',{badarg,[{?MODULE,fail_me_now,[],_}|_]}} = - (catch fail_me_now()), + ?AssertErrorStack(badarg, + [{?MODULE,fail_me_now,[],_}|_], + fail_me_now()), ok. fail_me_now() -> @@ -334,7 +357,9 @@ badarg(Reply, _A) -> Reply. otp_7223(Config) when is_list(Config) -> - {'EXIT', {function_clause, [{?MODULE,_,[1],_}|_]}} = (catch otp_7223_1(1)), + ?AssertErrorStack(function_clause, + [{?MODULE,_,[1],_}|_], + otp_7223_1(1)), ok. -compile({inline,[{otp_7223_1,1}]}). diff --git a/lib/compiler/test/lc_SUITE.erl b/lib/compiler/test/lc_SUITE.erl index dc848cb1a96..e2f4ea4ef68 100644 --- a/lib/compiler/test/lc_SUITE.erl +++ b/lib/compiler/test/lc_SUITE.erl @@ -29,10 +29,11 @@ basic/1,deeply_nested/1,no_generator/1, empty_generator/1,no_export/1,shadow/1, effect/1,singleton_generator/1,assignment_generator/1,gh10020/1, - multi/1]). + multi/1]). -include_lib("stdlib/include/assert.hrl"). -include_lib("common_test/include/ct.hrl"). +-include("test_lib.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -123,42 +124,42 @@ basic(Config) when is_list(Config) -> %% Error cases. [] = [{xx,X} || X <- L0, element(2, X) == no_no_no], - {'EXIT',_} = (catch [X || X <- L1, list_to_atom(X) == dum]), + ?assertError(_, [X || X <- L1, list_to_atom(X) == dum]), [] = [X || X <- L1, X+1 < 2], - {'EXIT',_} = (catch [X || X <- L1, odd(X)]), - {'EXIT',{{bad_generator,x},_}} = (catch [E || E <- id(x)]), - {'EXIT',{{bad_filter,not_bool},_}} = (catch [E || E <- [1,2], id(not_bool)]), + ?assertError(_, [X || X <- L1, odd(X)]), + ?assertError({bad_generator,x}, [E || E <- id(x)]), + ?assertError({bad_filter,not_bool}, [E || E <- [1,2], id(not_bool)]), %% Non-matching elements cause a badmatch error for strict generators - {'EXIT',{{badmatch,2},_}} = (catch [X || {ok, X} <:- [{ok,1},2,{ok,3}]]), - {'EXIT',{{badmatch,<<128,2>>},_}} = (catch [X || <<0:1, X:7>> <:= <<1,128,2>>]), - {'EXIT',{{badmatch,{2,error}},_}} = (catch [X || X := ok <:- #{1 => ok, 2 => error, 3 => ok}]), + ?assertError({badmatch,2}, [X || {ok, X} <:- [{ok,1},2,{ok,3}]]), + ?assertError({badmatch,<<128,2>>}, [X || <<0:1, X:7>> <:= <<1,128,2>>]), + ?assertError({badmatch,{2,error}}, [X || X := ok <:- #{1 => ok, 2 => error, 3 => ok}]), %% Make sure that line numbers point out the generator. case ?MODULE of lc_inline_SUITE -> ok; _ -> - {'EXIT',{{bad_generator,a}, - [{?MODULE,_,_, - [{file,"bad_lc.erl"},{line,4}]}|_]}} = - (catch id(bad_generator(a))), + ?AssertErrorStack({bad_generator,a}, + [{?MODULE,_,_, + [{file,"bad_lc.erl"},{line,4}]}|_], + id(bad_generator(a))), - {'EXIT',{{bad_generator,a}, - [{?MODULE,_,_, - [{file,"bad_lc.erl"},{line,7}]}|_]}} = - (catch id(bad_generator_bc(a))), + ?AssertErrorStack({bad_generator,a}, + [{?MODULE,_,_, + [{file,"bad_lc.erl"},{line,7}]}|_], + id(bad_generator_bc(a))), - {'EXIT',{{bad_generator,a}, - [{?MODULE,_,_, - [{file,"bad_lc.erl"},{line,10}]}|_]}} = - (catch id(bad_generator_mc(a))), + ?AssertErrorStack({bad_generator,a}, + [{?MODULE,_,_, + [{file,"bad_lc.erl"},{line,10}]}|_], + id(bad_generator_mc(a))), %% List comprehensions with improper lists. - {'EXIT',{{bad_generator,d}, - [{?MODULE,_,_, - [{file,"bad_lc.erl"},{line,4}]}|_]}} = - (catch bad_generator(id([a,b,c|d]))) + ?AssertErrorStack({bad_generator,d}, + [{?MODULE,_,_, + [{file,"bad_lc.erl"},{line,4}]}|_], + bad_generator(id([a,b,c|d]))) end, ok. diff --git a/lib/compiler/test/map_SUITE.erl b/lib/compiler/test/map_SUITE.erl index bb760dbecb6..cbc0ef6fcb2 100644 --- a/lib/compiler/test/map_SUITE.erl +++ b/lib/compiler/test/map_SUITE.erl @@ -19,7 +19,10 @@ %% %CopyrightEnd% %% -module(map_SUITE). --export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, +-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 ]). @@ -95,9 +98,14 @@ coverage/1 ]). --define(badmap(V, F, Args), {'EXIT', {{badmap,V}, [{maps,F,Args,_}|_]}}). --define(badkey(K, F, Args), {'EXIT', {{badkey,K}, [{maps,F,Args,_}|_]}}). --define(badarg(F, Args), {'EXIT', {badarg, [{maps,F,Args,_}|_]}}). +-define(BADMAP(V, F, Args, Expr), + ?AssertErrorStack({badmap,V}, [{maps,F,Args,_}|_], Expr)). + +-define(BADKEY(K, F, Args, Expr), + ?AssertErrorStack({badkey,K}, [{maps,F,Args,_}|_], Expr)). + +-define(BADARG(F, Args, Expr), + ?AssertErrorStack(badarg, [{maps,F,Args,_}|_], Expr)). suite() -> []. @@ -223,12 +231,12 @@ t_build_and_match_literals(Config) when is_list(Config) -> #{ <<0:358>> := "three" } = id(#{<<0:358>> =>"three"}), %% error case - {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3,x:=2} = id(#{x=>3}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{x:=2} = id(#{x=>3}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3} = id({a,b,c}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3} = id(#{y=>3}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{x:=3} = id(#{x=>"three"}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{#{"a"=>42} := 3}=id(#{#{"a"=>3}=>42}))), + ?assertError({badmatch,_}, (#{x:=3,x:=2} = id(#{x=>3}))), + ?assertError({badmatch,_}, (#{x:=2} = id(#{x=>3}))), + ?assertError({badmatch,_}, (#{x:=3} = id({a,b,c}))), + ?assertError({badmatch,_}, (#{x:=3} = id(#{y=>3}))), + ?assertError({badmatch,_}, (#{x:=3} = id(#{x=>"three"}))), + ?assertError({badmatch,_}, (#{#{"a"=>42} := 3}=id(#{#{"a"=>3}=>42}))), ok. t_build_and_match_literals_large(Config) when is_list(Config) -> @@ -731,9 +739,9 @@ t_map_size(Config) when is_list(Config) -> false = map_is_size(M#{ "c" => 2}, 2), %% Error cases. - {'EXIT',{{badmap,[]},_}} = (catch map_size([])), - {'EXIT',{{badmap,<<1,2,3>>},_}} = (catch map_size(<<1,2,3>>)), - {'EXIT',{{badmap,1},_}} = (catch map_size(1)), + ?assertError({badmap,[]}, map_size([])), + ?assertError({badmap,<<1,2,3>>}, map_size(<<1,2,3>>)), + ?assertError({badmap,1}, map_size(1)), ok. map_is_size(M,N) when map_size(M) =:= N -> true; @@ -742,8 +750,8 @@ map_is_size(_,_) -> false. t_map_get(Config) when is_list(Config) -> 1 = map_get(a, id(#{a=>1})), - {'EXIT',{{badkey,a},_}} = (catch map_get(a, #{})), - {'EXIT',{{badkey,a},_}} = (catch map_get(a, #{b=>1})), + ?assertError({badkey,a}, map_get(a, #{})), + ?assertError({badkey,a}, map_get(a, #{b=>1})), M = #{"a"=>1, "b" => 2}, true = check_map_value(M, "a", 1), @@ -751,9 +759,9 @@ t_map_get(Config) when is_list(Config) -> true = check_map_value(M#{"c"=>2}, "c", 2), false = check_map_value(M#{"a"=>5}, "a", 1), - {'EXIT',{{badmap,[]},_}} = (catch map_get(a, [])), - {'EXIT',{{badmap,<<1,2,3>>},_}} = (catch map_get(a, <<1,2,3>>)), - {'EXIT',{{badmap,1},_}} = (catch map_get(a, 1)), + ?assertError({badmap,[]}, map_get(a, [])), + ?assertError({badmap,<<1,2,3>>}, map_get(a, <<1,2,3>>)), + ?assertError({badmap,1}, map_get(a, 1)), %% Test that beam_validator understands that NewMap is %% a map after seeing map_get(a, NewMap). @@ -983,10 +991,9 @@ t_update_map_expressions(Config) when is_list(Config) -> #{ "a" := b } = F(), %% Error cases. - {'EXIT',{{badmap,<<>>},_}} = (catch (id(<<>>))#{ a := 42, b => 2 }), - {'EXIT',{{badmap,[]},_}} = (catch (id([]))#{ a := 42, b => 2 }), - {'EXIT',{{badmap,_},_}} = - (catch (fun t_update_map_expressions/1)#{u => 42}), + ?assertError({badmap,<<>>}, (id(<<>>))#{ a := 42, b => 2 }), + ?assertError({badmap,[]}, (id([]))#{ a := 42, b => 2 }), + ?assertError({badmap,_}, (fun t_update_map_expressions/1)#{u => 42}), ok. @@ -1002,19 +1009,19 @@ t_update_assoc(Config) when is_list(Config) -> #{1:=a,2:=b,3.0:=new,4:=d,5:=e} = M2, M2 = M0#{3.0:=wrong,3.0=>new}, - % Can't handle directly yet + %% Can't handle directly yet Bin = <<0:257>>, #{ Bin := val } = id(M0#{<<0:257>> => val}), %% binary limitation %% Errors cases. BadMap = id(badmap), - {'EXIT',{{badmap,BadMap},_}} = (catch BadMap#{nonexisting=>val}), - {'EXIT',{{badmap,<<>>},_}} = (catch <<>>#{nonexisting=>val}), + ?assertError({badmap,BadMap}, BadMap#{nonexisting=>val}), + ?assertError({badmap,<<>>}, <<>>#{nonexisting=>val}), F1 = fun() -> 0 #{part => V = false}, V end, - {'EXIT',{{badmap,0},_}} = (catch F1()), + ?assertError({badmap,0}, F1()), F2 = fun() -> case 42 of V -> @@ -1030,10 +1037,8 @@ t_update_assoc(Config) when is_list(Config) -> 42 = F2(), %% Evaluation order. - {'EXIT',{blurf,_}} = - (catch BadMap#{whatever=>id(error(blurf))}), - {'EXIT',{blurf,_}} = - (catch BadMap#{id(error(blurf))=>whatever}), + ?assertError(blurf, BadMap#{whatever=>id(error(blurf))}), + ?assertError(blurf, BadMap#{id(error(blurf))=>whatever}), ok. t_update_assoc_large(Config) when is_list(Config) -> @@ -1101,7 +1106,7 @@ t_update_assoc_large(Config) when is_list(Config) -> %% Errors cases. BadMap = id({no,map}), - {'EXIT',{{badmap,BadMap},_}} = (catch BadMap#{nonexisting=>M0}), + ?assertError({badmap,BadMap}, BadMap#{nonexisting=>M0}), ok. @@ -1126,29 +1131,25 @@ t_update_exact(Config) when is_list(Config) -> 1.0 => new_val4 }, %% Errors cases. - {'EXIT',{{badmap,nil},_}} = (catch ((id(nil))#{ a := b })), - {'EXIT',{{badkey,nonexisting},_}} = (catch M0#{nonexisting:=val}), - {'EXIT',{{badkey,1.0},_}} = (catch M0#{1.0:=v,1.0=>v2}), - {'EXIT',{{badkey,42},_}} = (catch M0#{42.0:=v,42:=v2}), - {'EXIT',{{badkey,42.0},_}} = (catch M0#{42=>v1,42.0:=v2,42:=v3}), - {'EXIT',{{badmap,<<>>},_}} = (catch <<>>#{nonexisting:=val}), - {'EXIT',{{badkey,<<0:257>>},_}} = - (catch M0#{<<0:257>> := val}), %limitation + ?assertError({badmap,nil}, ((id(nil))#{ a := b })), + ?assertError({badkey,nonexisting}, M0#{nonexisting:=val}), + ?assertError({badkey,1.0}, M0#{1.0:=v,1.0=>v2}), + ?assertError({badkey,42}, M0#{42.0:=v,42:=v2}), + ?assertError({badkey,42.0}, M0#{42=>v1,42.0:=v2,42:=v3}), + ?assertError({badmap,<<>>}, <<>>#{nonexisting:=val}), + ?assertError({badkey,<<0:257>>}, M0#{<<0:257>> := val}), %limitation %% A workaround for a bug allowed an empty map to be updated. - {'EXIT',{{badkey,a},_}} = (catch (id(#{}))#{a:=1}), - {'EXIT',{{badkey,a},_}} = (catch #{}#{a:=1}), + ?assertError({badkey,a}, (id(#{}))#{a:=1}), + ?assertError({badkey,a}, #{}#{a:=1}), Empty = #{}, - {'EXIT',{{badkey,a},_}} = (catch Empty#{a:=1}), + ?assertError({badkey,a}, Empty#{a:=1}), %% Evaluation order. BadMap = id([no,map]), - {'EXIT',{blurf,_}} = - (catch BadMap#{whatever:=id(error(blurf))}), - {'EXIT',{blurf,_}} = - (catch BadMap#{id(error(blurf)):=whatever}), - {'EXIT',{{badmap,BadMap},_}} = - (catch BadMap#{id(nonexisting):=whatever}), + ?assertError(blurf, BadMap#{whatever:=id(error(blurf))}), + ?assertError(blurf, BadMap#{id(error(blurf)):=whatever}), + ?assertError({badmap,BadMap}, BadMap#{id(nonexisting):=whatever}), ok. t_update_exact_large(Config) when is_list(Config) -> @@ -1226,10 +1227,10 @@ t_update_exact_large(Config) when is_list(Config) -> M2 = M0#{13.0=>wrong,13.0:=new}, %% Errors cases. - {'EXIT',{{badkey,nonexisting},_}} = (catch M0#{nonexisting:=val}), - {'EXIT',{{badkey,1.0},_}} = (catch M0#{1.0:=v,1.0=>v2}), - {'EXIT',{{badkey,42},_}} = (catch M0#{42.0:=v,42:=v2}), - {'EXIT',{{badkey,42.0},_}} = (catch M0#{42=>v1,42.0:=v2,42:=v3}), + ?assertError({badkey,nonexisting}, M0#{nonexisting:=val}), + ?assertError({badkey,1.0}, M0#{1.0:=v,1.0=>v2}), + ?assertError({badkey,42}, M0#{42.0:=v,42:=v2}), + ?assertError({badkey,42.0}, M0#{42=>v1,42.0:=v2,42:=v3}), ok. @@ -1310,20 +1311,17 @@ t_guard_bifs(Config) when is_list(Config) -> %% The guard BIFs used in a body. v = map_get(a, id(#{a=>v})), - {'EXIT',{{badkey,a},_}} = - (catch map_get(a, id(#{}))), - {'EXIT',{{badmap,not_a_map},_}} = - (catch map_get(a, id(not_a_map))), + ?assertError({badkey,a}, map_get(a, id(#{}))), + ?assertError({badmap,not_a_map}, map_get(a, id(not_a_map))), true = is_map_key(a, id(#{a=>1})), false = is_map_key(b, id(#{a=>1})), false = is_map_key(b, id(#{})), - {'EXIT',{{badmap,not_a_map},_}} = - (catch is_map_key(b, id(not_a_map))), + ?assertError({badmap,not_a_map}, is_map_key(b, id(not_a_map))), {true,v} = erl_699(#{k=>v}), - {'EXIT',{{badkey,k},_}} = (catch erl_699(#{})), - {'EXIT',{{badmap,not_a_map},_}} = (catch erl_699(not_a_map)), + ?assertError({badkey,k}, erl_699(#{})), + ?assertError({badmap,not_a_map}, erl_699(not_a_map)), %% Cover optimizations in beam_dead. @@ -1462,8 +1460,8 @@ t_guard_sequence(Config) when is_list(Config) -> {5,kk,kk,M5} = map_guard_sequence_2(M5 = id(#{a=>kk, b=>other, c=>sc2})), %% error case - {'EXIT',{function_clause,_}} = (catch map_guard_sequence_1(#{seq=>6,val=>id("e")})), - {'EXIT',{function_clause,_}} = (catch map_guard_sequence_2(#{b=>5})), + ?assertError(function_clause, map_guard_sequence_1(#{seq=>6,val=>id("e")})), + ?assertError(function_clause, map_guard_sequence_2(#{b=>5})), ok. t_guard_sequence_large(Config) when is_list(Config) -> @@ -1531,8 +1529,8 @@ t_guard_sequence_large(Config) when is_list(Config) -> {4,sc,sc,M4} = map_guard_sequence_2(M4 = id(M0#{a=>sc, b=>3, c=>sc2})), {5,kk,kk,M5} = map_guard_sequence_2(M5 = id(M0#{a=>kk, b=>other, c=>sc2})), - {'EXIT',{function_clause,_}} = (catch map_guard_sequence_1(M0#{seq=>6,val=>id("e")})), - {'EXIT',{function_clause,_}} = (catch map_guard_sequence_2(M0#{b=>5})), + ?assertError(function_clause, map_guard_sequence_1(M0#{seq=>6,val=>id("e")})), + ?assertError(function_clause, map_guard_sequence_2(M0#{b=>5})), ok. map_guard_sequence_1(#{seq:=1=Seq, val:=Val}) -> {Seq,Val}; @@ -1634,7 +1632,7 @@ do_bad_map_guard_update_1(Fun, Value) -> %% Note: The business with the seemingly redundant fun %% disables inlining, which would otherwise change the %% EXIT reason. - {'EXIT',{function_clause,_}} = (catch Fun(Value)), + ?assertError(function_clause, Fun(Value)), ok. burns(Richmond) when not (Richmond#{true := 0}); [Richmond] -> @@ -1768,16 +1766,19 @@ t_guard_fun(Config) when is_list(Config) -> {l,V} = F2(#{s=>l,v=>[V,V]}), %% error case - case (catch F1(#{s=>none,v=>none})) of - {'EXIT', {function_clause,[{?MODULE,_,[#{s:=none,v:=none}],_}|_]}} -> ok; - {'EXIT', {{case_clause,_},_}} -> {comment,inlined}; - Other -> - ct:fail({no_match, Other}) + try F1(#{s=>none,v=>none}) of + Result -> + ct:fail({unexpected_success, Result}) + catch + error:function_clause:Stack -> + [{?MODULE,_,[#{s:=none,v:=none}],_}|_] = Stack; + error:{case_clause,_} -> + {comment,inlined} end. t_map_sort_literals(Config) when is_list(Config) -> - % test relation + %% test relation %% size order true = #{ a => 1, b => 2} < id(#{ a => 1, b => 1, c => 1}), @@ -1853,11 +1854,12 @@ t_build_and_match_empty_val(Config) when is_list(Config) -> ok = F(id(#{"hi"=>ok,{1,2}=>ok,1337=>ok})), %% error case - case (catch (F(id(#{"hi"=>ok})))) of - {'EXIT',{function_clause,_}} -> ok; - {'EXIT', {{case_clause,_},_}} -> {comment,inlined}; - Other -> - ct:fail({no_match, Other}) + try F(id(#{"hi"=>ok})) of + Result -> + ct:fail({unexpected_success, Result}) + catch + error:function_clause -> ok; + error:{case_clause,_} -> ok end. t_build_and_match_val(Config) when is_list(Config) -> @@ -1871,11 +1873,12 @@ t_build_and_match_val(Config) when is_list(Config) -> {2,"second"} = F(id(#{"hi"=>second,v=>"second"})), %% error case - case (catch (F(id(#{"hi"=>ok})))) of - {'EXIT',{function_clause,_}} -> ok; - {'EXIT', {{case_clause,_},_}} -> {comment,inlined}; - Other -> - ct:fail({no_match, Other}) + try F(id(#{"hi"=>ok})) of + Result -> + ct:fail({unexpected_success, Result}) + catch + error:function_clause -> ok; + error:{case_clause,_} -> {comment,inlined} end. t_build_and_match_nil(Config) when is_list(Config) -> @@ -1950,12 +1953,12 @@ t_build_and_match_variables(Config) when is_list(Config) -> #{ Bin := "three" } = id(#{<<0:258>> =>"three"}), %% error case - {'EXIT',{{badmatch,_},_}} = (catch (#{K5:=3,x:=2} = id(#{K5=>3}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{K5:=2} = id(#{K5=>3}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{K5:=3} = id({a,b,c}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{K5:=3} = id(#{K6=>3}))), - {'EXIT',{{badmatch,_},_}} = (catch (#{K5:=3} = id(K7))), - {'EXIT',{{badmatch,_},_}} = (catch (#{K7:=3} = id(#{K7=>42}))), + ?assertError({badmatch,_}, (#{K5:=3,x:=2} = id(#{K5=>3}))), + ?assertError({badmatch,_}, (#{K5:=2} = id(#{K5=>3}))), + ?assertError({badmatch,_}, (#{K5:=3} = id({a,b,c}))), + ?assertError({badmatch,_}, (#{K5:=3} = id(#{K6=>3}))), + ?assertError({badmatch,_}, (#{K5:=3} = id(K7))), + ?assertError({badmatch,_}, (#{K7:=3} = id(#{K7=>42}))), ok. @@ -1983,8 +1986,8 @@ t_update_assoc_variables(Config) when is_list(Config) -> %% Errors cases. BadMap = id(badmap), - {'EXIT',{{badmap,BadMap},_}} = (catch BadMap#{nonexisting=>val}), - {'EXIT',{{badmap,<<>>},_}} = (catch <<>>#{nonexisting=>val}), + ?assertError({badmap,BadMap}, BadMap#{nonexisting=>val}), + ?assertError({badmap,<<>>}, <<>>#{nonexisting=>val}), ok. t_update_exact_variables(Config) when is_list(Config) -> @@ -2014,14 +2017,13 @@ t_update_exact_variables(Config) when is_list(Config) -> #{ "wat" := 3, 2 := a } = id(#{ "wat" => 1, K2 => 2 }#{ K2 := a, "wat" := 3 }), %% Errors cases. - {'EXIT',{{badmap,nil},_}} = (catch ((id(nil))#{ a := b })), - {'EXIT',{{badkey,nonexisting},_}} = (catch M0#{nonexisting:=val}), - {'EXIT',{{badkey,1.0},_}} = (catch M0#{1.0:=v,1.0=>v2}), - {'EXIT',{{badkey,42},_}} = (catch M0#{42.0:=v,42:=v2}), - {'EXIT',{{badkey,42.0},_}} = (catch M0#{42=>v1,42.0:=v2,42:=v3}), - {'EXIT',{{badmap,<<>>},_}} = (catch <<>>#{nonexisting:=val}), - {'EXIT',{{badkey,<<0:257>>},_}} = - (catch M0#{<<0:257>> := val}), %limitation + ?assertError({badmap,nil}, ((id(nil))#{ a := b })), + ?assertError({badkey,nonexisting}, M0#{nonexisting:=val}), + ?assertError({badkey,1.0}, M0#{1.0:=v,1.0=>v2}), + ?assertError({badkey,42}, M0#{42.0:=v,42:=v2}), + ?assertError({badkey,42.0}, M0#{42=>v1,42.0:=v2,42:=v3}), + ?assertError({badmap,<<>>}, <<>>#{nonexisting:=val}), + ?assertError({badkey,<<0:257>>}, M0#{<<0:257>> := val}), %limitation ok. t_nested_pattern_expressions(Config) when is_list(Config) -> @@ -2095,7 +2097,7 @@ t_guard_sequence_variables(Config) when is_list(Config) -> {5,"d"} = map_guard_sequence_var_1(b,#{seq=>5,b=>id("d"),a=>y}), %% error case - {'EXIT',{{case_clause,_},_}} = (catch map_guard_sequence_var_1("a",#{seq=>4,val=>id("e")})), + ?assertError({case_clause,_}, map_guard_sequence_var_1("a",#{seq=>4,val=>id("e")})), ok. @@ -2127,7 +2129,7 @@ t_guard_sequence_mixed(Config) when is_list(Config) -> 6 = map_guard_sequence_mixed(a,f,M6), %% error case - {'EXIT',{{case_clause,_},_}} = (catch map_guard_sequence_mixed(a,b,M0)), + ?assertError({case_clause,_}, map_guard_sequence_mixed(a,b,M0)), ok. map_guard_sequence_mixed(K1,K2,M) -> @@ -2230,14 +2232,14 @@ validate_frequency([], _) -> ok. t_bad_update(_Config) -> {#{0.0:=Id},#{}} = properly(#{}), 42 = Id(42), - {'EXIT',{{badmap,_},_}} = (catch increase(0)), + ?assertError({badmap,_}, increase(0)), ok. properly(Item) -> {Item#{0.0 => fun id/1},Item}. increase(Allows) -> - catch fun() -> Allows end#{[] => +Allows, "warranty" => fun id/1}. + fun() -> Allows end#{[] => +Allows, "warranty" => fun id/1}. t_reused_key_variable(Config) when is_list(Config) -> Key = id(key), @@ -2283,7 +2285,7 @@ t_key_expressions(_Config) -> F1 = fun(#{Int + 1 := Val}) -> Val end, val = F1(#{43 => val}), - {'EXIT',_} = (catch F1(a)), + ?assertError(_, F1(a)), F2 = fun(M, X, Y) -> case M of @@ -2356,7 +2358,7 @@ t_key_expressions(_Config) -> Other end) end, - {'EXIT',{badarg,_}} = (catch F7(whatever)), + ?assertError(badarg, F7(whatever)), ok. @@ -2392,8 +2394,8 @@ t_fold_3(_Config) -> true = Tot0 =:= Tot2, %% error case - ?badmap(a, fold, [_,0,a]) = catch maps:fold(fun(_,_,_) -> ok end, 0, id(a)), - ?badarg(fold, [<<>>,0,#{}]) = catch maps:fold(id(<<>>),0,#{}), + ?BADMAP(a, fold, [_,0,a], maps:fold(fun(_,_,_) -> ok end, 0, id(a))), + ?BADARG(fold, [<<>>,0,#{}], maps:fold(id(<<>>), 0, #{})), ok. t_from_keys(_Config) -> @@ -2408,8 +2410,8 @@ t_from_keys(_Config) -> Map2 = maps:from_keys([], value), 0 = map_size(Map2), - ?badarg(from_keys, [[a|b],value]) = catch maps:from_keys([a|b], value), - ?badarg(from_keys, [not_list,value]) = catch maps:from_keys(not_list, value), + ?BADARG(from_keys, [[a|b],value], maps:from_keys([a|b], value)), + ?BADARG(from_keys, [not_list,value], maps:from_keys(not_list, value)), ok. t_map_2(_Config) -> @@ -2422,8 +2424,8 @@ t_map_2(_Config) -> #{ {k,1} := 43, {k,200} := 242} = M2, %% error case - ?badmap(a, map, [_,a]) = catch maps:map(fun(_,_) -> ok end, id(a)), - ?badarg(map, [<<>>,#{}]) = catch maps:map(id(<<>>), #{}), + ?BADMAP(a, map, [_,a], maps:map(fun(_,_) -> ok end, id(a))), + ?BADARG(map, [<<>>,#{}], maps:map(id(<<>>), #{})), ok. t_maps_take_2(_Config) -> @@ -2433,7 +2435,7 @@ t_maps_take_2(_Config) -> error = maps:take(a, #{b => no}), NotMap = not_map(b), - {'EXIT',{{badmap,b},_}} = catch maps:take(a, b), + ?assertError({badmap,b}, maps:take(a, b)), ok. @@ -2451,9 +2453,9 @@ t_update_with_3(Config) when is_list(Config) -> #{ "key3" := [V3,V3,{V3,V3}] } = maps:update_with("key3", Fun, Map), %% error case - ?badmap(b, update_with, [[a,b],a,b]) = catch maps:update_with([a,b], id(a), b), - ?badarg(update_with, [[a,b],a,#{}]) = catch maps:update_with([a,b], id(a), #{}), - ?badkey([a,b], update_with, [[a,b],Fun,#{}]) = catch maps:update_with([a,b], Fun,#{}), + ?BADMAP(b, update_with, [[a,b],a,b], maps:update_with([a,b], id(a), b)), + ?BADARG(update_with, [[a,b],a,#{}], maps:update_with([a,b], id(a), #{})), + ?BADKEY([a,b], update_with, [[a,b],Fun,#{}], maps:update_with([a,b], Fun, #{})), ok. t_update_with_4(Config) when is_list(Config) -> @@ -2471,8 +2473,8 @@ t_update_with_4(Config) when is_list(Config) -> #{ key3 := Init } = maps:update_with(key3, Fun, Init, Map), %% error case - ?badmap(b, update_with, [[a,b],a,b]) = catch maps:update_with([a,b],id(a), b), - ?badarg(update_with, [[a,b],a,#{}]) = catch maps:update_with([a,b], id(a), #{}), + ?BADMAP(b, update_with, [[a,b],a,b], maps:update_with([a,b],id(a), b)), + ?BADARG(update_with, [[a,b],a,#{}], maps:update_with([a,b], id(a), #{})), ok. t_with_2(_Config) -> @@ -2482,11 +2484,13 @@ t_with_2(_Config) -> M1 = maps:with([{k,I} || I <- Ki], M0), %% error case - ?badmap(a, with, [[a,b],a]) = catch maps:with([a,b], id(a)), - ?badmap(a, with, [{a,b},a]) = catch maps:with({a,b}, id(a)), - ?badmap({0,<<>>,97}, with, [[],{0,<<>>,97}]) = catch maps:with([], {0,<<>>,97}), - ?badmap({0,<<>>,97}, with, [[false, -20, -8],{0,<<>>,97}]) = catch maps:with([false, -20, -8], {0, <<>>, 97}), - ?badarg(with, [a,#{}]) = catch maps:with(a,#{}), + ?BADMAP(a, with, [[a,b],a], maps:with([a,b], id(a))), + ?BADMAP(a, with, [{a,b},a], maps:with({a,b}, id(a))), + ?BADMAP({0,<<>>,97}, with, [[],{0,<<>>,97}], + maps:with([], {0,<<>>,97})), + ?BADMAP({0,<<>>,97}, with, [[false, -20, -8],{0,<<>>,97}], + maps:with([false, -20, -8], {0, <<>>, 97})), + ?BADARG(with, [a,#{}], maps:with(a,#{})), ok. t_bif_map_find(Config) when is_list(Config) -> @@ -2510,20 +2514,18 @@ t_bif_map_find(Config) when is_list(Config) -> error = maps:find({1.0,1}, #{ a=>a, {1,1.0} => "tuple hi"}), % reverse types in tuple key do_badmap(fun(T) -> - {'EXIT',{{badmap,T},[{maps,find,_,_}|_]}} = - catch maps:find(a, T) + ?AssertErrorStack({badmap,T}, + [{maps,find,_,_}|_], + maps:find(a, T)) end), ok. t_conflicting_destinations(_Config) -> - {'EXIT',{function_clause,_}} = - catch do_conflicts(#{{tag,whatever} => true}), - {'EXIT',{function_clause,_}} = - catch do_conflicts(#{[something] => 42}), - {'EXIT',{function_clause,_}} = - catch do_conflicts(#{{tag,whatever} => true, - #{} => <<0>>, - [something] => 42}), + ?assertError(function_clause, do_conflicts(#{{tag,whatever} => true})), + ?assertError(function_clause, do_conflicts(#{[something] => 42})), + ?assertError(function_clause, do_conflicts(#{{tag,whatever} => true, + #{} => <<0>>, + [something] => 42})), ok. do_conflicts(#{{tag,whatever} := true, @@ -2532,9 +2534,9 @@ do_conflicts(#{{tag,whatever} := true, ok. t_cse_assoc(_Config) -> - {'EXIT',{{case_clause,#{key:=any}},_}} = catch do_cse_assoc(id(any)), + ?assertError({case_clause,#{key:=any}}, do_cse_assoc(id(any))), - {'EXIT',{{case_clause,#{key:=value}},_}} = catch do_cse_assoc(id(#{}), id(value)), + ?assertError({case_clause,#{key:=value}}, do_cse_assoc(id(#{}), id(value))), 42 = do_cse_assoc(id(#{assoc => 42}), id(any)), ok. @@ -2603,14 +2605,14 @@ map_aliases(_Config) -> F6 = fun(E) -> #{Y := _} = (Y = ((_ = X) = E)) end, - {'EXIT',{{badmatch,0},_}} = catch F6(id(0)), - {'EXIT',{{badmatch,#{}},_}} = catch F6(id(#{})), - {'EXIT',{{badmatch,#{key := value}},_}} = catch F6(id(#{key => value})), + ?assertError({badmatch,0}, F6(id(0))), + ?assertError({badmatch,#{}}, F6(id(#{}))), + ?assertError({badmatch,#{key := value}}, F6(id(#{key => value}))), ok. coverage(_Config) -> - {'EXIT',{{badmatch,ok},_}} = catch coverage_1(), + ?assertError({badmatch,ok}, coverage_1()), ok. diff --git a/lib/compiler/test/match_SUITE.erl b/lib/compiler/test/match_SUITE.erl index 43b463b232e..8cfa58cdad7 100644 --- a/lib/compiler/test/match_SUITE.erl +++ b/lib/compiler/test/match_SUITE.erl @@ -21,6 +21,9 @@ %% -module(match_SUITE). +%% The main point of this test suite is testing aliased patterns. +-compile([nowarn_match_alias_pats]). + -export([all/0, suite/0,groups/0,init_per_suite/1, end_per_suite/1, init_per_group/2,end_per_group/2, pmatch/1,mixed/1,aliases/1,non_matching_aliases/1, @@ -31,8 +34,9 @@ tuple_size_in_try/1,match_boolean_list/1, heisen_variables/1, mutable_variables/1]). - + -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -171,24 +175,24 @@ aliases(Config) when is_list(Config) -> {a,b} = list_alias(id([a,b])), %% Multiple matches. - {'EXIT',{{badmatch,home},_}} = - (catch fun() -> - Rec = (42 = V) = home, - {Rec,V} - end()), + ?assertError({badmatch,home}, + fun() -> + Rec = (42 = V) = home, + {Rec,V} + end()), {home,home} = fun() -> Rec = (home = V) = home, {Rec,V} end(), - {'EXIT',{{badmatch,16},_}} = - (catch fun(B) -> - <<42:V>> = V = B - end(16)), - {'EXIT',{{badmatch,0},_}} = - (catch fun() -> - <<2:V>> = V = 0 - end()), + ?assertError({badmatch,16}, + fun(B) -> + <<42:V>> = V = B + end(16)), + ?assertError({badmatch,0}, + fun() -> + <<2:V>> = V = 0 + end()), {42,42} = fun(E) -> Rec = (42 = V) = id(E), @@ -387,31 +391,31 @@ non_matching_aliases(_Config) -> none = mixed_aliases(<<6789:16>>), none = mixed_aliases(#{key=>value}), - {'EXIT',{{badmatch,bar},_}} = (catch plus_plus_prefix()), - {'EXIT',{{badmatch,42},_}} = (catch nomatch_alias(42)), - {'EXIT',{{badmatch,job},_}} = (catch entirely()), - {'EXIT',{{badmatch,associates},_}} = (catch printer()), - {'EXIT',{{badmatch,borogoves},_}} = (catch tench()), + ?assertError({badmatch,bar}, plus_plus_prefix()), + ?assertError({badmatch,42}, nomatch_alias(42)), + ?assertError({badmatch,job}, entirely()), + ?assertError({badmatch,associates}, printer()), + ?assertError({badmatch,borogoves}, tench()), put(perch, 0), - {'EXIT',{{badmatch,{spine,42}},_}} = (catch perch(42)), + ?assertError({badmatch,{spine,42}}, perch(42)), 1 = erase(perch), put(salmon, 0), - {'EXIT',{{badmatch,mimsy},_}} = (catch salmon()), + ?assertError({badmatch,mimsy}, salmon()), 1 = erase(salmon), put(shark, 0), - {'EXIT',{{badmatch,_},_}} = (catch shark()), + ?assertError({badmatch,_}, shark()), 1 = erase(shark), - {'EXIT',{{badmatch,_},_}} = (catch radio(research)), + ?assertError({badmatch,_}, radio(research)), - {'EXIT',{{case_clause,whatever},_}} = (catch pike1(whatever)), - {'EXIT',{{case_clause,whatever},_}} = (catch pike2(whatever)), + ?assertError({case_clause,whatever}, pike1(whatever)), + ?assertError({case_clause,whatever}, pike2(whatever)), - {'EXIT',{badarith,_}} = catch squid(a), - {'EXIT',{{badmatch,43},_}} = catch squid(42), + ?assertError(badarith, squid(a)), + ?assertError({badmatch,43}, squid(42)), ok. @@ -510,7 +514,7 @@ match_in_call(Config) when is_list(Config) -> mac_e({gurka,42}), [{2,2},{2,2}] = mac_lc([{2,any},{2,2}]), - {'EXIT',_} = (catch mac_lc([{1,1}])), + ?assertError(_, mac_lc([{1,1}])), ok. @@ -596,8 +600,8 @@ shortcut_boolean(Config) when is_list(Config) -> false = shortcut_boolean_1([0]), true = shortcut_boolean_1({42}), 'maybe' = shortcut_boolean_1(self()), - {'EXIT',_} = (catch shortcut_boolean_1([a,b])), - {'EXIT',_} = (catch shortcut_boolean_1({a,b})), + ?assertError(_, shortcut_boolean_1([a,b])), + ?assertError(_, shortcut_boolean_1({a,b})), ok. shortcut_boolean_1(X) -> @@ -637,7 +641,7 @@ selectify(Config) when is_list(Config) -> atom = sel_different_types({r,forty_two}), float = sel_different_types({r,100.0}), none = sel_different_types({r,18}), - {'EXIT',_} = (catch sel_different_types([a,b,c])), + ?assertError(_, sel_different_types([a,b,c])), integer = sel_same_value({r,42}), error = sel_same_value({r,100}), @@ -806,7 +810,7 @@ match_map(Config) when is_list(Config) -> Map = #{key=>{x,y},ignore=>anything}, #s{map=Map,t={x,y}} = do_match_map(#s{map=Map}), {a,#{k:={a,b,c}}} = do_match_map_2(#{k=>{a,b,c}}), - {'EXIT',{{badmatch,whatever},_}} = catch do_match_map_none(id(whatever)), + ?assertError({badmatch,whatever}, do_match_map_none(id(whatever))), ok. do_match_map(#s{map=#{key:=Val}}=S) -> @@ -865,7 +869,7 @@ coverage(Config) when is_list(Config) -> a = coverage_7(x, x, id(true)), b = coverage_7(x, 0, id(false)), - {'EXIT',{{badmatch,{42}},_}} = catch coverage_8(id(42)), + ?assertError({badmatch,{42}}, coverage_8(id(42))), error = coverage_9(id(1)), true = coverage_9(id(0)), @@ -944,7 +948,7 @@ grab_bag(_Config) -> T1 = fun() -> [_|_] = x end, - {'EXIT',_} = (catch T1()), + ?assertError(_, T1()), T2 = fun(A, B) -> case {{element(1, A),element(2, B)}, @@ -1162,8 +1166,8 @@ match_boolean_list(Config) when is_list(Config) -> heisen_variables(_Config) -> - {'EXIT',{{badmatch,3},_}} = catch gh_6516_scope1(), - {'EXIT',{{badmatch,3},_}} = catch gh_6516_scope2(), + ?assertError({badmatch,3}, gh_6516_scope1()), + ?assertError({badmatch,3}, gh_6516_scope2()), ok. @@ -1175,11 +1179,11 @@ gh_6516_scope2() -> %% GH-6873. Bound variables would be overwritten. mutable_variables(_Config) -> - {'EXIT',{{badmatch,0},_}} = catch mutable_variables_1(), + ?assertError({badmatch,0}, mutable_variables_1()), F = fun() -> id({tag,whatever}) end, whatever = mutable_variables_2(id({tag,whatever}), F), - {'EXIT',{{badmatch,{tag,whatever}},_}} = catch mutable_variables_2(id(a), F), + ?assertError({badmatch,{tag,whatever}}, mutable_variables_2(id(a), F)), ok. diff --git a/lib/compiler/test/maybe_SUITE.erl b/lib/compiler/test/maybe_SUITE.erl index ea0b959aa95..46a65171ef5 100644 --- a/lib/compiler/test/maybe_SUITE.erl +++ b/lib/compiler/test/maybe_SUITE.erl @@ -21,6 +21,8 @@ %% -module(maybe_SUITE). +-include_lib("stdlib/include/assert.hrl"). + -export([all/0, groups/0, init_per_suite/1, end_per_suite/1]). -export([basic/1, nested/1]). @@ -47,7 +49,7 @@ basic(_Config) -> error = basic_1(0, #{0 => error}), error = basic_1(0, #{0 => {error,whatever}}), some_value = basic_1(0, #{0 => #value{v=some_value}}), - {'EXIT',{{else_clause,something_wrong},[_|_]}} = catch basic_1(0, #{0 => something_wrong}), + ?assertError({else_clause,something_wrong}, basic_1(0, #{0 => something_wrong})), {ok,life,"universe",everything} = basic_2(0, #{0 => {ok,life}, life => "universe", @@ -55,12 +57,12 @@ basic(_Config) -> error = basic_2(0, #{0 => {ok,life}, life => "universe", "universe" => error}), - {'EXIT',{{badmatch,not_a_list},[_|_]}} = catch basic_2(0, #{0 => {ok,life}, - life => not_a_list}), - {'EXIT',{{else_clause,not_ok},[_|_]}} = catch basic_2(0, #{0 => {ok,life}, - life => "universe", - "universe" => not_ok}), - {'EXIT',{{else_clause,not_ok},[_|_]}} = catch basic_2(0, #{0 => not_ok}), + ?assertError({badmatch,not_a_list}, basic_2(0, #{0 => {ok,life}, + life => not_a_list})), + ?assertError({else_clause,not_ok}, basic_2(0, #{0 => {ok,life}, + life => "universe", + "universe" => not_ok})), + ?assertError({else_clause,not_ok}, basic_2(0, #{0 => not_ok})), {ok,42,fish,dolphins} = basic_3(0, #{0 => {ok,42}, 42 => {ok,fish}, fish => {ok,#value{v=dolphins}}}), diff --git a/lib/compiler/test/mc_SUITE.erl b/lib/compiler/test/mc_SUITE.erl index e86d01c8f73..a021fef8a78 100644 --- a/lib/compiler/test/mc_SUITE.erl +++ b/lib/compiler/test/mc_SUITE.erl @@ -30,6 +30,8 @@ shadow/1,bad_generators/1,multi/1,from_keys_optimization/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). +-include("test_lib.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -137,9 +139,9 @@ basic(_Config) -> #{4 := 8} = #{X+1 => Y*2 || X := Y <:- #{1 => 2, 3 => 4}, X > 1}, %% Non-matching elements cause a badmatch error for strict generators - {'EXIT',{{badmatch,2},_}} = (catch #{X => X+1 || {ok, X} <:- [{ok,1},2,{ok,3}]}), - {'EXIT',{{badmatch,<<128,2>>},_}} = (catch #{X => X+1 || <<0:1, X:7>> <:= <<1,128,2>>}), - {'EXIT',{{badmatch,{2,error}},_}} = (catch #{X => X+1 || X := ok <:-#{1 => ok, 2 => error, 3 => ok}}), + ?assertError({badmatch,2}, #{X => X+1 || {ok, X} <:- [{ok,1},2,{ok,3}]}), + ?assertError({badmatch,<<128,2>>}, #{X => X+1 || <<0:1, X:7>> <:= <<1,128,2>>}), + ?assertError({badmatch,{2,error}}, #{X => X+1 || X := ok <:-#{1 => ok, 2 => error, 3 => ok}}), ok. @@ -268,37 +270,37 @@ bad_generators(_Config) -> mc_inline_SUITE -> ok; _ -> - {'EXIT',{{bad_generator,a}, - [{?MODULE,_,_, - [{file,"bad_mc.erl"},{line,4}]}|_]}} = - catch id(bad_generator(a)), + ?AssertErrorStack({bad_generator,a}, + [{?MODULE,_,_, + [{file,"bad_mc.erl"},{line,4}]}|_], + id(bad_generator(a))), - {'EXIT',{{bad_generator,a}, - [{?MODULE,_,_, - [{file,"bad_mc.erl"},{line,7}]}|_]}} = - catch id(bad_generator_bc(a)), + ?AssertErrorStack({bad_generator,a}, + [{?MODULE,_,_, + [{file,"bad_mc.erl"},{line,7}]}|_], + id(bad_generator_bc(a))), - {'EXIT',{{bad_generator,a}, - [{?MODULE,_,_, - [{file,"bad_mc.erl"},{line,10}]}|_]}} = - catch id(bad_generator_mc(a)), + ?AssertErrorStack({bad_generator,a}, + [{?MODULE,_,_, + [{file,"bad_mc.erl"},{line,10}]}|_], + id(bad_generator_mc(a))), BadIterator = [16#ffff|#{}], - {'EXIT',{{bad_generator,BadIterator}, - [{?MODULE,_,_, - [{file,"bad_mc.erl"},{line,4}]}|_]}} = - catch id(bad_generator(BadIterator)), + ?AssertErrorStack({bad_generator,BadIterator}, + [{?MODULE,_,_, + [{file,"bad_mc.erl"},{line,4}]}|_], + id(bad_generator(BadIterator))), - {'EXIT',{{bad_generator,BadIterator}, - [{?MODULE,_,_, - [{file,"bad_mc.erl"},{line,7}]}|_]}} = - catch id(bad_generator_bc(BadIterator)), + ?AssertErrorStack({bad_generator,BadIterator}, + [{?MODULE,_,_, + [{file,"bad_mc.erl"},{line,7}]}|_], + id(bad_generator_bc(BadIterator))), - {'EXIT',{{bad_generator,BadIterator}, + ?AssertErrorStack({bad_generator,BadIterator}, [{?MODULE,_,_, - [{file,"bad_mc.erl"},{line,10}]}|_]}} = - catch id(bad_generator_mc(BadIterator)) + [{file,"bad_mc.erl"},{line,10}]}|_], + id(bad_generator_mc(BadIterator))) end, ok. diff --git a/lib/compiler/test/receive_SUITE.erl b/lib/compiler/test/receive_SUITE.erl index 76977c71e1f..e223ca7a485 100644 --- a/lib/compiler/test/receive_SUITE.erl +++ b/lib/compiler/test/receive_SUITE.erl @@ -35,6 +35,7 @@ bs_get_tail/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). init_per_testcase(_Case, Config) -> Config. @@ -144,7 +145,7 @@ coverage(Config) when is_list(Config) -> 61 = tuple_to_values(999999, x), 0 = tuple_to_values(1, x), - {'EXIT',{{badmap,[]},_}} = (catch monitor_plus_badmap(self())), + ?assertError({badmap,[]}, monitor_plus_badmap(self())), self() ! {data,no_data}, @@ -192,7 +193,7 @@ coverage(Config) when is_list(Config) -> %% Cover code for handling a non-boolean `br` in beam_ssa_dead. self() ! whatever, - {'EXIT',{{badmatch,_},_}} = (catch [a || true =:= (other = receive whatever -> false end)]), + ?assertError({badmatch,_}, [a || true =:= (other = receive whatever -> false end)]), %% Cover code in beam_ssa_pre_codegen. self() ! 0, @@ -519,7 +520,7 @@ wait(Config) when is_list(Config) -> self() ! <<42>>, <<42>> = wait_1(r, 1, 2), {1,2,3} = wait_1(1, 2, 3), - {'EXIT',{timeout_value,_}} = (catch receive after [] -> timeout end), + ?assertError(timeout_value, receive after [] -> timeout end), ok. wait_1(r, _, _) -> @@ -850,8 +851,8 @@ in_after(_Config) -> do_in_after(fun() -> ok end), do_in_after(fun() -> ok end), self() ! message, - catch do_in_after(fun() -> error(bad) end), - catch do_in_after(fun() -> error(bad) end), + ?assertError(bad, do_in_after(fun() -> error(bad) end)), + ?assertError(bad, do_in_after(fun() -> error(bad) end)), self() ! last, first = receive M1 -> M1 end, last = receive M2 -> M2 end, diff --git a/lib/compiler/test/record_SUITE.erl b/lib/compiler/test/record_SUITE.erl index 97538762ce5..179a729e2f0 100644 --- a/lib/compiler/test/record_SUITE.erl +++ b/lib/compiler/test/record_SUITE.erl @@ -24,6 +24,7 @@ -module(record_SUITE). -include_lib("common_test/include/ct.hrl"). +-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, @@ -77,17 +78,16 @@ errors(Config) when is_list(Config) -> Foo = #foo{a=1,b=2,c=3,d=4}, #foo{a=19,b=42,c=3,d=4} = update_foo(Foo, 19, 42), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_bar(Foo, 19)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_bar(Foo, 19, 35)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_bar(Foo, 19, 35, 17)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_bar(Foo, 19, 35, 17, 42)), + ?assertError({badrecord,Foo}, update_foo_bar(Foo, 19)), + ?assertError({badrecord,Foo}, update_foo_bar(Foo, 19, 35)), + ?assertError({badrecord,Foo}, update_foo_bar(Foo, 19, 35, 17)), + ?assertError({badrecord,Foo}, update_foo_bar(Foo, 19, 35, 17, 42)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_barf(Foo, 19)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_barf(Foo, 19, 35)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_barf(Foo, 19, 35, 17)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_barf(Foo, 19, 35, 17, 42)), - {'EXIT',{{badrecord,Foo},_}} = (catch update_foo_barf(Foo, 19, - 35, 17, 42, -2)), + ?assertError({badrecord,Foo}, update_foo_barf(Foo, 19)), + ?assertError({badrecord,Foo}, update_foo_barf(Foo, 19, 35)), + ?assertError({badrecord,Foo}, update_foo_barf(Foo, 19, 35, 17)), + ?assertError({badrecord,Foo}, update_foo_barf(Foo, 19, 35, 17, 42)), + ?assertError({badrecord,Foo}, update_foo_barf(Foo, 19, 35, 17, 42, -2)), ok. @@ -252,7 +252,7 @@ record_test_2(Config) when is_list(Config) -> %% Call is_record/2 with illegal arguments. [] = [X || X <- [], is_record(t, id(X))], - {'EXIT',{badarg,_}} = (catch [X || X <- [1], is_record(t, id(X))]), + ?assertError(badarg, [X || X <- [1], is_record(t, id(X))]), %% Update several fields with a string literal. #barf{} = Barf0 = id(#barf{}), @@ -458,7 +458,7 @@ guard_opt(Config) when is_list(Config) -> end, [#r{a=4,b=7},#r{a=1,b=42}] = F(F, [#r{a=4,b=7},#r{a=4,b=7},#r{a=1,b=42}]), - {'EXIT',_} = (catch F(F, [#r1{}])), + ?assertError(_, F(F, [#r1{}])), ok end(), @@ -473,8 +473,8 @@ guard_opt(Config) when is_list(Config) -> end, ok = F(true, #r1{a=true}), error = F(false, anything_goes), - {'EXIT',_} = (catch F(true, #r1{})), - {'EXIT',_} = (catch F(true, #r{})), + ?assertError(_, F(true, #r1{})), + ?assertError(_, F(true, #r{})), ok end(), @@ -648,7 +648,7 @@ coverage(Config) when is_list(Config) -> error3 = check_file_header(#fileheader{}), %% Cover sanitization of is_tagged_tuple in beam_ssa_pre_codegen. - {'EXIT',_} = catch id((catch 22)#rr.a), + ?assertError(_, id((catch 22)#rr.a)), %% Cover beam_ssa_bool. error = coverage_1(true), @@ -762,10 +762,10 @@ grab_bag(_Config) -> error end end, - error = catch T6(100), - error = catch T6([a,b,c]), - error = catch T6(#bar{}), - {'EXIT',{{try_clause,#foo{}},_}} = catch T6(#foo{}), + error = T6(100), + error = T6([a,b,c]), + error = T6(#bar{}), + ?assertError({try_clause,#foo{}}, T6(#foo{})), ok. @@ -854,7 +854,7 @@ duplicate_update_record(Config) when is_list(Config) -> DuplicateUR1 = erlang:setelement(2, DuplicateUR0, false), DuplicateUR = erlang:setelement(2, DuplicateUR1, false), - {'EXIT', _} = catch duplicate_update_record_1(DuplicateUR), + ?assertError(_, duplicate_update_record_1(DuplicateUR)), ok. diff --git a/lib/compiler/test/regressions_SUITE.erl b/lib/compiler/test/regressions_SUITE.erl index 84127748dbf..b2a25e0f394 100644 --- a/lib/compiler/test/regressions_SUITE.erl +++ b/lib/compiler/test/regressions_SUITE.erl @@ -85,12 +85,13 @@ maps(Config) when is_list(Config) -> run(Config, Tests) -> F = fun({N,P}) -> io:format("Compiling test for: ~w~n", [N]), - case catch run_test(Config, P) of - {'EXIT', Reason} -> - io:format("~nTest ~p failed.~nReason: ~p~n", - [N, Reason]), - fail(); - _ -> ok + try + run_test(Config, P) + catch + error:Reason:Stack -> + io:format("~nTest ~p failed.~nReason: ~p~nStack: ~p~n", + [N, Reason, Stack]), + fail() end end, lists:foreach(F, Tests). diff --git a/lib/compiler/test/test_lib.erl b/lib/compiler/test/test_lib.erl index 3a7b6b0e89b..40065f147ad 100644 --- a/lib/compiler/test/test_lib.erl +++ b/lib/compiler/test/test_lib.erl @@ -28,7 +28,9 @@ smoke_disasm/1, p_run/2, highest_opcode/1, - get_unique_files/1,get_unique_files/2]). + get_unique_files/1,get_unique_files/2, + assert_error_stack/3 + ]). %% Used by test case that override BIFs. -export([binary_part/2,binary/1]). @@ -259,3 +261,32 @@ binary_part(_A,_B) -> %% This is for overridden_bif_SUITE. binary(N) -> N rem 10 =:= 0. + +%% Helper for ?AssertErrorStack(). +assert_error_stack(ErrorFun, StackFun, ExprFun) -> + try ExprFun() of + Result -> + error({unexpected_success,Result}) + catch + error:Error:Stack -> + case {ErrorFun(Error),StackFun(Stack)} of + {ok,ok} -> + ok; + {ActualError,ActualStack} -> + Args = case ActualError of + ok -> + []; + _ -> + [{unexpected_error, Error}, + {expected, ActualError}] + end ++ + case ActualStack of + ok -> + []; + _ -> + [{unexpected_stack, Stack}, + {expected_stack, ActualStack}] + end, + error(assertException, Args) + end + end. diff --git a/lib/compiler/test/test_lib.hrl b/lib/compiler/test/test_lib.hrl new file mode 100644 index 00000000000..ced9af9efad --- /dev/null +++ b/lib/compiler/test/test_lib.hrl @@ -0,0 +1,37 @@ +%% +%% %CopyrightBegin% +%% +%% SPDX-License-Identifier: Apache-2.0 +%% +%% Copyright Ericsson AB 2026. All Rights Reserved. +%% +%% Licensed under the Apache License, Version 2.0 (the "License"); +%% you may not use this file except in compliance with the License. +%% You may obtain a copy of the License at +%% +%% http://www.apache.org/licenses/LICENSE-2.0 +%% +%% Unless required by applicable law or agreed to in writing, software +%% distributed under the License is distributed on an "AS IS" BASIS, +%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +%% See the License for the specific language governing permissions and +%% limitations under the License. +%% +%% %CopyrightEnd% +%% + +-define(AssertErrorStack(Error, Stack, Expr), + test_lib:assert_error_stack( + fun(__Error__) -> + case __Error__ of + Error -> ok; + (_) -> ??Error + end + end, + fun(__Stack__) -> + case __Stack__ of + Stack -> ok; + (_) -> ??Stack + end + end, + fun() -> Expr end)). diff --git a/lib/compiler/test/trycatch_SUITE.erl b/lib/compiler/test/trycatch_SUITE.erl index 5550751f926..361b2d5995a 100644 --- a/lib/compiler/test/trycatch_SUITE.erl +++ b/lib/compiler/test/trycatch_SUITE.erl @@ -37,6 +37,7 @@ throw_opt_funs/1]). -include_lib("common_test/include/ct.hrl"). +-include_lib("stdlib/include/assert.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -963,7 +964,7 @@ bool(Config) when is_list(Config) -> error = do_bool(true, false), error = do_bool(true, true), error = do_bool(true, blurf), - {'EXIT',_} = (catch do_bool(blurf, false)), + ?assertError(_, do_bool(blurf, false)), ok. %% The following function used to cause a crash in beam_bool. @@ -1126,7 +1127,7 @@ grab_bag(_Config) -> <<>> = grab_bag_2(whatever), - {'EXIT',_} = (catch grab_bag_3()), + ?assertError(_, grab_bag_3()), true = grab_bag_4(), @@ -1558,7 +1559,7 @@ throw_opt_crash_1(false, _Term) -> ok. coverage(Config) -> - {'EXIT',{{badfun,true},[_|_]}} = (catch coverage_1()), + ?assertError({badfun,true}, coverage_1()), ok = coverage_ssa_throw(), error = coverage_pre_codegen(), {a,[42]} = do_plain_catch_list(42), diff --git a/lib/compiler/test/warnings_SUITE.erl b/lib/compiler/test/warnings_SUITE.erl index 5fa0e188911..beb004f18af 100644 --- a/lib/compiler/test/warnings_SUITE.erl +++ b/lib/compiler/test/warnings_SUITE.erl @@ -20,6 +20,7 @@ %% %CopyrightEnd% %% -module(warnings_SUITE). +-include_lib("stdlib/include/assert.hrl"). %%-define(STANDALONE, true). @@ -602,7 +603,7 @@ bin_opt_info(Config) when is_list(Config) -> split_binary(T, 4). ">>, - Ws = (catch run_test(Config, Code, [bin_opt_info])), + Ws = run_test(Config, Code, [bin_opt_info]), %% This is an inexact match since the pass reports exact instructions as %% part of the warnings, which may include annotations that vary from run @@ -624,7 +625,7 @@ bin_opt_info(Config) when is_list(Config) -> ]} = Ws, %% For coverage: don't give the bin_opt_info option. - [] = (catch run_test(Config, Code, [])), + [] = run_test(Config, Code, []), %% Now try with abstract code and no location. %% @@ -654,7 +655,7 @@ bin_opt_info(Config) when is_list(Config) -> [], [{call,0,{atom,0,t1},[{var,0,'T'}]}]}, {clause,0,[{bin,0,[]}],[],[{atom,0,ok}]}]}]}]}], - Wsf = (catch run_forms(Forms, [bin_opt_info])), + Wsf = run_forms(Forms, [bin_opt_info]), {warnings, [{none,beam_ssa_bsm,{unsuitable_call, @@ -1192,7 +1193,7 @@ recv_opt_info(Config) when is_list(Config) -> end. ">>, - Ws = (catch run_test(Config, Code, [recv_opt_info])), + Ws = run_test(Config, Code, [recv_opt_info]), %% This is an inexact match since the pass reports exact instructions as %% part of the warnings, which may include annotations that vary from run @@ -1212,7 +1213,7 @@ recv_opt_info(Config) when is_list(Config) -> {23,beam_ssa_recv,{used_receive_marker,_}}]} = Ws, %% For coverage: don't give the recv_opt_info option. - [] = (catch run_test(Config, Code, [])), + [] = run_test(Config, Code, []), %% Now try with abstract code and no location. %% @@ -1233,7 +1234,7 @@ recv_opt_info(Config) when is_list(Config) -> [{var,0,'Msg'}]}]}]}]}]} ], - Wsf = (catch run_forms(Forms, [recv_opt_info])), + Wsf = run_forms(Forms, [recv_opt_info]), {warnings, [{none,beam_ssa_recv,matches_any_message}]} = Wsf, ok. @@ -1393,12 +1394,13 @@ lines_only_1({Loc,Mod,Error}) -> do_run(Config, Tests) -> F = fun({N,P,Ws,E}, BadL) -> io:format("### ~s\n", [N]), - case catch run_test(Config, P, Ws) of - E -> - BadL; - Bad -> + try run_test(Config, P, Ws) of + E -> + BadL + catch + error:Bad:Stack -> io:format("~nTest ~p failed. Expected~n ~p~n" - "but got~n ~p~n", [N, E, Bad]), + "but got~n ~p ~p~n", [N, E, Bad, Stack]), fail() end end, diff --git a/lib/compiler/test/zlc_SUITE.erl b/lib/compiler/test/zlc_SUITE.erl index 4708d8d0a6b..69fe7929c4f 100644 --- a/lib/compiler/test/zlc_SUITE.erl +++ b/lib/compiler/test/zlc_SUITE.erl @@ -31,6 +31,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("stdlib/include/assert.hrl"). +-include("test_lib.hrl"). suite() -> [{ct_hooks,[ts_install_cth]}, @@ -225,10 +226,10 @@ strict_list(Config) when is_list(Config) -> [] = strict_list_mixed_1([], []), [11,22] = strict_list_mixed_1([{i,1},{i,2}], [{i,10},{i,20}]), [13,25] = strict_list_mixed_1([{i,3},{i,4},{i,5}], [{i,10},bad,{i,20}]), - {'EXIT',{{bad_generators,{[bad,{i,5}],[{i,15},{i,20}]}},_}} = - catch strict_list_mixed_1([{i,3},bad,{i,5}], [{i,10},{i,15},{i,20}]), - {'EXIT',{{bad_generators,{[{i,5}],[]}},_}} = - catch strict_list_mixed_1([{i,3},{i,5}], [bad]), + ?assertError({bad_generators,{[bad,{i,5}],[{i,15},{i,20}]}}, + strict_list_mixed_1([{i,3},bad,{i,5}], [{i,10},{i,15},{i,20}])), + ?assertError({bad_generators,{[{i,5}],[]}}, + strict_list_mixed_1([{i,3},{i,5}], [bad])), [] = strict_list_mixed_2([], #{}), [15] = strict_list_mixed_2([{i,3}], #{{k,4} => {v,3}}), @@ -239,21 +240,21 @@ strict_list(Config) when is_list(Config) -> strict_list_mixed_2([{i,I} || I <- Seq100], #{{k,3*I} => {v,7*I} || I <- Seq100})), SimpleMap = #{{k,1} => {v,2}}, - {'EXIT',{{bad_generators,{[{a,3}],{{k,1},{v,2},none}}},_}} = - catch strict_list_mixed_2([{a,3}], SimpleMap), - {'EXIT',{{bad_generators,{[],{{k,1},{v,2},none}}},_}} = - catch strict_list_mixed_2([], SimpleMap), + ?assertError({bad_generators,{[{a,3}],{{k,1},{v,2},none}}}, + strict_list_mixed_2([{a,3}], SimpleMap)), + ?assertError({bad_generators,{[],{{k,1},{v,2},none}}}, + strict_list_mixed_2([], SimpleMap)), [] = strict_list_strict_1([], []), [11,22] = strict_list_strict_1([{i,1},{i,2}], [{i,10},{i,20}]), - {'EXIT',{{bad_generators,{[bad,{i,5}],[{i,15},{i,20}]}},_}} = - catch strict_list_strict_1([{i,3},bad,{i,5}], [{i,10},{i,15},{i,20}]), - {'EXIT',{{bad_generators,{[{i,4},{i,5}],[{wrong_tag,7},{i,20}]}},_}} = - catch strict_list_strict_1([{i,3},{i,4},{i,5}], [{i,10},{wrong_tag,7},{i,20}]), - {'EXIT',{{bad_generators,{[{a,b,c},{i,5}],[{wrong_tag,7},{i,20}]}},_}} = - catch strict_list_strict_1([{i,3},{a,b,c},{i,5}], [{i,10},{wrong_tag,7},{i,20}]), - {'EXIT',{{bad_generators,{[{i,5}],[]}},_}} = - catch strict_list_strict_1([{i,3},{i,5}], [{i,7}]), + ?assertError({bad_generators,{[bad,{i,5}],[{i,15},{i,20}]}}, + strict_list_strict_1([{i,3},bad,{i,5}], [{i,10},{i,15},{i,20}])), + ?assertError({bad_generators,{[{i,4},{i,5}],[{wrong_tag,7},{i,20}]}}, + strict_list_strict_1([{i,3},{i,4},{i,5}], [{i,10},{wrong_tag,7},{i,20}])), + ?assertError({bad_generators,{[{a,b,c},{i,5}],[{wrong_tag,7},{i,20}]}}, + strict_list_strict_1([{i,3},{a,b,c},{i,5}], [{i,10},{wrong_tag,7},{i,20}])), + ?assertError({bad_generators,{[{i,5}],[]}}, + strict_list_strict_1([{i,3},{i,5}], [{i,7}])), [] = strict_list_strict_2([], [], <<>>), [5,23] = strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9>>), @@ -261,48 +262,47 @@ strict_list(Config) when is_list(Config) -> strict_list_strict_2([{i,2*I} || I <- Seq100], [{i,3*I} || I <- Seq100], list_to_binary(Seq100))), - {'EXIT',{{bad_generators,{[{i,2}],[{i,7}],<<9:7>>}},_}} = - catch strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9:7>>), - {'EXIT',{{bad_generators,{[],[],[]}},_}} = - catch strict_list_strict_2([], [], []), - {'EXIT',{{bad_generators,{[{i,0}],[],<<>>}},_}} = - catch strict_list_strict_2([{i,0}], [], <<>>), - {'EXIT',{{bad_generators,{[{i,0}],[{bad,5}],<<99>>}},_}} = - catch strict_list_strict_2([{i,0}], [{bad,5}], <<99>>), - {'EXIT',{{bad_generators,{[{i,20}],[{i,21}],<<42:7>>}},_}} = - catch strict_list_strict_2([{i,20}], [{i,21}], <<42:7>>), + ?assertError({bad_generators,{[{i,2}],[{i,7}],<<9:7>>}}, + strict_list_strict_2([{i,1},{i,2}], [{i,2},{i,7}], <<3,9:7>>)), + ?assertError({bad_generators,{[],[],[]}}, + strict_list_strict_2([], [], [])), + ?assertError({bad_generators,{[{i,0}],[],<<>>}}, + strict_list_strict_2([{i,0}], [], <<>>)), + ?assertError({bad_generators,{[{i,0}],[{bad,5}],<<99>>}}, + strict_list_strict_2([{i,0}], [{bad,5}], <<99>>)), + ?assertError({bad_generators,{[{i,20}],[{i,21}],<<42:7>>}}, + strict_list_strict_2([{i,20}], [{i,21}], <<42:7>>)), [] = strict_list_strict_3([], <<>>), [45] = strict_list_strict_3([{i,42}], <<3>>), - {'EXIT',{{bad_generators,{[],<<2>>}},_}} = - catch strict_list_strict_3([{i,1}], <<1,2>>), - {'EXIT',{{bad_generators,{[],<<0:7>>}},_}} = - catch strict_list_strict_3([], <<0:7>>), - {'EXIT',{{bad_generators,{[{i,1}],<<0:7>>}},_}} = - catch strict_list_strict_3([{i,1}], <<0:7>>), + ?assertError({bad_generators,{[],<<2>>}}, + strict_list_strict_3([{i,1}], <<1,2>>)), + ?assertError({bad_generators,{[],<<0:7>>}}, + strict_list_strict_3([], <<0:7>>)), + ?assertError({bad_generators,{[{i,1}],<<0:7>>}}, + strict_list_strict_3([{i,1}], <<0:7>>)), [] = strict_list_strict_4([], <<>>), [100] = strict_list_strict_4([{i,100}], <<42>>), - {'EXIT',{{bad_generators,{[{i,100}],<<0>>}},_}} = - catch strict_list_strict_4([{i,100}], <<0>>), - {'EXIT',{{bad_generators,{[{i,100}],<<>>}},_}} = - catch strict_list_strict_4([{i,100}], <<>>), - {'EXIT',{{bad_generators,{[{i,100}],<<0:8,1:1>>}},_}} = - catch strict_list_strict_4([{i,100}], <<0:8,1:1>>), + ?assertError({bad_generators,{[{i,100}],<<0>>}}, + strict_list_strict_4([{i,100}], <<0>>)), + ?assertError({bad_generators,{[{i,100}],<<>>}}, + strict_list_strict_4([{i,100}], <<>>)), + ?assertError({bad_generators,{[{i,100}],<<0:8,1:1>>}}, + strict_list_strict_4([{i,100}], <<0:8,1:1>>)), NaN = <<-1:64>>, [] = strict_list_5(<<>>, <<>>), [3.14] = strict_list_5(<<0:1,1:1>>, <<32,0.0:32/float, 64,3.14:64/float>>), [+0.0,3.14] = strict_list_5(<<1:1,1:1>>, <<32,0.0:32/float, 64,3.14:64/float>>), - {'EXIT',{{bad_generators,{<<>>,<<64,42.0/float>>}},_}} = - catch strict_list_5(<<>>, <<64,42.0/float>>), - {'EXIT',{{bad_generators,{<<0:1,1:1>>, - <<117,-1:117/signed,32,17.0:32/float>>}},_}} = - catch strict_list_5(<<0:1,1:1>>, <<117,-1:117, 32,17.0:32/float>>), - {'EXIT',{{bad_generators,{<<0:1>>,<<64,NaN/binary>>}},_}} = - catch strict_list_5(<<1:1,0:1>>, <<32,42.0:32/float, 64,NaN/binary>>), - {'EXIT',{{bad_generators,{<<1:1>>,<<64,NaN/binary>>}},_}} = - catch strict_list_5(<<1:1,1:1>>, <<32,42.0:32/float, 64,NaN/binary>>), + ?assertError({bad_generators,{<<>>,<<64,42.0/float>>}}, + strict_list_5(<<>>, <<64,42.0/float>>)), + ?assertError({bad_generators,{<<0:1,1:1>>,<<117,-1:117/signed,32,17.0:32/float>>}}, + strict_list_5(<<0:1,1:1>>, <<117,-1:117, 32,17.0:32/float>>)), + ?assertError({bad_generators,{<<0:1>>,<<64,NaN/binary>>}}, + strict_list_5(<<1:1,0:1>>, <<32,42.0:32/float, 64,NaN/binary>>)), + ?assertError({bad_generators,{<<1:1>>,<<64,NaN/binary>>}}, + strict_list_5(<<1:1,1:1>>, <<32,42.0:32/float, 64,NaN/binary>>)), ok. @@ -334,7 +334,8 @@ strict_binary(Config) when is_list(Config) -> Seq100 = lists:seq(1, 100), <<2,4,6>> = << <<(X+Y)>> || X <:- [1,2,3] && <> <= <<1,2,3>>>>, - {'EXIT',{{bad_generators,{<<3>>,[{2,3}]}},_}} = catch << <<(X+Y)>> || <> <:= <<1,2,3>> && {X, Y} <- [{1,1},{2,2},{2,3}]>>, + ?assertError({bad_generators,{<<3>>,[{2,3}]}}, + << <<(X+Y)>> || <> <:= <<1,2,3>> && {X, Y} <- [{1,1},{2,2},{2,3}]>>), <<2,24>> = << <<(X*Y*Z)>> || X := Y <:- #{1 => 2, 3 => 4} && <> <:= <<1,2>> >>, <<>> = strict_binary_1(#{}, <<>>), @@ -342,9 +343,9 @@ strict_binary(Config) when is_list(Config) -> ?assertEqual(<< <<(5*I * 3*I * I):64>> || I <- Seq100 >>, strict_binary_1(maps:iterator(#{5*I => {val,3*I} || I <- Seq100}, ordered), list_to_binary(Seq100))), - {'EXIT',{{bad_generators,{none,<<42:8>>}},_}} = catch strict_binary_1(#{}, <<42:8>>), - {'EXIT',{{bad_generators,{none,<<42:7>>}},_}} = catch strict_binary_1(#{}, <<42:7>>), - {'EXIT',{{bad_generators,{none,<<0:4>>}},_}} = catch strict_binary_1(#{2 => {val,3}}, <<0,0:4>>), + ?assertError({bad_generators,{none,<<42:8>>}}, strict_binary_1(#{}, <<42:8>>)), + ?assertError({bad_generators,{none,<<42:7>>}}, strict_binary_1(#{}, <<42:7>>)), + ?assertError({bad_generators,{none,<<0:4>>}}, strict_binary_1(#{2 => {val,3}}, <<0,0:4>>)), <<>> = strict_binary_mixed_1(<<>>, #{}, #{}), <<>> = strict_binary_mixed_1(<<1:2>>, #{}, #{}), @@ -357,16 +358,16 @@ strict_binary(Config) when is_list(Config) -> strict_binary_mixed_1(<<-1:100>>, #{I => {v,I} || I <- Seq100}, #{I => {v,-I} || I <- Seq100})), - {'EXIT',{{bad_generators,{<<0:1>>,{0,0,none},{0,{v,7},none}}},_}} = - catch strict_binary_mixed_1(<<0:1>>, #{0 => 0}, #{0 => {v,7}}), + ?assertError({bad_generators,{<<0:1>>,{0,0,none},{0,{v,7},none}}}, + strict_binary_mixed_1(<<0:1>>, #{0 => 0}, #{0 => {v,7}})), Island = ~"skärgårdsö", IslandSeq = lists:seq(1, length([C || <> <= Island])), ?assertEqual(<< <> || {I,C} <:- lists:zip(IslandSeq, [C || <> <= Island]) >>, strict_binary_utf8(IslandSeq, Island)), - {'EXIT',{{bad_generators,{[4,5,6,7,8],<<16#ff,16#ff,"def">>}},_}} = - catch strict_binary_utf8(lists:seq(1, 8), <<"abc",16#ff,16#ff,"def">>), + ?assertError({bad_generators,{[4,5,6,7,8],<<16#ff,16#ff,"def">>}}, + strict_binary_utf8(lists:seq(1, 8), <<"abc",16#ff,16#ff,"def">>)), ok. @@ -385,39 +386,53 @@ strict_binary_mixed_1(Bin, MapA0, MapB0) -> end || <> <= Bin && _ := {v,V1} <:- MapA && _ := {v,V2} <- MapB>>. nomatch(Config) when is_list(Config) -> - [] = do_nomatch_1([], []), - [] = do_nomatch_1([1], [a]), - [] = do_nomatch_1([1,2], [a,b]), - {'EXIT',{{bad_generators,{[1,2,3],[]}},_}} = do_nomatch_1([1,2,3], []), - {'EXIT',{{bad_generators,{[3],[]}},_}} = do_nomatch_1([1,2,3], [a,b]), + [] = do_nomatch_1a([], []), + [] = do_nomatch_1b([], []), + [] = do_nomatch_1c([1], [a]), + + [] = do_nomatch_1a([1,2], [a,b]), + [] = do_nomatch_1b([1,2], [a,b]), + [] = do_nomatch_1c([1,2], [a,b]), + + ?assertError({bad_generators,{[],[1,2,3]}}, do_nomatch_1a([1,2,3], [])), + ?assertError({bad_generators,{[1,2,3],[]}}, do_nomatch_1b([1,2,3], [])), + ?assertError({bad_generators,{[1,2,3],[]}}, do_nomatch_1c([1,2,3], [])), + + ?assertError({bad_generators,{[],[3]}}, do_nomatch_1a([1,2,3], [a,b])), + ?assertError({bad_generators,{[3],[]}}, do_nomatch_1b([1,2,3], [a,b])), + ?assertError({bad_generators,{[3],[]}}, do_nomatch_1c([1,2,3], [a,b])), <<>> = do_nomatch_2([], <<>>), <<>> = do_nomatch_2([a], <<1>>), - {'EXIT',{{bad_generators,{[2],<<>>}},_}} = do_nomatch_2([1,2], <<3>>), + ?assertError({bad_generators,{[2],<<>>}}, do_nomatch_2([1,2], <<3>>)), ok. -do_nomatch_1(L1, L2) -> - catch [{X, Y} || Y <- L2 && a=b=X <- L1], - catch [{X, Y} || a=b=X <- L1 && Y <:- L2], - catch [{X, Y} || a=b=X <- L1 && Y <- L2]. +do_nomatch_1a(L1, L2) -> + [{X, Y} || Y <- L2 && a=b=X <- L1]. + +do_nomatch_1b(L1, L2) -> + [{X, Y} || a=b=X <- L1 && Y <:- L2]. + +do_nomatch_1c(L1, L2) -> + [{X, Y} || a=b=X <- L1 && Y <- L2]. do_nomatch_2(L, Bin) -> - catch << <<(X+Y)/integer>> || a=b=X <- L && <> <= Bin >>. + << <<(X+Y)/integer>> || a=b=X <- L && <> <= Bin >>. bad_generators(Config) when is_list(Config) -> - {'EXIT',{{bad_generators,{x,[1,2]}},_}} = - catch [{X,Y} || X <- x && Y <- [1,2]], - {'EXIT',{{bad_generators,{[],[4]}},_}} = - catch [{X,Y} || X <- [1,2,3] && Y <- [1,2,3,4]], - {'EXIT',{{bad_generators,{[3,4],[]}},_}} = - catch [{X,Y} || X <- [1,2,3,4] && Y <- [1,2], X < 3], - {'EXIT',{{bad_generators,{[3,4],[]}},_}} = - catch << <<(X+Y)/integer>> || X <- [1,2,3,4] && Y <- [1,2], X < 3>>, - {'EXIT',{{bad_generators,{<<1,2>>,a}},_}} = - catch << <> || <> <= <<1:8,2:8>> && <> <= a>>, - {'EXIT',{{bad_generator,a},_}} = catch [X || X := X <- a && _Y <- [1]], - {'EXIT',{{bad_generators,{[d],[]}},_}} = - catch #{X => Y || X <- [a,b,c,d] && Y <- [1,2,3], Y > 1}, + ?assertError({bad_generators,{x,[1,2]}}, + [{X,Y} || X <- x && Y <- [1,2]]), + ?assertError({bad_generators,{[],[4]}}, + [{X,Y} || X <- [1,2,3] && Y <- [1,2,3,4]]), + ?assertError({bad_generators,{[3,4],[]}}, + [{X,Y} || X <- [1,2,3,4] && Y <- [1,2], X < 3]), + ?assertError({bad_generators,{[3,4],[]}}, + << <<(X+Y)/integer>> || X <- [1,2,3,4] && Y <- [1,2], X < 3>>), + ?assertError({bad_generators,{<<1,2>>,a}}, + << <> || <> <= <<1:8,2:8>> && <> <= a>>), + ?assertError({bad_generator,a}, [X || X := X <- a && _Y <- [1]]), + ?assertError({bad_generators,{[d],[]}}, + #{X => Y || X <- [a,b,c,d] && Y <- [1,2,3], Y > 1}), ?assertError({bad_generator,gen}, [ok || 0 <:- [a] && _ := true <- gen]), %% Make sure that line numbers point out the generator. @@ -426,27 +441,28 @@ bad_generators(Config) when is_list(Config) -> %% No inline suite for now. Just a guard in case we add it later. ok; _ -> - {'EXIT',{{bad_generators,{[],[4]}}, - [{?MODULE,_,_, - [{file,"bad_zlc.erl"},{line,4}]}|_]}} = - catch bad_generators([1,2,3],[1,2,3,4]), + ?AssertErrorStack({bad_generators,{[],[4]}}, + [{?MODULE,_,_, + [{file,"bad_zlc.erl"},{line,4}]}|_], + bad_generators([1,2,3],[1,2,3,4])), - {'EXIT',{{bad_generators,{a,[2,3]}}, - [{?MODULE,_,_, - [{file,"bad_zlc.erl"},{line,7}]}|_]}} = - catch bad_generators_bc(a,[2,3]), + ?AssertErrorStack({bad_generators,{a,[2,3]}}, + [{?MODULE,_,_, + [{file,"bad_zlc.erl"},{line,7}]}|_], + bad_generators_bc(a,[2,3])), - {'EXIT',{{bad_generators,{[2],[]}}, - [{?MODULE,_,_, - [{file,"bad_zlc.erl"},{line,10}]}|_]}} = - catch bad_generators_mc([1,2],[1]), + ?AssertErrorStack({bad_generators,{[2],[]}}, + [{?MODULE,_,_, + [{file,"bad_zlc.erl"},{line,10}]}|_], + bad_generators_mc([1,2],[1])), %% List comprehensions with improper lists. - {'EXIT',{{bad_generators,{d,[d]}}, - [{?MODULE,_,_, - [{file,"bad_zlc.erl"},{line,4}]}|_]}} = - catch bad_generators([a,b,c|d],[a,b,c,d]) + ?AssertErrorStack({bad_generators,{d,[d]}}, + [{?MODULE,_,_, + [{file,"bad_zlc.erl"},{line,4}]}|_], + bad_generators([a,b,c|d],[a,b,c,d])) end, + ok. %% Cover some code in sys_coverage. @@ -479,32 +495,33 @@ do_cover_1(L1, L2) -> strict_pat(Config) when is_list(Config) -> [a] = strict_pat_1([a], [a], [a]), - {'EXIT',{{bad_generators,{[b],[a],[a]}},_}} = - catch strict_pat_1([b], [a], [a]), - {'EXIT',{{bad_generators,{[b],[a],[b]}},_}} = - catch strict_pat_1([b], [a], [b]), - {'EXIT',{{bad_generators,{[b],[a],[b]}},_}} = - catch strict_pat_1([a,b], [a,a], [a,b]), + ?assertError({bad_generators,{[b],[a],[a]}}, + strict_pat_1([b], [a], [a])), + ?assertError({bad_generators,{[b],[a],[b]}}, + strict_pat_1([b], [a], [b])), + ?assertError({bad_generators,{[b],[a],[b]}}, + strict_pat_1([a,b], [a,a], [a,b])), [{a,b}] = strict_pat_2([{a,b}], [b], [a]), [] = strict_pat_2([{a,b}], [b], [b]), - {'EXIT',{{bad_generators,{[{a,b}],[a],[b]}},_}} = - catch strict_pat_2([{a,b}], [a], [b]), + ?assertError({bad_generators,{[{a,b}],[a],[b]}}, + strict_pat_2([{a,b}], [a], [b])), #{1:= 2} = strict_pat_3(#{1=>2}, #{1=>3}), - {'EXIT',{{bad_generators,{{1,2,none},{2,3,none}}},_}} = - catch strict_pat_3(#{1=>2}, #{2=>3}), + ?assertError({bad_generators,{{1,2,none},{2,3,none}}}, + strict_pat_3(#{1=>2}, #{2=>3})), [{a,b,c}] = strict_pat_4([{{a,b},c}], [c]), [] = strict_pat_4([{[a,b],c}], [c]), [] = strict_pat_4([{no_tuple,c}], [c]), - {'EXIT',{{bad_generators,{[{{a,b},c}],[d]}},_}} = - catch strict_pat_4([{{a,b},c}], [d]), + ?assertError({bad_generators,{[{{a,b},c}],[d]}}, + strict_pat_4([{{a,b},c}], [d])), [{a,1}] = strict_pat_5([a], [#{a=>1}], [1]), [{a,1},{a,2}] = strict_pat_5([a], [#{a=>1},#{a=>2}], [1,2]), - {'EXIT',{{bad_generators,{[#{a:=1},#{a:=2}],[2,1]}},_}} = - catch strict_pat_5([a], [#{a=>1},#{a=>2}], [2,1]), + ?assertError({bad_generators,{[#{a:=1},#{a:=2}],[2,1]}}, + strict_pat_5([a], [#{a=>1},#{a=>2}], [2,1])), + ok. strict_pat_1(G1, G2, G3) -> @@ -516,8 +533,11 @@ strict_pat_2(G1, G2, G3) -> [{X,Y} || {X,Y} <- G1 && Y <:- G2 && X <- G3]. strict_pat_3(G1, G2) -> - catch #{K => V || a=b=K := V <- G1 && K := _ <:- G2}, - #{K => V || K := V <- G1 && K := _ <:- G2}. + case #{K => V || a=b=K := V <- G1 && K := _ <:- G2} of + Map when map_size(Map) =:= 0 -> + ok + end, + Res = #{K => V || K := V <- G1 && K := _ <:- G2}. strict_pat_4(G1, G2) -> Res = [{X,Y,Z} || {{X,Y},Z} <- G1 && Z <:- G2],