diff options
author | Tristan Sloughter <t@crashfast.com> | 2015-04-11 13:12:13 -0500 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2015-04-11 13:19:25 -0500 |
commit | 41b95eb295c2e4c76dbea4c26dee2d73180d5b74 (patch) | |
tree | 99ba3084c5a2c47ceb4b167623b3558b90123dc5 /test | |
parent | d75ba02671236634906989f70eadc785658b4959 (diff) |
add test for single atom pkg dep picking the highest available
Diffstat (limited to 'test')
-rw-r--r-- | test/mock_pkg_resource.erl | 17 | ||||
-rw-r--r-- | test/rebar_compile_SUITE.erl | 30 |
2 files changed, 44 insertions, 3 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl index afb6fb4..615e8a5 100644 --- a/test/mock_pkg_resource.erl +++ b/test/mock_pkg_resource.erl @@ -110,6 +110,8 @@ mock_pkg_index(Opts) -> GraphParts = to_graph_parts(Dict), Digraph = rebar_digraph:restore_graph(GraphParts), meck:new(rebar_packages, [passthrough, no_link]), + meck:expect(rebar_packages, registry, + fun(_State) -> {ok, to_registry(Deps)} end), meck:expect(rebar_packages, get_packages, fun(_State) -> {Dict, Digraph} end). @@ -117,10 +119,23 @@ mock_pkg_index(Opts) -> %%%%%%%%%%%%%%% %%% Helpers %%% %%%%%%%%%%%%%%% + +to_registry(Deps) -> + Tid = ets:new(registry, []), + lists:foreach(fun({{Name, Vsn}, _}) -> + case ets:lookup(Tid, Name) of + [{_, [Vsns]}] -> + ets:insert(Tid, {Name, [[Vsn | Vsns]]}); + _ -> + ets:insert(Tid, {Name, [[Vsn]]}) + end + end, Deps), + Tid. + all_files(Dir) -> filelib:wildcard(filename:join([Dir, "**"])). -archive_names(Dir, App, Vsn, Files) -> +archive_names(Dir, _App, _Vsn, Files) -> [{(F -- Dir) -- "/", F} || F <- Files]. find_parts(Apps, Skip) -> find_parts(Apps, Skip, dict:new()). diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl index bc72913..2fdf36d 100644 --- a/test/rebar_compile_SUITE.erl +++ b/test/rebar_compile_SUITE.erl @@ -18,7 +18,8 @@ deps_in_path/1, delete_beam_if_source_deleted/1, checkout_priority/1, - compile_plugins/1]). + compile_plugins/1, + highest_version_of_pkg_dep/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -45,7 +46,7 @@ all() -> build_all_srcdirs, recompile_when_hrl_changes, recompile_when_opts_change, dont_recompile_when_opts_dont_change, dont_recompile_yrl_or_xrl, delete_beam_if_source_deleted, - deps_in_path, checkout_priority, compile_plugins]. + deps_in_path, checkout_priority, compile_plugins, highest_version_of_pkg_dep]. build_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -420,3 +421,28 @@ compile_plugins(Config) -> Config, RConf, ["compile"], {ok, [{app, Name}, {plugin, PluginName}, {dep, DepName}]} ). + +highest_version_of_pkg_dep(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("app1_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + PkgName = rebar_test_utils:create_random_name("pkg1_"), + mock_git_resource:mock([]), + mock_pkg_resource:mock([ + {pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}, + {{iolist_to_binary(PkgName), <<"0.0.1">>}, []}, + {{iolist_to_binary(PkgName), <<"0.1.3">>}, []}, + {{iolist_to_binary(PkgName), <<"0.1.1">>}, []}]} + ]), + + RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [list_to_atom(PkgName)]}]), + {ok, RConf} = file:consult(RConfFile), + + %% Build with deps. + rebar_test_utils:run_and_check( + Config, RConf, ["compile"], + {ok, [{app, Name}, {dep, PkgName, <<"0.1.3">>}]} + ). |