Skip to content

Commit

Permalink
Make sure both mfa and fun m:f/a are tested
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Jul 24, 2023
1 parent 7f69ce8 commit 7eafb23
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions integration_test/dummy_scenario.erl
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
-required_variable([
%% var2 must be positively verified by the test_verification_function/1 function.
%% verification function must be supplied as an mfa of the format
%% '{module, function, arity}' format. Note that it must be an exported function.
%% otherwise it will not pass compilation.
%% '{module, function, arity}', or a fun of the format `fun module:function/arity`.
%% Note that it must be an exported function, otherwise it will not pass compilation.
#{name => var2, description => "description2", default_value => def2,
verification => {?MODULE, test_verification_function, 1}},
#{name => var3, description => "description3", default_value => def3,
Expand Down
13 changes: 11 additions & 2 deletions test/amoc_config_attributes_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#{name => var3, description => "var3", default_value => def3,
verification => [def3, another_atom]},
#{name => var4, description => "var4", default_value => def4,
verification => {?MODULE, verify_value, 1}}
verification => {?MODULE, verify_value, 1}},
#{name => var4b, description => "var4b", default_value => def4b,
verification => fun ?MODULE:verify_value/1}
]).
-required_variable(#{name => var5, description => "var5", default_value => def5,
update => read_only}).
Expand Down Expand Up @@ -57,6 +59,8 @@ get_module_attributes(_) ->
verification => [def3, another_atom]},
#{name => var4, description => "var4", default_value => def4,
verification => {?MODULE, verify_value, 1}},
#{name => var4b, description => "var4b", default_value => def4b,
verification => fun ?MODULE:verify_value/1},
#{name => var5, description => "var5", default_value => def5,
update => read_only},
#{name => var6, description => "var6", default_value => def6,
Expand Down Expand Up @@ -84,6 +88,8 @@ get_module_configuration(_) ->
%% 'one_of_function' test case.
#module_parameter{name = var4, mod = ?MODULE, value = def4,
verification_fn = VerifyValueFN, update_fn = read_only},
#module_parameter{name = var4b, mod = ?MODULE, value = def4b,
verification_fn = VerifyValueFN, update_fn = read_only},
#module_parameter{name = var5, mod = ?MODULE, value = def5,
verification_fn = VerificationNone, update_fn = read_only},
#module_parameter{name = var6, mod = ?MODULE, value = def6,
Expand All @@ -100,6 +106,8 @@ errors_reporting(_) ->
ValidParam3 = #{name => valid_var3, description => "var3", default_value => def3,
verification => [def3, another_atom]},
InvalidParam4 = #{name => invalid_var4, description => "var4",
verification => {erlang, not_exported_function, 1}},
InvalidParam4b = #{name => invalid_var4b, description => "var4b",
verification => fun erlang:not_exported_function/1},
InvalidParam5 = #{name => invalid_var5, description => "var5",
update => invalid_update_method},
Expand All @@ -108,14 +116,15 @@ errors_reporting(_) ->
InvalidParam7 = #{name => invalid_var7, description => "var7",
update => fun update_value/2}, %% local function
Attributes = [InvalidParam0, InvalidParam1, InvalidParam2, ValidParam3,
InvalidParam4, InvalidParam5, InvalidParam6, InvalidParam7],
InvalidParam4, InvalidParam4b, InvalidParam5, InvalidParam6, InvalidParam7],
{error, invalid_attribute_format, Reason} =
amoc_config_attributes:process_module_attributes(?MODULE, Attributes),
?assertEqual(
[{InvalidParam0, invalid_attribute},
{InvalidParam1, invalid_attribute},
{InvalidParam2, invalid_verification_method},
{InvalidParam4, verification_method_not_exported},
{InvalidParam4b, verification_method_not_exported},
{InvalidParam5, invalid_update_method},
{InvalidParam6, update_method_not_exported},
{InvalidParam7, update_method_not_exported}],
Expand Down
2 changes: 2 additions & 0 deletions test/amoc_config_scenario_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
-required_variable(#{name => var2, description => "var2", default_value => def2}).
-override_variable(#{name => var2, description => "var2", default_value => val2,
verification => [def2, val2], update => {?MODULE, update_fn, 2}}).
-override_variable(#{name => var3, description => "var3", default_value => def3,
update => fun ?MODULE:update_fn/2}).
-override_variable(#{name => var3, description => "var3", default_value => def3,
update => {?MODULE, update_fn, 2}}).

Expand Down

0 comments on commit 7eafb23

Please sign in to comment.