Skip to content

Commit

Permalink
Add some testcases to compiler to verify that overriding really happens
Browse files Browse the repository at this point in the history
  • Loading branch information
bufflig committed Jun 2, 2010
1 parent 634dd37 commit b72cac2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 4 deletions.
49 changes: 47 additions & 2 deletions lib/compiler/test/misc_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,23 @@

-export([all/1,init_per_testcase/2,fin_per_testcase/2,
tobias/1,empty_string/1,md5/1,silly_coverage/1,
confused_literals/1,integer_encoding/1]).
confused_literals/1,integer_encoding/1,override_bif/1]).

-include("test_server.hrl").

%% For the override_bif testcase.
%% NB, no other testcases in this testsuite can use these without erlang:prefix!
-compile({no_auto_import,[abs/1]}).
-compile({no_auto_import,[binary_part/3]}).
-compile({no_auto_import,[binary_part/2]}).
-import(test_lib,[binary_part/2]).

%% This should do no harm (except for fun byte_size/1 which does not, by design, work with import
-compile({no_auto_import,[byte_size/1]}).
-import(erlang,[byte_size/1]).



%% Include an opaque declaration to cover the stripping of
%% opaque types from attributes in v3_kernel.
-opaque misc_SUITE_test_cases() :: [atom()].
Expand All @@ -42,7 +55,39 @@ fin_per_testcase(Case, Config) when is_atom(Case), is_list(Config) ->
all(suite) ->
test_lib:recompile(?MODULE),
[tobias,empty_string,md5,silly_coverage,confused_literals,
integer_encoding].
integer_encoding, override_bif].


%%
%% Functions that override new and old bif's
%%
abs(_N) ->
dummy_abs.

binary_part(_,_,_) ->
dummy_bp.

% Make sure that auto-imported BIF's are overridden correctly

override_bif(suite) ->
[];
override_bif(doc) ->
["Test dat local functions and imports override auto-imported BIFs."];
override_bif(Config) when is_list(Config) ->
?line dummy_abs = abs(1),
?line dummy_bp = binary_part(<<"hello">>,1,1),
?line dummy = binary_part(<<"hello">>,{1,1}),
?line 1 = erlang:abs(1),
?line <<"e">> = erlang:binary_part(<<"hello">>,1,1),
?line <<"e">> = erlang:binary_part(<<"hello">>,{1,1}),
F = fun(X) when byte_size(X) =:= 4 ->
four;
(X) ->
byte_size(X)
end,
?line four = F(<<1,2,3,4>>),
?line 5 = F(<<1,2,3,4,5>>),
ok.

%% A bug reported by Tobias Lindahl for a development version of R11B.

Expand Down
8 changes: 6 additions & 2 deletions lib/compiler/test/test_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
-module(test_lib).

-include("test_server.hrl").

-export([recompile/1,opt_opts/1,get_data_dir/1,smoke_disasm/1,p_run/2]).
-compile({no_auto_import,[binary_part/2]}).
-export([recompile/1,opt_opts/1,get_data_dir/1,smoke_disasm/1,p_run/2,binary_part/2]).

recompile(Mod) when is_atom(Mod) ->
case whereis(cover_server) of
Expand Down Expand Up @@ -104,3 +104,7 @@ p_run_loop(Test, List, N, Refs0, Errors0, Ws0) ->
Refs = Refs0 -- [Ref],
p_run_loop(Test, List, N, Refs, Errors, Ws)
end.

%% This is for the misc_SUITE:override_bif testcase
binary_part(_A,_B) ->
dummy.

0 comments on commit b72cac2

Please sign in to comment.