Skip to content

Instantly share code, notes, and snippets.

@gliush
Last active August 29, 2015 14:11
Show Gist options
  • Save gliush/12a4fed35df7af21fb21 to your computer and use it in GitHub Desktop.
Save gliush/12a4fed35df7af21fb21 to your computer and use it in GitHub Desktop.
meck fails while running 'meck:expect'

Here's a test project with 2 files that shows the problem.

You need 2 modules

  • in the first module you should have a eunit test
  • in the second module you should meck any function from the first module

When you run eunit, the meck fails at 'meck:expect' with 'undefined' exception.

How to reproduce:

./rebar get-deps
./rebar compile
mkdir -p .eunit
erlc -o .eunit/ *.erl
erl -pa deps/meck/ebin/ -pa .eunit/ -eval "eunit:test([t1,t2])" -s init stop

Diagnostics:

Erlang R16B02 (erts-5.10.3) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.3  (abort with ^G)
1> t2.erl:17:<0.39.0>: before meck:new

t2.erl:19:<0.39.0>: before meck:expect

undefined
*unexpected termination of test process*
::killed

=======================================================
  Failed: 0.  Skipped: 0.  Passed: 1.
One or more tests were cancelled.

=ERROR REPORT==== 16-Dec-2014::11:53:26 ===
** Generic server t1_meck terminating
** Last message in was {'EXIT',<0.39.0>,killed}
** When Server state == {state,t1,
                         [{stop,1},{foo_test_,0},{test,0}],
                         {dict,1,16,16,8,80,48,
                          {[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]},
                          {{[],[],[],[],[],[],[],[],[],[],[],
                            [[{stop,1}|
                              {{stop,1},
                               [{{args_matcher,['_'],<<>>,false},
                                 {meck_exec,#Fun<t2.3.55841443>}}]}]],
                            [],[],[],[]}}},
                         true,[],
                         {false,no_binary},
                         false,
                         {<0.44.0>,{<0.39.0>,#Ref<0.0.0.42>}},
                         []}
** Reason for termination ==
** killed

Though, if checked separately, tests pass:

$ erl -pa deps/meck/ebin/ -pa .eunit/ -eval "eunit:test([t1])" -noshell -s init stop
  Test passed.
$ erl -pa deps/meck/ebin/ -pa .eunit/ -eval "eunit:test([t2])" -noshell -s init stop
t2.erl:17:<0.34.0>: before meck:new

t2.erl:19:<0.34.0>: before meck:expect

  Test passed.
{lib_dirs, ["deps"]}.
{deps_dir, "deps"}.
{deps, [
{meck, "0.*", {git, "git://github.com/eproxus/meck", {branch, "master"}}}
]}.
-module(t1).
-export([ stop/1 ]).
stop(_) -> ok.
-include_lib("eunit/include/eunit.hrl").
foo_test_() -> ?_assertEqual(true, true).
-module(t2).
-export([foo/0]).
foo() -> ok.
-include_lib("eunit/include/eunit.hrl").
lala_test_() ->
{setup,
fun setup_fn/0,
fun cleanup_fn/1,
[ ?_assertEqual(true, true) ]}.
cleanup_fn(_) ->
meck:unload().
setup_fn() ->
?debugFmt("before meck:new~n", []),
meck:new(t1),
?debugFmt("before meck:expect~n", []),
meck:expect(t1, stop, fun(_) -> ok end),
?debugFmt("after meck:expect~n", []),
ok.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment