summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorTristan Sloughter <tristan.sloughter@gmail.com>2015-02-17 10:35:50 -0600
committerTristan Sloughter <tristan.sloughter@gmail.com>2015-02-17 10:35:50 -0600
commit43a18bf4fa55a7ef23a6da837ba4450996fe8725 (patch)
tree14a08750177ecf866353583dd8d7549f0ba30864 /test
parentd65e6da7dae7a205050befb76752b58721660ff9 (diff)
parent501b9b42dfa4c06bc1d537e810f2e4d730e5d8f7 (diff)
Merge pull request #145 from tsloughter/hex
Replace package management with hex.pm
Diffstat (limited to 'test')
-rw-r--r--test/mock_git_resource.erl2
-rw-r--r--test/mock_pkg_resource.erl19
-rw-r--r--test/rebar_deps_SUITE.erl249
-rw-r--r--test/rebar_upgrade_SUITE.erl9
4 files changed, 203 insertions, 76 deletions
diff --git a/test/mock_git_resource.erl b/test/mock_git_resource.erl
index d2f0207..6940f54 100644
--- a/test/mock_git_resource.erl
+++ b/test/mock_git_resource.erl
@@ -103,7 +103,7 @@ mock_download(Opts) ->
Overrides = proplists:get_value(override_vsn, Opts, []),
meck:expect(
?MOD, download,
- fun (Dir, Git) ->
+ fun (Dir, Git, _) ->
filelib:ensure_dir(Dir),
{git, Url, {_, Vsn}} = normalize_git(Git, Overrides, Default),
App = app(Url),
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl
index ab2c0d3..c7276b6 100644
--- a/test/mock_pkg_resource.erl
+++ b/test/mock_pkg_resource.erl
@@ -21,7 +21,7 @@ mock() -> mock([]).
| {not_in_index, [{App, Vsn}]}
| {pkgdeps, [{{App,Vsn}, [Dep]}]},
App :: string(),
- Dep :: {App, string(), {pkg, App, Vsn, Url::string()}},
+ Dep :: {App, string(), {pkg, App, Vsn}},
Vsn :: string().
mock(Opts) ->
meck:new(?MOD, [no_link]),
@@ -50,7 +50,7 @@ mock_update(Opts) ->
ToUpdate = proplists:get_value(update, Opts, []),
meck:expect(
?MOD, needs_update,
- fun(_Dir, {pkg, App, _Vsn, _Url}) ->
+ fun(_Dir, {pkg, App, _Vsn}) ->
lists:member(App, ToUpdate)
end).
@@ -65,7 +65,7 @@ mock_vsn(_Opts) ->
%% @doc For each app to download, create a dummy app on disk instead.
%% The configuration for this one (passed in from `mock/1') includes:
%%
-%% - Specify a version with `{pkg, _, Vsn, _}'
+%% - Specify a version with `{pkg, _, Vsn}'
%% - Dependencies for each application must be passed of the form:
%% `{pkgdeps, [{"app1", [{app2, ".*", {pkg, ...}}]}]}' -- basically
%% the `pkgdeps' option takes a key/value list of terms to output directly
@@ -74,7 +74,7 @@ mock_download(Opts) ->
Deps = proplists:get_value(pkgdeps, Opts, []),
meck:expect(
?MOD, download,
- fun (Dir, {pkg, AppBin, Vsn, _Url}) ->
+ fun (Dir, {pkg, AppBin, Vsn}, _) ->
App = binary_to_list(AppBin),
filelib:ensure_dir(Dir),
AppDeps = proplists:get_value({App,Vsn}, Deps, []),
@@ -83,11 +83,15 @@ mock_download(Opts) ->
[element(1,D) || D <- AppDeps]
),
rebar_test_utils:create_config(Dir, [{deps, AppDeps}]),
- Tarball = filename:join([Dir, "package.tar.gz"]),
+ Tarball = filename:join([Dir, App++"-"++binary_to_list(Vsn)++".tar"]),
+ Contents = filename:join([Dir, "contents.tar.gz"]),
Files = all_files(rebar_app_info:dir(AppInfo)),
- ok = erl_tar:create(Tarball,
+ ok = erl_tar:create(Contents,
archive_names(Dir, App, Vsn, Files),
[compressed]),
+ ok = erl_tar:create(Tarball,
+ [{"contents.tar.gz", Contents}],
+ []),
[file:delete(F) || F <- Files],
{tarball, Tarball}
end).
@@ -117,8 +121,7 @@ all_files(Dir) ->
filelib:wildcard(filename:join([Dir, "**"])).
archive_names(Dir, App, Vsn, Files) ->
- ArchName = App++"-"++binary_to_list(Vsn),
- [{ArchName ++ (F -- Dir), F} || F <- Files].
+ [{(F -- Dir) -- "/", F} || F <- Files].
find_parts(Apps, Skip) -> find_parts(Apps, Skip, dict:new()).
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl
index 4aaa7e3..633e9a2 100644
--- a/test/rebar_deps_SUITE.erl
+++ b/test/rebar_deps_SUITE.erl
@@ -1,14 +1,16 @@
-%% TODO: add tests for:
-%% - only part of deps fetched
-%% - only part of deps locked
-%% - output only shown once
-%% - modification asterisk on locked file
-module(rebar_deps_SUITE).
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-all() -> [default_nodep, default_lock].
+all() -> [{group, git}, {group, pkg}].
+
+groups() ->
+ [{all, [], [flat, pick_highest_left, pick_highest_right,
+ pick_smallest1, pick_smallest2,
+ circular1, circular2, circular_skip]},
+ {git, [], [{group, all}]},
+ {pkg, [], [{group, all}]}].
init_per_suite(Config) ->
application:start(meck),
@@ -17,79 +19,202 @@ init_per_suite(Config) ->
end_per_suite(_Config) ->
application:stop(meck).
+init_per_group(git, Config) ->
+ [{deps_type, git} | Config];
+init_per_group(pkg, Config) ->
+ [{deps_type, pkg} | Config];
+init_per_group(_, Config) ->
+ Config.
+
+end_per_group(_, Config) ->
+ Config.
+
init_per_testcase(Case, Config) ->
- meck:new(io, [no_link, passthrough, unstick]),
- setup_project(Case, Config).
+ {Deps, Warnings, Expect} = deps(Case),
+ Expected = case Expect of
+ {ok, List} -> {ok, format_expected_deps(List)};
+ {error, Reason} -> {error, Reason}
+ end,
+ DepsType = ?config(deps_type, Config),
+ mock_warnings(),
+ [{expect, Expected},
+ {warnings, Warnings}
+ | setup_project(Case, Config, expand_deps(DepsType, Deps))].
end_per_testcase(_, Config) ->
meck:unload(),
Config.
-config_content() ->
- [{deps, [
- {src_a, ".*", {git, "https://example.org/ferd/src_a.git", {branch, "master"}}},
- {src_b, {git, "https://example.org/ferd/src_b.git", {branch, "master"}}},
- {pkg_a, "1.0.0"}
- ]},
- {profiles,
- [{test,
- [{deps, [
- {tdep, {git, "git://example.org/ferd/tdep.git", {tag, "0.8.2"}}}
- ]}]
- }]}
- ].
-
-setup_project(Case, Config0) ->
+format_expected_deps(Deps) ->
+ [case Dep of
+ {N,V} -> {dep, N, V};
+ N -> {dep, N}
+ end || Dep <- Deps].
+
+%% format:
+%% {Spec,
+%% [Warning],
+%% {ok, Result} | {error, Reason}}
+%%
+%% Spec is a list of levelled dependencies of two possible forms:
+%% - {"Name", Spec}
+%% - {"Name", "Vsn", Spec}
+%%
+%% Warnings are going to match on mocked ?WARN(...)
+%% calls to be evaluated. An empty list means we do not care about
+%% warnings, not that no warnings will be printed. This means
+%% the list of warning isn't interpreted to be exhaustive, and more
+%% warnings may be generated than are listed.
+deps(flat) ->
+ {[{"B", []},
+ {"C", []}],
+ [],
+ {ok, ["B", "C"]}};
+deps(pick_highest_left) ->
+ {[{"B", [{"C", "2", []}]},
+ {"C", "1", []}],
+ [{"C","2"}],
+ {ok, ["B", {"C", "1"}]}};
+deps(pick_highest_right) ->
+ {[{"B", "1", []},
+ {"C", [{"B", "2", []}]}],
+ [{"B","2"}],
+ {ok, [{"B","1"}, "C"]}};
+deps(pick_smallest1) ->
+ {[{"B", [{"D", "1", []}]},
+ {"C", [{"D", "2", []}]}],
+ [{"D","2"}],
+ %% we pick D1 because B < C
+ {ok, ["B","C",{"D","1"}]}};
+deps(pick_smallest2) ->
+ {[{"C", [{"D", "2", []}]},
+ {"B", [{"D", "1", []}]}],
+ [{"D","2"}],
+ %% we pick D1 because B < C
+ {ok, ["B","C",{"D","1"}]}};
+deps(circular1) ->
+ {[{"B", [{"A", []}]}, % A is the top-level app
+ {"C", []}],
+ [],
+ {error, {rebar_prv_install_deps, {cycles, [[<<"A">>,<<"B">>]]}}}};
+deps(circular2) ->
+ {[{"B", [{"C", [{"B", []}]}]},
+ {"C", []}],
+ [],
+ {error, {rebar_prv_install_deps, {cycles, [[<<"B">>,<<"C">>]]}}}};
+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"]}}.
+
+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(
Config0,
- atom_to_list(Case)++"_"
+ atom_to_list(Case)++"_"++atom_to_list(DepsType)++"_"
),
AppDir = ?config(apps, Config),
rebar_test_utils:create_app(AppDir, "A", "0.0.0", [kernel, stdlib]),
- TopDeps = proplists:get_value(deps, config_content()),
- StringDeps = [erlang:setelement(1, Dep, atom_to_list(element(1,Dep)))
- || Dep <- TopDeps],
+ TopDeps = top_level_deps(Deps),
RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
- mock_git_resource:mock([{deps, lists:filter(fun src_dep/1, StringDeps)}]),
- mock_pkg_resource:mock([{pkgdeps,
- [{{ec_cnv:to_binary(N),
- ec_cnv:to_binary(V)},[]}
- || {N,V} <- lists:filter(fun pkg_dep/1, StringDeps)]}]),
+ case DepsType of
+ git ->
+ mock_git_resource:mock([{deps, flat_deps(Deps)}]);
+ pkg ->
+ mock_pkg_resource:mock([{pkgdeps, flat_pkgdeps(Deps)}])
+ end,
[{rebarconfig, RebarConf} | Config].
-src_dep(Dep) ->
- case element(1, Dep) of
- "src_"++_ -> true;
- _ -> false
- end.
-pkg_dep(Dep) ->
- case element(1, Dep) of
- "pkg_"++_ -> true;
- _ -> false
- end.
+flat_deps([]) -> [];
+flat_deps([{{Name,_Vsn,Ref}, Deps} | Rest]) ->
+ [{{Name,vsn_from_ref(Ref)}, top_level_deps(Deps)}]
+ ++
+ flat_deps(Deps)
+ ++
+ flat_deps(Rest).
-default_nodep(Config) ->
- {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
- rebar_test_utils:run_and_check(
- Config, RebarConfig, ["deps"], {ok, []}
- ),
- History = meck:history(io),
- Strings = [io_lib:format(Str, Args) || {_, {io, format, [Str, Args]}, _} <- History],
- {match, _} = re:run(Strings, "src_a\\* \\(git source\\)"),
- {match, _} = re:run(Strings, "src_b\\* \\(git source\\)"),
- {match, _} = re:run(Strings, "pkg_a\\* \\(package 1.0.0\\)").
+vsn_from_ref({git, _, {_, Vsn}}) -> Vsn;
+vsn_from_ref({git, _, Vsn}) -> Vsn.
-default_lock(Config) ->
+flat_pkgdeps([]) -> [];
+flat_pkgdeps([{{pkg, Name, Vsn}, Deps} | Rest]) ->
+ [{{iolist_to_binary(Name),iolist_to_binary(Vsn)}, 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
+ {pkg, N, V} -> {N,V};
+ {N,V,_Ref} -> {N,V}
+ end,
+ [{Name, Vsn}] ++ app_vsn(Deps) ++ app_vsn(Rest).
+
+mock_warnings() ->
+ %% just let it do its thing, we check warnings through
+ %% the call log.
+ meck:new(rebar_log, [no_link, passthrough]).
+
+%%% TESTS %%%
+flat(Config) -> run(Config).
+pick_highest_left(Config) -> run(Config).
+pick_highest_right(Config) -> run(Config).
+pick_smallest1(Config) -> run(Config).
+pick_smallest2(Config) -> run(Config).
+circular1(Config) -> run(Config).
+circular2(Config) -> run(Config).
+circular_skip(Config) -> run(Config).
+
+run(Config) ->
{ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
rebar_test_utils:run_and_check(
- Config, RebarConfig, ["lock"], {ok, []}
+ Config, RebarConfig, ["install_deps"], ?config(expect, Config)
),
- rebar_test_utils:run_and_check(
- Config, RebarConfig, ["deps"], {ok, []}
- ),
- History = meck:history(io),
- Strings = [io_lib:format(Str, Args) || {_, {io, format, [Str, Args]}, _} <- History],
- {match, _} = re:run(Strings, "src_a\\ \\(locked git source\\)"),
- {match, _} = re:run(Strings, "src_b\\ \\(locked git source\\)"),
- {match, _} = re:run(Strings, "pkg_a\\ \\(locked package 1.0.0\\)").
+ check_warnings(warning_calls(), ?config(warnings, Config), ?config(deps_type, Config)).
+
+warning_calls() ->
+ History = meck:history(rebar_log),
+ [{Str, Args} || {_, {rebar_log, log, [warn, Str, Args]}, _} <- History].
+
+check_warnings(_, [], _) ->
+ ok;
+check_warnings(Warns, [{Name, Vsn} | Rest], Type) ->
+ ct:pal("Checking for warning ~p in ~p", [{Name,Vsn},Warns]),
+ ?assert(in_warnings(Type, Warns, Name, Vsn)),
+ check_warnings(Warns, Rest, Type).
+
+in_warnings(git, Warns, NameRaw, VsnRaw) ->
+ Name = iolist_to_binary(NameRaw),
+ 1 =< length([1 || {_, [AppName, {git, _, {_, Vsn}}]} <- Warns,
+ AppName =:= Name, Vsn =:= VsnRaw]);
+in_warnings(pkg, Warns, NameRaw, VsnRaw) ->
+ Name = iolist_to_binary(NameRaw),
+ Vsn = iolist_to_binary(VsnRaw),
+ 1 =< length([1 || {_, [AppName, AppVsn]} <- Warns,
+ AppName =:= Name, AppVsn =:= Vsn]).
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index 39b9687..b4daef9 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -359,7 +359,7 @@ upgrades(delete_d) ->
top_level_deps([]) -> [];
top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) ->
[{list_to_atom(Name), Vsn, Ref} | top_level_deps(Deps)];
-top_level_deps([{{pkg, Name, Vsn, _URL}, _} | Deps]) ->
+top_level_deps([{{pkg, Name, Vsn}, _} | Deps]) ->
[{list_to_atom(Name), Vsn} | top_level_deps(Deps)].
mock_deps(git, Deps, Upgrades) ->
@@ -381,7 +381,7 @@ vsn_from_ref({git, _, {_, Vsn}}) -> Vsn;
vsn_from_ref({git, _, Vsn}) -> Vsn.
flat_pkgdeps([]) -> [];
-flat_pkgdeps([{{pkg, Name, Vsn, _Url}, Deps} | Rest]) ->
+flat_pkgdeps([{{pkg, Name, Vsn}, Deps} | Rest]) ->
[{{iolist_to_binary(Name),iolist_to_binary(Vsn)}, top_level_deps(Deps)}]
++
flat_pkgdeps(Deps)
@@ -396,10 +396,10 @@ 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", "https://example.org/user/"++Name++".tar.gz"},
+ 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, "https://example.org/user/"++Name++".tar.gz"},
+ Dep = {pkg, Name, Vsn},
[{Dep, expand_deps(pkg, Deps)} | expand_deps(pkg, Rest)].
normalize_unlocks({App, Locks}) ->
@@ -472,4 +472,3 @@ run(Config) ->
rebar_test_utils:run_and_check(
Config, NewRebarConfig, ["upgrade", App], Expectation
).
-