Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When cover is enabled in rebar.config after test meck failed with enoent #111

Closed
jonasrichard opened this issue Aug 27, 2013 · 6 comments
Closed
Labels

Comments

@jonasrichard
Copy link

```=ERROR REPORT==== 27-Aug-2013::13:36:22 ===
** Generic server my_module_meck terminating
** Last message in was {'EXIT',<0.150.0>,normal}
** When Server state == {state,my_module,
                               {dict,0,16,16,8,80,48,
                                     {[],[],[],[],[],[],[],[],[],[],[],[],[],
                                      [],[],[]},
                                     {{[],[],[],[],[],[],[],[],[],[],[],[],[],
                                       [],[],[]}}},
                               true,[],
                               {{"/xxxxxx/apps/my_app/.eunit/my_module.beam",
                                 "my_module.coverdata",
                                 [{outdir,".eunit"},
                                  debug_info,
                                  {d,'TEST'},
                                  fail_on_warning,debug_info,
                                  {i,"../"},
                                  {i,"include"}]},
                                <<70,79,82,49```

The test using:

    meck:new(my_module, [passthrough]).
    meck:expect(my_module, time, ...).
    meck:unload(my_module).
    meck:new(my_module).

The reason behind the unload/new again is to leave the module loaded. Otherwise consecutive tests will fail in error:undef my_module:time/1.
Am I doing something wrong or meck is confused?

@eproxus
Copy link
Owner

eproxus commented Aug 27, 2013

Could you attach a (preferably) minimal test module so I can reproduce this?

@jonasrichard
Copy link
Author

I managed to reproduce but the bug is just partly related to the cover thing, it came up with lager_transform only.

rebar.config

{erl_opts, [debug_info,
            {parse_transform, lager_transform}]}.

{cover_enabled, true}.

{deps, [
    {lager, ".*",
        {git, "git://github.com/basho/lager.git", {tag, "2.0.0"}}},
    {meck, ".*",
        {git, "git://github.com/eproxus/meck.git", {tag, "0.7.2"}}}
]}.

src/meckbug.app.src: just a placeholder in order that rebar starts work

{application, meckbug,
 [
  {description, ""},
  {vsn, "1"},
  {registered, []},
  {applications, [
                  kernel,
                  stdlib
                 ]},
  {mod, { meckbug_app, []}},
  {env, []}
 ]}.

src/my_module.erl:

-module(my_module).

-export([calculate/2]).

calculate(A, B) ->
    lager:info("Addig ~p and ~p", [A, B]),   %% without this, everything is fine
    A + B.

src/my_other.erl:

-module(my_other).

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.

-ifdef(TEST).

calculate_test() ->
    meck:new(my_module, [passthrough]),
    meck:expect(my_module, calculate,
        fun(1, 2) ->
            5
        end),

    ?debugVal(my_module:calculate(1, 2)),
    ?assertEqual(5, my_module:calculate(1, 2)),

    meck:unload(my_module),
    meck:new(my_module).

-endif.

./rebar compile
./rebar eunit apps=meckbug

So the problem is to meck:new() a module which is lager transformed.

@rlipscombe
Copy link
Contributor

I'm seeing the same problem. Was there any resolution?

@rlipscombe
Copy link
Contributor

*Ignore this, this is a separate issue #114 *

Further investigation seems to show meck_cover:read_cover_file being called with a relative path "my_module_meck_original.coverdata", but with file:get_cwd() returning "/path/to/my/apps/app", rather than "/path/to/my/apps/app/.eunit".

If I hack on meck_cover:read_cover_file to make it also look in the .eunit folder, it works -- at least until it barfs in meck_proc:restore_original instead.

@shino
Copy link
Contributor

shino commented Mar 28, 2014

@jonasrichard You call meck:new(my_module) again at the end of my_other:calculate_test/0.
It seems unnecessary, isn't it? When I use meck/cover/lager at once, I encountered the same error but went well after proper use of meck:unload/0,1.

@jonasrichard
Copy link
Author

Yes, it seems that removing extra meck:new solves the problem. I wrote that because somehow I experienced that after meck:unload I wasn't able to use the non-mocked module.

    meck:unload(my_module),
    my_module:calculate(1, 2).
    %%meck:new(my_module).

After changing the eunit test I didn't get any error, and I am able to use my_module. So I am closing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants