From 6cfe28c954dc12f847a15a78b5fcf65154f0407a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sat, 6 Dec 2014 16:29:44 +0000 Subject: Partial fix to circular deps (#40) - Adding tests - fixing use of set fetching to find repeated deps and prevent infinite loops On a circular loop rebar3 now fails with `{error, no_sort}`, which is uncaught and should be handled to consider the issue fully fixed. --- test/rebar_deps_SUITE.erl | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) (limited to 'test/rebar_deps_SUITE.erl') diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index b6ee8b8..6e5b874 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -4,7 +4,8 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -all() -> [flat, pick_highest_left, pick_highest_right, pick_earliest]. +all() -> [flat, pick_highest_left, pick_highest_right, pick_earliest, + circular1, circular2]. init_per_suite(Config) -> application:start(meck), @@ -15,29 +16,42 @@ end_per_suite(_Config) -> init_per_testcase(Case, Config) -> {Deps, Expect} = deps(Case), - [{expect, - [case Dep of + Expected = case Expect of + {ok, List} -> {ok, format_expected_deps(List)}; + {error, Reason} -> {error, Reason} + end, + [{expect, Expected} | setup_project(Case, Config, expand_deps(Deps))]. + +format_expected_deps(Deps) -> + [case Dep of {N,V} -> {dep, N, V}; N -> {dep, N} - end || Dep <- Expect]} - | setup_project(Case, Config, expand_deps(Deps))]. + end || Dep <- Deps]. deps(flat) -> {[{"B", []}, {"C", []}], - ["B", "C"]}; + {ok, ["B", "C"]}}; deps(pick_highest_left) -> {[{"B", [{"C", "2", []}]}, {"C", "1", []}], - ["B", {"C", "1"}]}; % Warn C2 + {ok, ["B", {"C", "1"}]}}; % Warn C2 deps(pick_highest_right) -> {[{"B", "1", []}, {"C", [{"B", "2", []}]}], - [{"B","1"}, "C"]}; % Warn B2 + {ok, [{"B","1"}, "C"]}}; % Warn B2 deps(pick_earliest) -> {[{"B", [{"D", "1", []}]}, {"C", [{"D", "2", []}]}], - ["B","C",{"D","1"}]}. % Warn D2 + {ok, ["B","C",{"D","1"}]}}; % Warn D2 +deps(circular1) -> + {[{"B", [{"A", []}]}, % A is the top-level app + {"C", []}], + {error, no_sort}}; % circular dep +deps(circular2) -> + {[{"B", [{"C", [{"B", []}]}]}, + {"C", []}], + {error, no_sort}}. % circular dep end_per_testcase(_, Config) -> mock_git_resource:unmock(), @@ -55,6 +69,7 @@ expand_deps([{Name, Vsn, Deps} | Rest]) -> setup_project(Case, Config0, Deps) -> Config = rebar_test_utils:init_rebar_state(Config0, atom_to_list(Case)), AppDir = ?config(apps, Config), + rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]), TopDeps = top_level_deps(Deps), RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]), mock_git_resource:mock([{deps, flat_deps(Deps)}]), @@ -76,6 +91,8 @@ flat(Config) -> run(Config). pick_highest_left(Config) -> run(Config). pick_highest_right(Config) -> run(Config). pick_earliest(Config) -> run(Config). +circular1(Config) -> run(Config). +circular2(Config) -> run(Config). run(Config) -> {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), -- cgit v1.1 From 63003c3986ca20e2f733e79453315fa0b7076bd9 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sat, 6 Dec 2014 23:18:35 +0000 Subject: Return cycles in deps solver --- test/rebar_deps_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/rebar_deps_SUITE.erl') diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index 6e5b874..a98f690 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -47,11 +47,11 @@ deps(pick_earliest) -> deps(circular1) -> {[{"B", [{"A", []}]}, % A is the top-level app {"C", []}], - {error, no_sort}}; % circular dep + {error, {cycles, [[<<"A">>,<<"B">>]]}}}; % circular dep deps(circular2) -> {[{"B", [{"C", [{"B", []}]}]}, {"C", []}], - {error, no_sort}}. % circular dep + {error, {cycles, [[<<"B">>,<<"C">>]]}}}. % circular dep end_per_testcase(_, Config) -> mock_git_resource:unmock(), -- cgit v1.1 From be39ab9e7bd1553132def2a1e89f1ce38f6f2fcc Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Sat, 6 Dec 2014 23:53:11 +0000 Subject: Handle cycle errors in provider --- test/rebar_deps_SUITE.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test/rebar_deps_SUITE.erl') diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index a98f690..656c3b5 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -47,11 +47,11 @@ deps(pick_earliest) -> deps(circular1) -> {[{"B", [{"A", []}]}, % A is the top-level app {"C", []}], - {error, {cycles, [[<<"A">>,<<"B">>]]}}}; % circular dep + {error, {rebar_prv_install_deps, {cycles, [[<<"A">>,<<"B">>]]}}}}; deps(circular2) -> {[{"B", [{"C", [{"B", []}]}]}, {"C", []}], - {error, {cycles, [[<<"B">>,<<"C">>]]}}}. % circular dep + {error, {rebar_prv_install_deps, {cycles, [[<<"B">>,<<"C">>]]}}}}. end_per_testcase(_, Config) -> mock_git_resource:unmock(), -- cgit v1.1