diff options
-rw-r--r-- | test/rebar_deps_SUITE.erl | 60 | ||||
-rw-r--r-- | test/rebar_profiles_SUITE.erl | 82 | ||||
-rw-r--r-- | test/rebar_test_utils.erl | 32 |
3 files changed, 128 insertions, 46 deletions
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl index 0e5c6fe..6b902a5 100644 --- a/test/rebar_deps_SUITE.erl +++ b/test/rebar_deps_SUITE.erl @@ -43,7 +43,7 @@ init_per_testcase(Case, Config) -> mock_warnings(), [{expect, Expected}, {warnings, Warnings} - | setup_project(Case, Config, expand_deps(DepsType, Deps))]. + | setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))]. end_per_testcase(_, Config) -> meck:unload(), @@ -114,20 +114,6 @@ deps(circular_skip) -> [{"C","2"}], {ok, ["B", {"C","1"}, "D"]}}. -expand_deps(_, []) -> []; -expand_deps(git, [{Name, Deps} | Rest]) -> - Dep = {Name, ".*", {git, "https://example.org/user/"++Name++".git", "master"}}, - [{Dep, expand_deps(git, Deps)} | expand_deps(git, Rest)]; -expand_deps(git, [{Name, Vsn, Deps} | Rest]) -> - Dep = {Name, Vsn, {git, "https://example.org/user/"++Name++".git", {tag, Vsn}}}, - [{Dep, expand_deps(git, Deps)} | expand_deps(git, Rest)]; -expand_deps(pkg, [{Name, Deps} | Rest]) -> - Dep = {pkg, Name, "0.0.0"}, - [{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)]; -expand_deps(pkg, [{Name, Vsn, Deps} | Rest]) -> - Dep = {pkg, Name, Vsn}, - [{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)]. - setup_project(Case, Config0, Deps) -> DepsType = ?config(deps_type, Config0), Config = rebar_test_utils:init_rebar_state( @@ -136,42 +122,24 @@ setup_project(Case, Config0, Deps) -> ), AppDir = ?config(apps, Config), rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]), - TopDeps = top_level_deps(Deps), + TopDeps = rebar_test_utils:top_level_deps(Deps), RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]), case DepsType of git -> - mock_git_resource:mock([{deps, flat_deps(Deps)}]); + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]); pkg -> mock_pkg_resource:mock([{pkgdeps, flat_pkgdeps(Deps)}]) end, [{rebarconfig, RebarConf} | Config]. - -flat_deps([]) -> []; -flat_deps([{{Name,_Vsn,Ref}, Deps} | Rest]) -> - [{{Name,vsn_from_ref(Ref)}, top_level_deps(Deps)}] - ++ - flat_deps(Deps) - ++ - flat_deps(Rest). - -vsn_from_ref({git, _, {_, Vsn}}) -> Vsn; -vsn_from_ref({git, _, Vsn}) -> Vsn. - flat_pkgdeps([]) -> []; flat_pkgdeps([{{pkg, Name, Vsn}, Deps} | Rest]) -> - [{{iolist_to_binary(Name),iolist_to_binary(Vsn)}, top_level_deps(Deps)}] + [{{iolist_to_binary(Name),iolist_to_binary(Vsn)}, rebar_test_utils:top_level_deps(Deps)}] ++ flat_pkgdeps(Deps) ++ flat_pkgdeps(Rest). -top_level_deps([]) -> []; -top_level_deps([{{pkg, Name, Vsn}, _} | Deps]) -> - [{list_to_atom(Name), Vsn} | top_level_deps(Deps)]; -top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) -> - [{list_to_atom(Name), Vsn, Ref} | top_level_deps(Deps)]. - app_vsn([]) -> []; app_vsn([{Source, Deps} | Rest]) -> {Name, Vsn} = case Source of @@ -199,21 +167,21 @@ circular_skip(Config) -> run(Config). %% are included, but that top level rebar.config deps take precedence sub_app_deps(Config) -> AppDir = ?config(apps, Config), - Deps = expand_deps(git, [{"a", "1.0.0", []} - ,{"b", "1.0.0", []} - ,{"b", "2.0.0", []}]), - mock_git_resource:mock([{deps, flat_deps(Deps)}]), + Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"b", "1.0.0", []} + ,{"b", "2.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]), Name = rebar_test_utils:create_random_name("sub_app1_"), Vsn = rebar_test_utils:create_random_vsn(), SubAppsDir = filename:join([AppDir, Name]), - SubDeps = top_level_deps(expand_deps(git, [{"a", "1.0.0", []} + SubDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} ,{"b", "2.0.0", []}])), rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]), rebar_test_utils:create_config(SubAppsDir, [{deps, SubDeps}]), - TopDeps = top_level_deps(expand_deps(git, [{"b", "1.0.0", []}])), + TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])), {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])), rebar_test_utils:run_and_check( @@ -223,10 +191,10 @@ sub_app_deps(Config) -> %% Newly added dependency after locking newly_added_dep(Config) -> AppDir = ?config(apps, Config), - Deps = expand_deps(git, [{"a", "1.0.0", []} + Deps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} ,{"b", "1.0.0", [{"c", "1.0.0", []}]} ,{"c", "2.0.0", []}]), - mock_git_resource:mock([{deps, flat_deps(Deps)}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]), Name = rebar_test_utils:create_random_name("app_"), Vsn = rebar_test_utils:create_random_vsn(), @@ -234,14 +202,14 @@ newly_added_dep(Config) -> SubAppsDir = filename:join([AppDir, Name]), rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]), - TopDeps = top_level_deps(expand_deps(git, [{"b", "1.0.0", []}])), + TopDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])), {ok, RebarConfig} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps}])), rebar_test_utils:run_and_check( Config, RebarConfig, ["compile"], {ok, [{app, Name}, {dep, "b", "1.0.0"}, {dep, "c", "1.0.0"}]}), %% Add a and c to top level - TopDeps2 = top_level_deps(expand_deps(git, [{"a", "1.0.0", []} + TopDeps2 = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} ,{"c", "2.0.0", []} ,{"b", "1.0.0", []}])), {ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])), diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl new file mode 100644 index 0000000..802b772 --- /dev/null +++ b/test/rebar_profiles_SUITE.erl @@ -0,0 +1,82 @@ +-module(rebar_profiles_SUITE). + +-export([init_per_suite/1, + end_per_suite/1, + init_per_testcase/2, + end_per_testcase/2, + all/0, + profile_new_key/1, + profile_merge_keys/1]). + +-include_lib("common_test/include/ct.hrl"). +-include_lib("eunit/include/eunit.hrl"). +-include_lib("kernel/include/file.hrl"). + +all() -> + [profile_new_key, profile_merge_keys]. + +init_per_suite(Config) -> + application:start(meck), + Config. + +end_per_suite(_Config) -> + application:stop(meck). + +init_per_testcase(_, Config) -> + rebar_test_utils:init_rebar_state(Config). + +end_per_testcase(_, Config) -> + meck:unload(), + Config. + +profile_new_key(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"b", "1.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]), + + 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]), + + Deps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"b", "1.0.0", []}])), + ct:pal("Deps ~p", [Deps]), + RebarConfig = [{profiles, + [{ct, + [{deps, Deps}]}]}], + + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "ct", "compile"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "1.0.0"}]}). + +profile_merge_keys(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.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("profile_new_key_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + Deps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"b", "1.0.0", []}])), + ProfileDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])), + + RebarConfig = [{deps, Deps}, + {profiles, + [{ct, + [{deps, ProfileDeps}]}]}], + + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "ct", "compile"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "2.0.0"}]}). diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl index 73b9903..acefd8b 100644 --- a/test/rebar_test_utils.erl +++ b/test/rebar_test_utils.erl @@ -2,6 +2,7 @@ -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). -export([init_rebar_state/1, init_rebar_state/2, run_and_check/4]). +-export([expand_deps/2, flat_deps/1, top_level_deps/1]). -export([create_app/4, create_empty_app/4, create_config/2]). -export([create_random_name/1, create_random_vsn/0]). @@ -97,6 +98,37 @@ create_random_vsn() -> ".", erlang:integer_to_list(random:uniform(100)), ".", erlang:integer_to_list(random:uniform(100))]). +expand_deps(_, []) -> []; +expand_deps(git, [{Name, Deps} | Rest]) -> + Dep = {Name, ".*", {git, "https://example.org/user/"++Name++".git", "master"}}, + [{Dep, expand_deps(git, Deps)} | expand_deps(git, Rest)]; +expand_deps(git, [{Name, Vsn, Deps} | Rest]) -> + Dep = {Name, Vsn, {git, "https://example.org/user/"++Name++".git", {tag, Vsn}}}, + [{Dep, expand_deps(git, Deps)} | expand_deps(git, Rest)]; +expand_deps(pkg, [{Name, Deps} | Rest]) -> + Dep = {pkg, Name, "0.0.0"}, + [{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)]; +expand_deps(pkg, [{Name, Vsn, Deps} | Rest]) -> + Dep = {pkg, Name, Vsn}, + [{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)]. + +flat_deps([]) -> []; +flat_deps([{{Name,_Vsn,Ref}, Deps} | Rest]) -> + [{{Name,vsn_from_ref(Ref)}, top_level_deps(Deps)}] + ++ + flat_deps(Deps) + ++ + flat_deps(Rest). + +vsn_from_ref({git, _, {_, Vsn}}) -> Vsn; +vsn_from_ref({git, _, Vsn}) -> Vsn. + +top_level_deps([]) -> []; +top_level_deps([{{pkg, Name, Vsn}, _} | Deps]) -> + [{list_to_atom(Name), Vsn} | top_level_deps(Deps)]; +top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) -> + [{list_to_atom(Name), Vsn, Ref} | top_level_deps(Deps)]. + %%%%%%%%%%%%%%% %%% Helpers %%% %%%%%%%%%%%%%%% |