Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix compile forms error when mock up both behaviour_info and its callback modules (by filter out option) #63

Closed
wants to merge 2 commits into from

2 participants

@shino

When mock up both behaviour_info and its callback modules,
an error(precisely speaking, a waning) occurs when compiling
a callback module to backup it.

  1. When compiling a callback module, compiler can not find behaviour_info/1 since it is already mocked away.
  2. If warnings_as_errors exists in compile options, the warning turns into an error.

In this pull request, I filter out the warnings_as_errors option
when backup original module.
I think this has no drawbacks because warnings are treated before
eunit runs.

PS: #64 is an altenative fix for the same error.

@eproxus
Owner

The test case would pass if written like this:

meck_behaviour_info_module_test() ->
    ?assertEqual(ok, meck:new(meck_test_behaviour_info_module), [passthrough]),
    ?assertEqual(ok, meck:new(meck_test_behaviour_callback_module)),
    ?assertEqual(ok, meck:unload(meck_test_behaviour_info_module)),
    ?assertEqual(ok, meck:unload(meck_test_behaviour_callback_module)).

I think this is an okay prerequisite, is it not?

Another modification would be to change meck_mod to return a full list of compilation errors instead of just error to help debug such errors.

@shino

I think this is an okay prerequisite, is it not?

It's nice! Tests run and succeed with passthrough.
Thank you for so simple advice!

Close this issue because it's useless.

Thanks again.

@shino shino closed this
@shino

Another modification would be to change meck_mod to return a full list
of compilation errors instead of just error to help debug such errors.

Looking for the cause of this error was rather troublesome.
I will try this modification when I have time :-)

P.S.
I found you fixed already 60e5734 . Thanks once more :-)

@eproxus
Owner

5bc12e4 will show more compilation errors than before, it's in 0.7.2.

@shino

Oops, commit hash in my comment were wrong...
Thanks for right commit hash.

@eproxus
Owner

No problem, just let me know if you have any additional issues with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
9 src/meck_mod.erl
@@ -113,6 +113,13 @@ load_binary(Name, Binary) ->
% parse transforms have already been applied to the abstract code in the
% module, and often are not always available when compiling the forms, so
% filter them out of the options
+% When mock up a module declaring behaviour, warnings are emitted in
+% compiling its callback module. With warnings_as_errors in compiler
+% options, meck:new fails by the error.
filter_options (Options) ->
- lists:filter(fun({parse_transform,_}) -> false; (_) -> true end, Options).
+ lists:filter(fun({parse_transform,_}) -> false;
+ (warnings_as_errors) -> false;
+ (_) -> true
+ end,
+ Options).
View
7 test/meck_test_behaviour_callback_module.erl
@@ -0,0 +1,7 @@
+-module(meck_test_behaviour_callback_module).
+
+-export([a/0]).
+
+-behaviour(meck_test_behaviour_info_module).
+
+a() -> ok.
View
6 test/meck_test_behaviour_info_module.erl
@@ -0,0 +1,6 @@
+-module(meck_test_behaviour_info_module).
+
+-export([behaviour_info/1]).
+
+behaviour_info(callbacks) ->
+ [{a, 0}].
View
6 test/meck_tests.erl
@@ -877,6 +877,12 @@ meck_parametrized_module_passthrough_test() ->
?assertEqual({mecked, var2}, Object:var2()),
?assertEqual(ok, meck:unload(meck_test_parametrized_module)).
+meck_behaviour_info_module_test() ->
+ ?assertEqual(ok, meck:new(meck_test_behaviour_info_module)),
+ ?assertEqual(ok, meck:new(meck_test_behaviour_callback_module)),
+ ?assertEqual(ok, meck:unload(meck_test_behaviour_info_module)),
+ ?assertEqual(ok, meck:unload(meck_test_behaviour_callback_module)).
+
%%==============================================================================
%% Internal Functions
%%==============================================================================
Something went wrong with that request. Please try again.