summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2018-04-20 18:31:26 -0700
committerGitHub <noreply@github.com>2018-04-20 18:31:26 -0700
commitd4c529a4702128761f7919a81b7ce88bf39809d9 (patch)
tree14100e1e27189f9eb6ed89301d9d1b21ac640779
parent1a07624457fec031e248589e3324f275bc318beb (diff)
parent543fe579a6d7c71fb4ed6a898540b573f6255dd0 (diff)
Merge pull request #1759 from ferd/fix-erlopts-test-profile
Fix precedence rules of erl_opts for test profile
-rw-r--r--src/rebar3.erl6
-rw-r--r--test/rebar_profiles_SUITE.erl32
2 files changed, 37 insertions, 1 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 80b4e4d..eb5ad58 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -389,7 +389,11 @@ state_from_global_config(Config, GlobalConfigFile) ->
rebar_state:providers(rebar_state:new(GlobalConfig3, Config), GlobalPlugins).
test_state(State) ->
- ErlOpts = rebar_state:get(State, erl_opts, []),
+ %% Fetch the test profile's erl_opts only
+ Opts = rebar_state:opts(State),
+ Profiles = rebar_opts:get(Opts, profiles, []),
+ ProfileOpts = proplists:get_value(test, Profiles, []),
+ ErlOpts = proplists:get_value(erl_opts, ProfileOpts, []),
TestOpts = safe_define_test_macro(ErlOpts),
[{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}].
diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl
index ddc3cf1..512832a 100644
--- a/test/rebar_profiles_SUITE.erl
+++ b/test/rebar_profiles_SUITE.erl
@@ -28,6 +28,7 @@
test_profile_erl_opts_order_4/1,
test_profile_erl_opts_order_5/1,
test_erl_opts_debug_info/1,
+ test_profile_erl_opts_precedence/1,
first_files_exception/1]).
-include_lib("common_test/include/ct.hrl").
@@ -52,6 +53,7 @@ all() ->
test_profile_erl_opts_order_4,
test_profile_erl_opts_order_5,
test_erl_opts_debug_info,
+ test_profile_erl_opts_precedence,
first_files_exception].
init_per_suite(Config) ->
@@ -527,6 +529,36 @@ test_erl_opts_debug_info(_Config) ->
no_debug_info,b,c,{debug_info,{mod,"123"}}])),
ok.
+test_profile_erl_opts_precedence(Config) ->
+ AppDir = ?config(apps, Config),
+ Name = rebar_test_utils:create_random_name("profile_new_key_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ RebarConfig = [{erl_opts, [no_debug_info]},
+ {profiles, [
+ {test, [{erl_opts, [debug_info, {d,'HI'}]}]},
+ {other, [{erl_opts, [debug_info, {d,'HI'}]}]}
+ ]}],
+ {ok, State1} = rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["as", "test", "compile"], return
+ ),
+ {ok, State2} = rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["as", "other", "compile"], return
+ ),
+ {ok, State3} = rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["compile"], return
+ ),
+ Opts1 = rebar_state:opts(State1),
+ Opts2 = rebar_state:opts(State2),
+ Opts3 = rebar_state:opts(State3),
+ ErlOpts1 = rebar_opts:erl_opts(Opts1),
+ ErlOpts2 = rebar_opts:erl_opts(Opts2),
+ ErlOpts3 = rebar_opts:erl_opts(Opts3),
+ ?assertEqual([{d,'TEST'}, debug_info, {d,'HI'}], ErlOpts1),
+ ?assertEqual([debug_info, {d,'HI'}], ErlOpts2),
+ ?assertEqual([], ErlOpts3),
+ ok.
+
first_files_exception(_Config) ->
RebarConfig = [{erl_first_files, ["c","a","b"]},
{mib_first_files, ["c","a","b"]},