summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorViacheslav V. Kovalev <kovyl2404@gmail.com>2015-04-21 22:26:20 +0300
committerViacheslav Kovalev <kovyl2404@gmail.com>2015-04-22 11:16:38 +0300
commit83d738a829fae4547776c87c3c4689cf17e69541 (patch)
tree390ff27d84056ac31b47e2c903d99b121a73ed95 /test
parent381c6f4779a93b50308f2cc86de8a19b23ebcee5 (diff)
Implement some test on profiles deduplication
Diffstat (limited to 'test')
-rw-r--r--test/rebar_profiles_SUITE.erl91
-rw-r--r--test/rebar_utils_SUITE.erl24
2 files changed, 113 insertions, 2 deletions
diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl
index 6288053..d1d10c6 100644
--- a/test/rebar_profiles_SUITE.erl
+++ b/test/rebar_profiles_SUITE.erl
@@ -7,7 +7,10 @@
all/0,
profile_new_key/1,
profile_merge_keys/1,
+ explicit_profile_deduplicate_deps/1,
+ implicit_profile_deduplicate_deps/1,
profile_merges/1,
+ same_profile_deduplication/1,
add_to_profile/1,
add_to_existing_profile/1,
profiles_remain_applied_with_config_present/1,
@@ -22,6 +25,8 @@
all() ->
[profile_new_key, profile_merge_keys, profile_merges,
+ explicit_profile_deduplicate_deps, implicit_profile_deduplicate_deps,
+ same_profile_deduplication,
add_to_profile, add_to_existing_profile,
profiles_remain_applied_with_config_present,
test_profile_applied_at_completion,
@@ -95,6 +100,67 @@ profile_merge_keys(Config) ->
,{dep, "a", "1.0.0"}
,{dep, "b", "2.0.0"}]}).
+explicit_profile_deduplicate_deps(Config) ->
+ AppDir = ?config(apps, Config),
+
+ AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
+ ,{"a", "2.0.0", []}
+ ,{"b", "1.0.0", []}
+ ,{"b", "2.0.0", []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
+
+ Name = rebar_test_utils:create_random_name("explicit_profile_deduplicate_deps_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ FooDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []},
+ {"b", "2.0.0", []}])),
+ BarDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
+
+ RebarConfig = [{profiles,
+ [{foo,
+ [{deps, FooDeps}]},
+ {bar,
+ [{deps, BarDeps}]}]}],
+
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["as", "bar,foo,bar", "compile"], {ok, [{app, Name}
+ ,{dep, "a", "1.0.0"}
+ ,{dep, "b", "1.0.0"}]}).
+
+implicit_profile_deduplicate_deps(Config) ->
+ AppDir = ?config(apps, Config),
+
+ AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
+ ,{"a", "2.0.0", []}
+ ,{"b", "1.0.0", []}
+ ,{"b", "2.0.0", []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]),
+
+ Name = rebar_test_utils:create_random_name("implicit_profile_deduplicate_deps_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ TestDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []},
+ {"b", "2.0.0", []}])),
+ ProfileDeps = rebar_test_utils:top_level_deps(
+ rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])),
+
+ RebarConfig = [{profiles,
+ [{test,
+ [{deps, TestDeps}]},
+ {bar,
+ [{deps, ProfileDeps}]}]}],
+
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["as", "test,bar", "eunit"], {ok, [{app, Name}
+ ,{dep, "a", "1.0.0"}
+ ,{dep, "b", "2.0.0"}]}).
+
+
profile_merges(_Config) ->
RebarConfig = [{test1, [{key1, 1, 2}, key2]},
{test2, "hello"},
@@ -127,6 +193,31 @@ 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}, key1]},
+ {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)),
+ %% Combine lists
+ ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]),
+ lists:sort(rebar_state:get(State1, test1))),
+
+
+ %% Check that a newvalue of []/"" doesn't override non-string oldvalues
+ ?assertEqual([key3], rebar_state:get(State1, test3)),
+ ?assertEqual([foo, bar], rebar_state:get(State1, test2)).
+
+
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..9b7bca1 100644
--- a/test/rebar_utils_SUITE.erl
+++ b/test/rebar_utils_SUITE.erl
@@ -21,7 +21,9 @@
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,
+ trivial_umerge/1,
+ three_tuple_umerge/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -29,7 +31,10 @@
all() ->
- [{group, args_to_tasks}].
+ [{group, args_to_tasks},
+ trivial_umerge,
+ three_tuple_umerge
+ ].
groups() ->
[{args_to_tasks, [], [empty_arglist,
@@ -118,3 +123,18 @@ special_task_do(_Config) ->
"do",
"bar,",
"baz"]).
+
+trivial_umerge(_Config) ->
+ New = [{key, foo}],
+ Old = [{key, bar}],
+ Result = rebar_utils:tup_umerge(New, Old),
+ ?assertEqual([{key, foo}], Result).
+
+three_tuple_umerge(_Config) ->
+ New = rebar_utils:tup_sort([{d, foo, true}, {d, bar, true}]),
+ Old = rebar_utils:tup_sort([{d, foo, false}, {d, bar, true}]),
+ Result = rebar_utils:tup_umerge(New, Old),
+ ?assertEqual(
+ rebar_utils:tup_sort([{do, foo, true}, {d, bar, true}]),
+ Result
+ ).