summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorViacheslav V. Kovalev <kovyl2404@gmail.com>2015-04-22 14:44:45 +0300
committerViacheslav V. Kovalev <kovyl2404@gmail.com>2015-04-22 14:44:45 +0300
commit0b682e364da25287aa45784150702013f4c4aee0 (patch)
treea8de73ae7fccc5e6d1eddb93a39b88812cd92c97
parentb725711d638bef39aa6a2685c3dabd57c80a8024 (diff)
parent82b0d4b7b29fe5d33148022be28eab55320f47a9 (diff)
Merge branch 'app-discover-profile-duplication' of https://github.com/kovyl2404/rebar3 into app-discover-profile-duplication
Conflicts: test/rebar_profiles_SUITE.erl
-rw-r--r--src/rebar_state.erl1
-rw-r--r--src/rebar_utils.erl15
-rw-r--r--test/rebar_profiles_SUITE.erl70
-rw-r--r--test/rebar_utils_SUITE.erl15
4 files changed, 96 insertions, 5 deletions
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 22e5497..f73370b 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -231,7 +231,6 @@ do_deduplicate([Head | Rest], Acc) ->
merge_opts(Profile, NewOpts, OldOpts) ->
Opts = merge_opts(NewOpts, OldOpts),
-
case dict:find(deps, NewOpts) of
{ok, Value} ->
dict:store({deps, Profile}, Value, Opts);
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index bc2e4ac..76be9a8 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -257,7 +257,20 @@ tup_sort(List) ->
tup_umerge([], Olds) ->
Olds;
tup_umerge([New|News], Olds) ->
- lists:reverse(umerge(News, Olds, [], New)).
+ reverse_deduplicate( umerge(News, Olds, [], New) ).
+
+reverse_deduplicate(List) ->
+ lists:reverse( do_deduplicate(lists:reverse(List), []) ).
+
+do_deduplicate([], Acc) ->
+ Acc;
+do_deduplicate([Value | Rest], Acc) ->
+ case lists:member(Value, Acc) of
+ true ->
+ do_deduplicate(Rest, Acc);
+ false ->
+ do_deduplicate(Rest, [Value | Acc])
+ end.
%% This is equivalent to umerge2_2 in the stdlib, except we use the expanded
%% value/key only to compare
diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl
index e5d0b20..f812793 100644
--- a/test/rebar_profiles_SUITE.erl
+++ b/test/rebar_profiles_SUITE.erl
@@ -11,6 +11,7 @@
implicit_profile_deduplicate_deps/1,
profile_merges/1,
same_profile_deduplication/1,
+ stack_deduplication/1,
add_to_profile/1,
add_to_existing_profile/1,
profiles_remain_applied_with_config_present/1,
@@ -25,7 +26,8 @@
all() ->
[profile_new_key, profile_merge_keys, profile_merges,
- explicit_profile_deduplicate_deps, implitit_profilededuplicate_deps,
+ explicit_profile_deduplicate_deps, implicit_profile_deduplicate_deps,
+ same_profile_deduplication, stack_deduplication,
add_to_profile, add_to_existing_profile,
profiles_remain_applied_with_config_present,
test_profile_applied_at_completion,
@@ -192,6 +194,72 @@ profile_merges(_Config) ->
[{key5, false}, {key5, true}] = rebar_state:get(State1, test5),
[{key6, true}, {key6, false}] = rebar_state:get(State1, test6).
+same_profile_deduplication(_Config) ->
+ RebarConfig = [{test1, [{key1, 1, 2}, key2]},
+ {test2, [foo]},
+ {test3, [key3]},
+ {profiles,
+ [{profile1,
+ [{test1, [{key3, 5}, {key2, "hello"}]},
+ {test2, [bar]},
+ {test3, []}
+ ]}]
+ }],
+ State = rebar_state:new(RebarConfig),
+ State1 = rebar_state:apply_profiles(State, [profile1, profile1, profile1]),
+
+ ?assertEqual([default, profile1], rebar_state:current_profiles(State1)),
+ Test1 = rebar_state:get(State1, test1),
+
+ %% Combine lists
+ ?assertEqual(lists:sort([key2, {key1, 1, 2}, {key3, 5}, {key2, "hello"}]),
+ lists:sort(Test1)),
+
+ %% Key2 from profile1 overrides key2 from default profile
+ ?assertEqual("hello", proplists:get_value(key2, Test1)),
+
+ %% Check that a newvalue of []/"" doesn't override non-string oldvalues
+ ?assertEqual([key3], rebar_state:get(State1, test3)),
+ ?assertEqual([bar, foo], rebar_state:get(State1, test2)).
+
+stack_deduplication(_Config) ->
+ RebarConfig = [
+ {test_key, default},
+ {test_list, [ {foo, default} ]},
+ {profiles, [
+ {a, [
+ {test_key, a},
+ {test_list, [ {foo, a} ]}
+ ]},
+ {b, [
+ {test_key, b},
+ {test_list, [ {foo, b} ]}
+ ]},
+ {c, [
+ {test_key, c},
+ {test_list, [ {foo, c} ]}
+ ]},
+ {d, [
+ {test_key, d},
+ {test_list, [ {foo, d} ]}
+ ]},
+ {e, [
+ {test_key, e},
+ {test_list, [ {foo, e} ]}
+ ]}
+ ]}
+ ],
+ State = rebar_state:new(RebarConfig),
+ State1 = rebar_state:apply_profiles(State, [a, b, c, d, e, a, e, b]),
+ ?assertEqual(b, rebar_state:get(State1, test_key)),
+
+ TestList = rebar_state:get(State1, test_list),
+ ?assertEqual(
+ [{foo, b}, {foo, e}, {foo, a}, {foo, d}, {foo, c}, {foo, default} ],
+ TestList
+ ),
+ ?assertEqual(b, proplists:get_value(foo, TestList)).
+
add_to_profile(_Config) ->
RebarConfig = [{foo, true}, {bar, false}],
State = rebar_state:new(RebarConfig),
diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl
index e9b32e2..98e7e58 100644
--- a/test/rebar_utils_SUITE.erl
+++ b/test/rebar_utils_SUITE.erl
@@ -21,7 +21,8 @@
task_with_flag_with_trailing_comma/1,
task_with_flag_with_commas/1,
task_with_multiple_flags/1,
- special_task_do/1]).
+ special_task_do/1,
+ tup_umerge_deduplication/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -29,7 +30,9 @@
all() ->
- [{group, args_to_tasks}].
+ [{group, args_to_tasks},
+ tup_umerge_deduplication
+ ].
groups() ->
[{args_to_tasks, [], [empty_arglist,
@@ -118,3 +121,11 @@ special_task_do(_Config) ->
"do",
"bar,",
"baz"]).
+
+tup_umerge_deduplication(_Config) ->
+ Old = [{key,c},{key,b},{key,a}],
+ New = [{key, a}],
+ ?assertEqual(
+ [{key, a}, {key, c}, {key, b}],
+ rebar_utils:tup_umerge(New, Old)
+ ).