eproxus/meck

Can not meck ets module.

Closed this issue · 4 comments

my_test() ->
meck:new(ets, [unstick]),
meck:unload(ets),
ok.

m: my_test (module 'm')...skipped
undefined
unexpected termination of test process
::{compile_forms,{error,[],
[{"ets.erl",
[{50,erl_lint,
{deprecated_builtin_type,{...},...}}]}]}}

Can you replace the call to meck:new(ets, [unstick]) with this code and paste the whole error message?

    io:format(user, "MECK ERROR: ~p~n", [(catch meck:new(ets, [unstick]))]).

I suspect this is because Ets has built-in functions (functions coded in C) that Meck cannot deal with in runtime. This is a limitation of Meck that unfortunately cannot be fixed (or at least it is very hard).

MECK ERROR: {'EXIT',
                {{compile_forms,
                     {error,[],
                         [{"ets.erl",
                           [{50,erl_lint,
                             {deprecated_builtin_type,
                                 {tid,0},
                                 {ets,tid},
                                 "OTP 18.0"}}]}]}},
                 [{meck_proc,start,
                      [ets,[unstick]],
                      [{file,"src/meck_proc.erl"},{line,96}]},
                  {cluster_server_info,other_test,0,
                      [{file,"src/cluster/cluster_server_info.erl"},
                       {line,61}]},
                  {eunit_test,'-mf_wrapper/2-fun-0-',2,
                      [{file,"eunit_test.erl"},{line,266}]},
                  {eunit_test,run_testfun,1,
                      [{file,"eunit_test.erl"},{line,65}]},
                  {eunit_proc,run_test,1,[{file,"eunit_proc.erl"},{line,506}]},
                  {eunit_proc,with_timeout,3,
                      [{file,"eunit_proc.erl"},{line,331}]},
                  {eunit_proc,handle_test,2,
                      [{file,"eunit_proc.erl"},{line,489}]},
                  {eunit_proc,tests_inorder,3,
                      [{file,"eunit_proc.erl"},{line,431}]}]}}
cluster_server_info: other_test (module 'cluster_server_info')...*skipped*
undefined
*unexpected termination of test process*
::{compile_forms,{error,[],
                        [{"ets.erl",
                          [{50,erl_lint,
                            {deprecated_builtin_type,{...},...}}]}]}}

Can reproduce on 17.5, but not on R16B03-1. One thing to note is that Meck is internally using ets, so mocking ets could be tricky/impossible in the first place. For example (R16B03-1):

17> meck:new(ets, [unstick]).
ok
18> meck:expect(ets, i, 0, ok).
ok
19> ets:i().

=ERROR REPORT==== 13-May-2015::10:13:33 ===
** Generic server ets_meck terminating
** Last message in was {get_result_spec,i,[]}
** When Server state == {state,ets,[...]}
** Reason for termination ==
** {undef,[{ets,match_spec_run,[[{[]}],<<>>],[]},
           {meck_args_matcher,match,2,
                              [{file,"src/meck_args_matcher.erl"},{line,85}]},
           ...]}

If you want to mock away ets usage, I'd suggest mocking the module that uses ets instead of ets itself.

Closing because of inactivity. Please re-open if it is still an issue!