diff options
-rw-r--r-- | src/rebar_prv_upgrade.erl | 21 | ||||
-rw-r--r-- | test/mock_pkg_resource.erl | 3 | ||||
-rw-r--r-- | test/rebar_upgrade_SUITE.erl | 34 |
3 files changed, 49 insertions, 9 deletions
diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index 05845e4..ab8ca90 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -94,10 +94,15 @@ prepare_locks([Name|Names], Deps, Locks, Unlocks) -> AtomName = binary_to_atom(Name, utf8), case lists:keyfind(Name, 1, Locks) of {_, _, 0} = Lock -> - case lists:keyfind(AtomName, 1, Deps) of - false -> + case {lists:keyfind(AtomName, 1, Deps), lists:member(AtomName, Deps)} of + {false, false} -> ?PRV_ERROR({unknown_dependency, Name}); - Dep -> + {Dep, false} -> + {Source, NewLocks, NewUnlocks} = prepare_lock(Dep, Lock, Locks), + prepare_locks(Names, Deps, NewLocks, + [{Name, Source, 0} | NewUnlocks ++ Unlocks]); + {false, true} -> % package as a single atom + Dep = AtomName, {Source, NewLocks, NewUnlocks} = prepare_lock(Dep, Lock, Locks), prepare_locks(Names, Deps, NewLocks, [{Name, Source, 0} | NewUnlocks ++ Unlocks]) @@ -116,9 +121,13 @@ prepare_locks([Name|Names], Deps, Locks, Unlocks) -> end. prepare_lock(Dep, Lock, Locks) -> - Source = Source = case Dep of - {_, Src} -> Src; - {_, _, Src} -> Src + Source = case Dep of + {_, SrcOrVsn} -> SrcOrVsn; + {_, _, Src} -> Src; + _ when is_atom(Dep) -> + %% version-free package. Must unlock whatever matches in locks + {_, Vsn, _} = lists:keyfind(ec_cnv:to_binary(Dep), 1, Locks), + Vsn end, {NewLocks, NewUnlocks} = unlock_higher_than(0, Locks -- [Lock]), {Source, NewLocks, NewUnlocks}. diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl index 9ed0962..2895cb3 100644 --- a/test/mock_pkg_resource.erl +++ b/test/mock_pkg_resource.erl @@ -15,7 +15,7 @@ mock() -> mock([]). %% Specific config options are explained in each of the private functions. -spec mock(Opts) -> ok when Opts :: [Option], - Option :: {update, [App]} + Option :: {upgrade, [App]} | {cache_dir, string()} | {default_vsn, Vsn} | {override_vsn, [{App, Vsn}]} @@ -120,7 +120,6 @@ mock_pkg_index(Opts) -> meck:expect(rebar_packages, get_packages, fun(_State) -> {Dict, Digraph} end). - %%%%%%%%%%%%%%% %%% Helpers %%% %%%%%%%%%%%%%%% diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl index 793f10a..79cf29e 100644 --- a/test/rebar_upgrade_SUITE.erl +++ b/test/rebar_upgrade_SUITE.erl @@ -3,7 +3,7 @@ -include_lib("eunit/include/eunit.hrl"). -compile(export_all). -all() -> [{group, git}, {group, pkg}]. +all() -> [{group, git}, {group, pkg}, novsn_pkg]. groups() -> [{all, [], [top_a, top_b, top_c, top_d1, top_d2, top_e, @@ -31,6 +31,26 @@ init_per_group(_, Config) -> end_per_group(_, Config) -> Config. +init_per_testcase(novsn_pkg, Config0) -> + Config = rebar_test_utils:init_rebar_state(Config0, "novsn_pkg_"), + AppDir = ?config(apps, Config), + RebarConf = rebar_test_utils:create_config(AppDir, [{deps, [fakeapp]}]), + + Deps = [{{<<"fakeapp">>, <<"1.0.0">>}, []}], + UpDeps = [{{<<"fakeapp">>, <<"1.1.0">>}, []}], + Upgrades = ["fakeapp"], + + [{rebarconfig, RebarConf}, + {mock, fun() -> + catch mock_pkg_resource:unmock(), + mock_pkg_resource:mock([{pkgdeps, Deps}, {upgrade, []}]) + end}, + {mock_update, fun() -> + catch mock_pkg_resource:unmock(), + mock_pkg_resource:mock([{pkgdeps, UpDeps}, {upgrade, Upgrades}]) + end}, + {expected, {ok, [{dep, "fakeapp", "1.1.0"}, {lock, "fakeapp", "1.1.0"}]}} + | Config]; init_per_testcase(Case, Config) -> DepsType = ?config(deps_type, Config), {Deps, UpDeps, ToUp, Expectations} = upgrades(Case), @@ -517,6 +537,18 @@ run(Config) -> Config, NewRebarConfig, ["upgrade", App], Expectation ). +novsn_pkg(Config) -> + apply(?config(mock, Config), []), + {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)), + %% Install dependencies before re-mocking for an upgrade + rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}), + Expectation = ?config(expected, Config), + apply(?config(mock_update, Config), []), + rebar_test_utils:run_and_check( + Config, RebarConfig, ["upgrade"], Expectation + ), + ok. + rewrite_locks({ok, Expectations}, Config) -> AppDir = ?config(apps, Config), LockFile = filename:join([AppDir, "rebar.lock"]), |