-
-
Notifications
You must be signed in to change notification settings - Fork 231
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
With a bogus test instantiator, meck fails with {error, enoent} in meck_cover:read_cover_file/1 #114
Comments
So, the question is, does it do this between |
Good question. My Erlang-fu isn't strong enough to figure that out yet. I figured that -- maybe -- rebar is calling eunit:test(), which is failing, but then there's a race between rebar changing the working directory, and meck's gen_server being torn down (it's usually torn down in unload, right, but in this instance, it's doing it because of the error?). |
Sorry for the late reply. I guess the error does not appear if you fix the test (i.e. remove the "is not a test" error)? |
Correct. When it is a test, whether it passes or fails, then it cleans up properly. It looks like a race condition in tear down, but only in this case (or maybe in similar cases). (tbh, I'm not that bothered about it now, since I've figured it out, and Google returns this issue as the top result for the error message, so if it's a PITA to fix, don't worry about it, and thanks for all that you've done with meck). |
I think the correct way to pass an argument to a test is something like this (taken from {foreach, fun setup/0, fun teardown/1,
[{with, [T]} || T <- [fun ?MODULE:one/1,
fun ?MODULE:two/1]]} It's kind off ugly, but the only way to tell EUnit to pass an argument to each test case. My theory is that the setup function is run before EUnit examines your test case fun and thus fails, bringing Meck down with it. This is "expected" behaviour. The problem is more or less the design of EUnit in that it doesn't verify the test specification before running any of the functions (which means cleanup is also broken etc.). |
Closing because of inactivity. Please re-open if it is still an issue. |
I get the same error with the following test (with no "is not a test" error):
Installed meck today, any hints? |
Cannot really reproduce this. A freshly created rebar app with nothing but the exact same test case you posted and Meck as a dependency works for me.
|
It seems to be something coming from other tests - I could not reproduce it in a separate module either. Need to investigate. |
I came across this today. I had three modules: module 'a' had code and tests, module 'b' had code, module b_tests was tests for 'b' (e.g. 'a', 'b', 'b_tests'). Module b was mecking out module a. Once I removed the tests from module a and put them in a_tests, the problem went away. |
@cwmaguire Did you mock module |
No, I didn't mock |
Hmm, the assumption that |
It looks like I have found a way to reproduce that enoent: |
Having a similar issue. It looks like some weird interaction between
Commenting out the above line does not cause meck to crash. It looks like the latest version of rebar does things quite differently, so I will try to investigate more. |
@robertoaloi So, ideally, Meck should only mess with cover data on mocking and unloading modules (which should happen inside tests) and Rebar (hopefully) only after tests have been run. If you've found a bug here, I would be interested to hear about it. 😄 |
I've run into this a couple of times. Each time has been due to using an So I don't think meck is to blame, but it'd be nice if there was a more obvious error message! |
@qrilka @robertoaloi So, after some more investigation I think I figured out what happens. You are mocking And this is really the strange part. If I look into the |
@eproxus the code is on github, I don't do anything special myself and I didn't dig deeper into this issue so I don't have any other details on this |
+1 |
Turns out that we can't rely on the current working directory always staying the same. The real world scenario is when Meck is cleaning up after the last failed test case and Rebar changes directory from the .eunit folder to the project root. Meck now stores absolute paths to cover backup files.
This issue should be fixed now. The solution was pretty simple, just save the absolute path of cover files instead of relying on the current directory always staying the same. |
Awesome stuff, thanks Adam! |
If I have a test instantiator looking like this:
...eunit reports "result from instantiator foo_tests:'-all_test_/0-fun-2-'/1 is not a test", which is fair enough, but then meck fails as follows:
(I've ellided the line numbers, because this I've been hacking on it and don't want to confuse anyone).
Further investigation seems to show
meck_cover:read_cover_file
being called with a relative path"foo_meck_original.coverdata"
, but withfile:get_cwd()
returning"/path/to/my/apps/foo"
, rather than"/path/to/my/apps/foo/.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 inmeck_proc:restore_original
instead.This is using
rebar eunit
, by the way. It looks like either eunit or (more likely) rebar are changing cwd underneath meck's feet.The text was updated successfully, but these errors were encountered: