Skip to content

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
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.