diff options
author | Björn Gustavsson <[email protected]> | 2016-06-23 13:20:57 +0200 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2016-06-29 11:37:31 +0200 |
commit | b23b3f903e2cfac2f9b9faac7c7fa19c0ec8f625 (patch) | |
tree | 23cf5b1ef64b23c1909ea6ec0f1e23052df31e39 /lib/compiler/test/bif_SUITE.erl | |
parent | 1c7526a30444a0e3f0bc038ae5894d63b7914e46 (diff) | |
download | otp-b23b3f903e2cfac2f9b9faac7c7fa19c0ec8f625.tar.gz otp-b23b3f903e2cfac2f9b9faac7c7fa19c0ec8f625.tar.bz2 otp-b23b3f903e2cfac2f9b9faac7c7fa19c0ec8f625.zip |
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).
Diffstat (limited to 'lib/compiler/test/bif_SUITE.erl')
-rw-r--r-- | lib/compiler/test/bif_SUITE.erl | 45 |
1 files changed, 43 insertions, 2 deletions
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."). |