From b23b3f903e2cfac2f9b9faac7c7fa19c0ec8f625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Thu, 23 Jun 2016 13:20:57 +0200 Subject: compiler: Eliminate num_bif_SUITE num_bif_SUITE.erl was originally copied from the emulator test suite. It does not test much of the compiler. Therefore, remove num_bif_SUITE. Add a new test to bif_SUITE to test trunc/1 and round/1 in contexts that could be tricky for the compiler to handle correctly. Note that there is no need to test abs/1 in bif_SUITE, since it is tested in many other places (e.g. in guard_SUITE). --- lib/compiler/test/bif_SUITE.erl | 45 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'lib/compiler/test/bif_SUITE.erl') diff --git a/lib/compiler/test/bif_SUITE.erl b/lib/compiler/test/bif_SUITE.erl index 51bc71da81..6d7231b426 100644 --- a/lib/compiler/test/bif_SUITE.erl +++ b/lib/compiler/test/bif_SUITE.erl @@ -19,9 +19,11 @@ %% -module(bif_SUITE). +-include_lib("syntax_tools/include/merl.hrl"). + -export([all/0,suite/0,groups/0,init_per_suite/1,end_per_suite/1, init_per_group/2,end_per_group/2, - beam_validator/1]). + beam_validator/1,trunc_and_friends/1]). suite() -> [{ct_hooks,[ts_install_cth]}]. @@ -32,7 +34,8 @@ all() -> groups() -> [{p,[parallel], - [beam_validator + [beam_validator, + trunc_and_friends ]}]. init_per_suite(Config) -> @@ -63,3 +66,41 @@ food(Curriculum) -> catch _ -> 0 end, Curriculum]. + +%% Test trunc/1, round/1. +trunc_and_friends(_Config) -> + Bifs = [trunc,round], + Fs = trunc_and_friends_1(Bifs), + Mod = ?FUNCTION_NAME, + Calls = [begin + Atom = erl_syntax:function_name(N), + ?Q("'@Atom'()") + end || N <- Fs], + Tree = ?Q(["-module('@Mod@').", + "-export([test/0]).", + "test() -> _@Calls, ok.", + "id(I) -> I."]) ++ Fs, + merl:print(Tree), + Opts = test_lib:opt_opts(?MODULE), + {ok,_Bin} = merl:compile_and_load(Tree, Opts), + Mod:test(), + ok. + +trunc_and_friends_1([F|Fs]) -> + Func = list_to_atom("f"++integer_to_list(length(Fs))), + [trunc_template(Func, F)|trunc_and_friends_1(Fs)]; +trunc_and_friends_1([]) -> []. + +trunc_template(Func, Bif) -> + Val = 42.77, + Res = erlang:Bif(Val), + FloatRes = float(Res), + ?Q("'@Func@'() -> + Var = id(_@Val@), + if _@Bif@(Var) =:= _@Res@ -> ok end, + if _@Bif@(Var) == _@FloatRes@ -> ok end, + if _@Bif@(Var) == _@Res@ -> ok end, + _@Res@ = _@Bif@(Var), + try begin _@Bif@(a), ok end + catch error:badarg -> ok end, + ok."). -- cgit v1.2.3