Browse Source

add test for single atom pkg dep picking the highest available

pull/330/head
Tristan Sloughter 10 years ago
parent
commit
41b95eb295
3 changed files with 45 additions and 4 deletions
  1. +1
    -1
      src/rebar_packages.erl
  2. +16
    -1
      test/mock_pkg_resource.erl
  3. +28
    -2
      test/rebar_compile_SUITE.erl

+ 1
- 1
src/rebar_packages.erl View File

@ -43,7 +43,7 @@ get_packages(State) ->
registry(State) ->
Dir = rebar_dir:global_cache_dir(State),
RegistryDir = filename:join(Dir, "packages"),
HexFile = filename:join(RegistryDir, "registry2"),
HexFile = filename:join(RegistryDir, "registry"),
case ets:file2tab(HexFile) of
{ok, T} ->
{ok, T};

+ 16
- 1
test/mock_pkg_resource.erl View File

@ -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()).

+ 28
- 2
test/rebar_compile_SUITE.erl View File

@ -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">>}]}
).

Loading…
Cancel
Save