4
%% Copyright Ericsson AB 1999-2010. All Rights Reserved.
6
%% The contents of this file are subject to the Erlang Public License,
7
%% Version 1.1, (the "License"); you may not use this file except in
8
%% compliance with the License. You should have received a copy of the
9
%% Erlang Public License along with this software. If not, it can be
10
%% retrieved online at http://www.erlang.org/.
12
%% Software distributed under the License is distributed on an "AS IS"
13
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
14
%% the License for the specific language governing rights and limitations
21
-module(my_int_eval_module).
22
-stupid_attribute({a,b}).
24
-export([ets_new/0,ets_delete/1,spawn_test/0,apply_test/1,external_call_test/1]).
25
-export([check_exports/1,check_module_info/2]).
26
-export([give_me_a_fun_0/0,give_me_a_fun_0/1,give_me_a_fun_1/2,
27
give_me_a_bad_fun/0, do_apply/1, do_apply/2]).
28
-export([please_call_exit/1,i_will_do_the_exit/1]).
29
-export([more_catch/1,more_nocatch/1,exit_me/0]).
30
-export([f/1, f_try/1, f_catch/1]).
31
-export([otp_5837/1, otp_8310/0]).
34
-export([echo/2,my_subtract/2,catch_a_ball/0,throw_a_ball/0]).
35
-export([i_am_exported/1]).
37
-import(lists, [member/2]).
39
-define(line,put(test_server_loc,{?MODULE,?LINE}),).
40
-define(t,test_server).
41
-define(m,test_server:match).
42
-define(config,test_server:lookup_config).
45
Id = ets:new(my_int_eval_table, [private]),
55
Pid = spawn_link(?MODULE, echo, [self(),Term]),
57
{result,Pid,Term} -> ok;
58
Other -> {bad_response,Other}
64
Parent ! {result,self(),Term}.
69
42 = Fun(number(2), number(40)),
70
12 = apply(Fun, [number(7),number(5)]),
74
[a] = Mod:my_subtract(same([a,b,c]), same([b,c])),
75
[a,b] = Mod:Func(same([a,b,c]), same([c])),
76
[a,b,d] = ?MODULE:Func(same([a,b,c,d]), same([c])),
77
[d,e] = apply(Mod, Func, [same([d,e,f]), same([f])]),
78
[3] = apply(?MODULE, Func, [same([3,4]),same([4])]),
80
%% This is obsolete, but it should work anyway.
81
HomeMadeFun = {?MODULE,my_subtract},
82
[a] = HomeMadeFun(same([a,x,c]), same([x,c])),
83
[x] = apply(HomeMadeFun, [[x,y],[y,z]]),
87
number(X) -> {number,X}.
89
func() -> my_subtract.
92
my_subtract(X, Y) -> X -- Y.
97
{a,ball} = (catch throw_a_ball()),
108
case catch lists:filter(Fun, [a]) of
109
{'EXIT', {_, exit}} ->
115
lists:filter(Fun, [a]).
119
external_call_test(Data) ->
120
{'EXIT',{undef,[{?MODULE,not_exported,[42,Data]}|_]}} =
121
(catch ?MODULE:not_exported(42, Data)),
122
{yes,Data} = i_am_exported(Data),
123
{yes,Data} = ?MODULE:i_am_exported(Data),
125
%% Excercise the function cache in the interpreter.
127
{ok,Data,[a,b]} = not_exported(Data, [a,b]),
128
{yes,Data} = i_am_exported(Data),
129
{ok,Data,[a,b]} = not_exported(Data, [a,b]),
130
{'EXIT',{undef,[{?MODULE,not_exported,[7,Data]}|_]}} =
131
(catch ?MODULE:not_exported(7, Data)),
132
{yes,Data} = ?MODULE:i_am_exported(Data),
135
not_exported(N, D) ->
141
%% The module_info/0,1 functions and list comprehensions (funs).
143
check_exports(Exp) ->
144
%% Check the structure of the export list and that there are more
147
Exp = [{F,A} || {F,A} <- Exp, erlang:is_atom(F), erlang:is_integer(A)],
149
Len when Len > 4 -> ok
152
check_module_info(ModInfo, Exports) ->
153
ModInfo = module_info(),
154
Exports = module_info(exports),
157
%% Testcase apply_interpreted_fun/1.
160
fun() -> perfectly_alright end.
162
give_me_a_fun_0(Term) ->
163
fun() -> {ok,Term} end.
165
give_me_a_fun_1(Min, Max) ->
166
Seq = lists:seq(Min, Max),
167
fun (L) when list(L) ->
168
[Info || {Key,Info} <- L, lists:member(Key, Seq)];
170
L = tuple_to_list(T),
171
F = fun({Key,Info}) ->
172
case lists:member(Key, Seq) of
177
list_to_tuple(lists:map(F, L))
180
give_me_a_bad_fun() ->
181
fun(Arg) -> erlang:error(Arg) end.
185
do_apply(Fun, Arg) ->
189
please_call_exit(Reason) ->
190
put(asked_to_call_exit, Reason),
191
put(will_call_my_good_friend, ''),
192
Res = int_eval_SUITE:applier(?MODULE, i_will_do_the_exit, [Reason]),
194
%% We don't want a tail-recursive call above.
195
io:format("Returned from exit/1 -- how strange\n").
197
i_will_do_the_exit(Reason) ->
213
g({error, Reason}) ->
214
erlang:error(Reason);
217
g({throw, Reason}) ->
218
erlang:throw(Reason);
226
lists:map(fun(X) when N==X ->
234
a = if (false orelse a) =:= a -> a; true -> b end,
236
{'EXIT',{{bad_filter,a},_}} =
237
(catch {a, [X || X <- [1,2,3], _ = F1()]}),
238
F2 = fun() -> << 3:8 >> end,
239
{'EXIT',{{bad_filter,<<3>>},_}} =
240
(catch {a, << << X >> || << X >> <= << 7:8 >>,_ = F2() >>}),
241
{'EXIT',{{bad_generator,a},_}} =
242
(catch {a, [X || X <- a]}),
243
{'EXIT',{{bad_generator,b},_}} =
244
(catch {a, << <<X>> || << X >> <= b >>}),