summaryrefslogtreecommitdiff
path: root/test/rebar_deps_SUITE.erl
diff options
context:
space:
mode:
Diffstat (limited to 'test/rebar_deps_SUITE.erl')
-rw-r--r--test/rebar_deps_SUITE.erl160
1 files changed, 91 insertions, 69 deletions
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl
index 24bf2a0..8a3362d 100644
--- a/test/rebar_deps_SUITE.erl
+++ b/test/rebar_deps_SUITE.erl
@@ -7,7 +7,7 @@ all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock,
http_proxy_settings, https_proxy_settings,
http_os_proxy_settings, https_os_proxy_settings,
semver_matching_lt, semver_matching_lte, semver_matching_gt,
- valid_version, {group, git}, {group, pkg}].
+ valid_version, top_override, {group, git}, {group, pkg}].
groups() ->
[{all, [], [flat, pick_highest_left, pick_highest_right,
@@ -47,6 +47,8 @@ init_per_testcase(newly_added_dep, Config) ->
rebar_test_utils:init_rebar_state(Config);
init_per_testcase(sub_app_deps, Config) ->
rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(top_override, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
init_per_testcase(http_proxy_settings, Config) ->
%% Create private rebar.config
Priv = ?config(priv_dir, Config),
@@ -186,27 +188,27 @@ deps(flat) ->
[],
{ok, ["B", "C"]}};
deps(pick_highest_left) ->
- {[{"B", [{"C", "2", []}]},
- {"C", "1", []}],
- [{"C","2"}],
- {ok, ["B", {"C", "1"}]}};
+ {[{"B", [{"C", "2.0.0", []}]},
+ {"C", "1.0.0", []}],
+ [{"C","2.0.0"}],
+ {ok, ["B", {"C", "1.0.0"}]}};
deps(pick_highest_right) ->
- {[{"B", "1", []},
- {"C", [{"B", "2", []}]}],
- [{"B","2"}],
- {ok, [{"B","1"}, "C"]}};
+ {[{"B", "1.0.0", []},
+ {"C", [{"B", "2.0.0", []}]}],
+ [{"B","2.0.0"}],
+ {ok, [{"B","1.0.0"}, "C"]}};
deps(pick_smallest1) ->
- {[{"B", [{"D", "1", []}]},
- {"C", [{"D", "2", []}]}],
- [{"D","2"}],
+ {[{"B", [{"D", "1.0.0", []}]},
+ {"C", [{"D", "2.0.0", []}]}],
+ [{"D","2.0.0"}],
%% we pick D1 because B < C
- {ok, ["B","C",{"D","1"}]}};
+ {ok, ["B","C",{"D","1.0.0"}]}};
deps(pick_smallest2) ->
- {[{"C", [{"D", "2", []}]},
- {"B", [{"D", "1", []}]}],
- [{"D","2"}],
+ {[{"C", [{"D", "2.0.0", []}]},
+ {"B", [{"D", "1.0.0", []}]}],
+ [{"D","2.0.0"}],
%% we pick D1 because B < C
- {ok, ["B","C",{"D","1"}]}};
+ {ok, ["B","C",{"D","1.0.0"}]}};
deps(circular1) ->
{[{"B", [{"A", []}]}, % A is the top-level app
{"C", []}],
@@ -220,15 +222,17 @@ deps(circular2) ->
deps(circular_skip) ->
%% Never spot the circular dep due to being to low in the deps tree
%% in source deps
- {[{"B", [{"C", "2", [{"B", []}]}]},
- {"C", "1", [{"D",[]}]}],
- [{"C","2"}],
- {ok, ["B", {"C","1"}, "D"]}}.
+ {[{"B", [{"C", "2.0.0", [{"B", []}]}]},
+ {"C", "1.0.0", [{"D",[]}]}],
+ [{"C","2.0.0"}],
+ {ok, ["B", {"C","1.0.0"}, "D"]}}.
setup_project(Case, Config0, Deps) ->
DepsType = ?config(deps_type, Config0),
+ %% spread packages across 3 repos randomly
+ Repos = [<<"test-repo-1">>, <<"test-repo-2">>, <<"hexpm">>],
Config = rebar_test_utils:init_rebar_state(
- Config0,
+ [{repos, Repos} | Config0],
atom_to_list(Case)++"_"++atom_to_list(DepsType)++"_"
),
AppDir = ?config(apps, Config),
@@ -237,7 +241,7 @@ setup_project(Case, Config0, Deps) ->
RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
{SrcDeps, PkgDeps} = rebar_test_utils:flat_deps(Deps),
mock_git_resource:mock([{deps, SrcDeps}]),
- mock_pkg_resource:mock([{pkgdeps, PkgDeps}]),
+ mock_pkg_resource:mock([{pkgdeps, PkgDeps}, {repos, Repos}]),
[{rebarconfig, RebarConf} | Config].
mock_warnings() ->
@@ -255,6 +259,32 @@ circular1(Config) -> run(Config).
circular2(Config) -> run(Config).
circular_skip(Config) -> run(Config).
+%% Test that a top-level application overtakes dependencies, and
+%% works even if said deps do not exist.
+top_override(Config) ->
+ AppDir = ?config(apps, Config),
+ ct:pal("dir: ~p", [AppDir]),
+ Name1 = rebar_test_utils:create_random_name("sub_app1_"),
+ Name2 = rebar_test_utils:create_random_name("sub_app2_"),
+ SubAppsDir1 = filename:join([AppDir, "apps", Name1]),
+ SubAppsDir2 = filename:join([AppDir, "apps", Name2]),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(SubAppsDir1, Name1, Vsn, [kernel, stdlib]),
+ rebar_test_utils:create_app(SubAppsDir2, Name2, Vsn, [kernel, stdlib]),
+ rebar_test_utils:create_config(
+ SubAppsDir1,
+ [{deps, [list_to_atom(Name2)]}]
+ ),
+ rebar_test_utils:create_config(
+ SubAppsDir2,
+ [{deps, [{list_to_atom(Name1),
+ {git, "https://example.org", {branch, "master"}}}]}]
+ ),
+ rebar_test_utils:run_and_check(
+ Config, [], ["compile"],
+ {ok, [{app, Name1}, {app,Name2}]}
+ ).
+
%% Test that the deps of project apps that have their own rebar.config
%% are included, but that top level rebar.config deps take precedence
sub_app_deps(Config) ->
@@ -384,70 +414,62 @@ https_os_proxy_settings(_Config) ->
httpc:get_option(https_proxy, rebar)).
semver_matching_lt(_Config) ->
- Dep = <<"test">>,
- Dep1 = {Dep, <<"1.0.0">>, Dep},
MaxVsn = <<"0.2.0">>,
Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
- ?assertEqual([{Dep, <<"0.1.9">>}],
- rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
+ ?assertEqual({ok, <<"0.1.9">>},
+ rebar_packages:cmpl_(undefined, MaxVsn, Vsns,
fun ec_semver:lt/2)).
semver_matching_lte(_Config) ->
- Dep = <<"test">>,
- Dep1 = {Dep, <<"1.0.0">>, Dep},
MaxVsn = <<"0.2.0">>,
Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
- ?assertEqual([{Dep, <<"0.2.0">>}],
- rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
+ ?assertEqual({ok, <<"0.2.0">>},
+ rebar_packages:cmpl_(undefined, MaxVsn, Vsns,
fun ec_semver:lte/2)).
semver_matching_gt(_Config) ->
- Dep = <<"test">>,
- Dep1 = {Dep, <<"1.0.0">>, Dep},
MaxVsn = <<"0.2.0">>,
Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
- ?assertEqual([{Dep, <<"0.2.1">>}],
- rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
+ ?assertEqual({ok, <<"0.2.1">>},
+ rebar_packages:cmp_(undefined, MaxVsn, Vsns,
fun ec_semver:gt/2)).
semver_matching_gte(_Config) ->
- Dep = <<"test">>,
- Dep1 = {Dep, <<"1.0.0">>, Dep},
MaxVsn = <<"0.2.0">>,
Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>],
- ?assertEqual([{Dep, <<"0.2.0">>}],
- rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
+ ?assertEqual({ok, <<"0.2.0">>},
+ rebar_packages:cmp_(undefined, MaxVsn, Vsns,
fun ec_semver:gt/2)).
valid_version(_Config) ->
- ?assert(rebar_prv_update:valid_vsn(<<"0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"<0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"<0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<">0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<">0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"<=0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"<=0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<">=0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<">=0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"==0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"==0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"~>0.1">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"~>0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
- ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
- ?assertNot(rebar_prv_update:valid_vsn(<<"> 0.1.0 and < 0.2.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<"0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<" 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<" 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"<0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<"<0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"< 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"< 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<">0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<">0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"> 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"> 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"<=0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<"<=0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"<= 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"<= 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<">=0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<">=0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<">= 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<">= 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"==0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<"==0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"== 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"== 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"~>0.1">>)),
+ ?assert(rebar_packages:valid_vsn(<<"~>0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"~> 0.1.0">>)),
+ ?assert(rebar_packages:valid_vsn(<<"~> 0.1.0">>)),
+ ?assertNot(rebar_packages:valid_vsn(<<"> 0.1.0 and < 0.2.0">>)),
ok.
@@ -476,5 +498,5 @@ in_warnings(git, Warns, NameRaw, VsnRaw) ->
in_warnings(pkg, Warns, NameRaw, VsnRaw) ->
Name = iolist_to_binary(NameRaw),
Vsn = iolist_to_binary(VsnRaw),
- 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn, _}]} <- Warns,
+ 1 =< length([1 || {_, [AppName, {pkg, _, AppVsn}]} <- Warns,
AppName =:= Name, AppVsn =:= Vsn]).