summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mock_git_resource.erl11
-rw-r--r--test/rebar_deps_SUITE.erl112
-rw-r--r--test/rebar_pkg_SUITE.erl9
-rw-r--r--test/rebar_plugins_SUITE.erl52
-rw-r--r--test/rebar_test_utils.erl29
5 files changed, 185 insertions, 28 deletions
diff --git a/test/mock_git_resource.erl b/test/mock_git_resource.erl
index 0f4aff6..e922af3 100644
--- a/test/mock_git_resource.erl
+++ b/test/mock_git_resource.erl
@@ -1,6 +1,6 @@
%%% Mock a git resource and create an app magically for each URL submitted.
-module(mock_git_resource).
--export([mock/0, mock/1, unmock/0]).
+-export([mock/0, mock/1, mock/2, unmock/0]).
-define(MOD, rebar_git_resource).
%%%%%%%%%%%%%%%%%
@@ -24,11 +24,14 @@ mock() -> mock([]).
| {pkg, App, term()},
Vsn :: string().
mock(Opts) ->
+ mock(Opts, create_app).
+
+mock(Opts, CreateType) ->
meck:new(?MOD, [no_link]),
mock_lock(Opts),
mock_update(Opts),
mock_vsn(Opts),
- mock_download(Opts),
+ mock_download(Opts, CreateType),
ok.
unmock() ->
@@ -98,7 +101,7 @@ mock_vsn(Opts) ->
%% `{deps, [{"app1", [{app2, ".*", {git, ...}}]}]}' -- basically
%% the `deps' option takes a key/value list of terms to output directly
%% into a `rebar.config' file to describe dependencies.
-mock_download(Opts) ->
+mock_download(Opts, CreateType) ->
Deps = proplists:get_value(deps, Opts, []),
Config = proplists:get_value(config, Opts, []),
Default = proplists:get_value(default_vsn, Opts, "0.0.0"),
@@ -110,7 +113,7 @@ mock_download(Opts) ->
{git, Url, {_, Vsn}} = normalize_git(Git, Overrides, Default),
App = app(Url),
AppDeps = proplists:get_value({App,Vsn}, Deps, []),
- rebar_test_utils:create_app(
+ rebar_test_utils:CreateType(
Dir, App, Vsn,
[kernel, stdlib] ++ [element(1,D) || D <- AppDeps]
),
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl
index fcc46c3..c95854a 100644
--- a/test/rebar_deps_SUITE.erl
+++ b/test/rebar_deps_SUITE.erl
@@ -3,7 +3,7 @@
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, {group, git}, {group, pkg}].
+all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock, http_proxy_settings, https_proxy_settings, semver_matching_lt, semver_matching_lte, semver_matching_gt, valid_version, {group, git}, {group, pkg}].
groups() ->
[{all, [], [flat, pick_highest_left, pick_highest_right,
@@ -29,6 +29,14 @@ init_per_group(_, Config) ->
end_per_group(_, Config) ->
Config.
+init_per_testcase(valid_version, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(semver_matching_lt, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(semver_matching_lte, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(semver_matching_gt, Config) ->
+ rebar_test_utils:init_rebar_state(Config);
init_per_testcase(newly_added_after_empty_lock, Config) ->
rebar_test_utils:init_rebar_state(Config);
init_per_testcase(newly_added_dep, Config) ->
@@ -49,14 +57,14 @@ init_per_testcase(http_proxy_settings, Config) ->
%% Insert proxy variables into config
rebar_test_utils:create_config(GlobalConfigDir,
[{http_proxy, "http://localhost:1234"}
- ]),
+ ]),
rebar_test_utils:init_rebar_state(Config);
init_per_testcase(https_proxy_settings, Config) ->
SupportsHttpsProxy = case erlang:system_info(otp_release) of
- "R16"++_ -> true;
- "R"++_ -> false;
- _ -> true % 17 and up don't have a "R" in the version
- end,
+ "R16"++_ -> true;
+ "R"++_ -> false;
+ _ -> true % 17 and up don't have a "R" in the version
+ end,
if not SupportsHttpsProxy ->
{skip, https_proxy_unsupported_before_R16};
SupportsHttpsProxy ->
@@ -73,20 +81,20 @@ init_per_testcase(https_proxy_settings, Config) ->
%% Insert proxy variables into config
rebar_test_utils:create_config(GlobalConfigDir,
[{https_proxy, "http://localhost:1234"}
- ]),
+ ]),
rebar_test_utils:init_rebar_state(Config)
end;
init_per_testcase(Case, Config) ->
{Deps, Warnings, Expect} = deps(Case),
Expected = case Expect of
- {ok, List} -> {ok, format_expected_deps(List)};
- {error, Reason} -> {error, Reason}
- end,
+ {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, rebar_test_utils:expand_deps(DepsType, Deps))].
+ | setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))].
end_per_testcase(https_proxy_settings, Config) ->
meck:unload(rebar_dir),
@@ -100,8 +108,8 @@ end_per_testcase(_, Config) ->
format_expected_deps(Deps) ->
[case Dep of
- {N,V} -> {dep, N, V};
- N -> {dep, N}
+ {N,V} -> {dep, N, V};
+ N -> {dep, N}
end || Dep <- Deps].
%% format:
@@ -208,7 +216,7 @@ sub_app_deps(Config) ->
SubAppsDir = filename:join([AppDir, "apps", Name]),
SubDeps = rebar_test_utils:top_level_deps(rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}
- ,{"b", "2.0.0", []}])),
+ ,{"b", "2.0.0", []}])),
rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
rebar_test_utils:create_config(SubAppsDir, [{deps, SubDeps}]),
@@ -242,12 +250,12 @@ newly_added_dep(Config) ->
%% Add a and c to top level
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", []}])),
+ ,{"c", "2.0.0", []}
+ ,{"b", "1.0.0", []}])),
{ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])),
LockFile = filename:join(AppDir, "rebar.lock"),
RebarConfig3 = rebar_config:merge_locks(RebarConfig2,
- rebar_config:consult_lock_file(LockFile)),
+ rebar_config:consult_lock_file(LockFile)),
%% a should now be installed and c should not change
rebar_test_utils:run_and_check(
@@ -277,7 +285,7 @@ newly_added_after_empty_lock(Config) ->
{ok, RebarConfig2} = file:consult(rebar_test_utils:create_config(AppDir, [{deps, TopDeps2}])),
LockFile = filename:join(AppDir, "rebar.lock"),
RebarConfig3 = rebar_config:merge_locks(RebarConfig2,
- rebar_config:consult_lock_file(LockFile)),
+ rebar_config:consult_lock_file(LockFile)),
%% a should now be installed and c should not change
rebar_test_utils:run_and_check(
@@ -304,6 +312,74 @@ https_proxy_settings(_Config) ->
httpc:get_option(https_proxy, rebar)).
+semver_matching_lt(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
+ ?assertEqual([{Dep, <<"0.1.9">>}],
+ rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:lt/2)).
+
+semver_matching_lte(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
+ ?assertEqual([{Dep, <<"0.2.0">>}],
+ rebar_prv_update:cmpl_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:lte/2)).
+
+semver_matching_gt(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>, <<"0.2.1">>],
+ ?assertEqual([{Dep, <<"0.2.1">>}],
+ rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:gt/2)).
+semver_matching_gte(_Config) ->
+ Dep = <<"test">>,
+ Dep1 = {Dep, <<"1.0.0">>, Dep},
+ MaxVsn = <<"0.2.0">>,
+ Vsns = [<<"0.1.7">>, <<"0.1.9">>, <<"0.1.8">>, <<"0.2.0">>],
+ ?assertEqual([{Dep, <<"0.2.0">>}],
+ rebar_prv_update:cmp_(undefined, MaxVsn, Vsns, [], Dep1,
+ fun ec_semver:gt/2)).
+
+valid_version(_Config) ->
+ ?assert(rebar_prv_update:valid_vsn(<<"0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<" 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"< 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"> 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<=0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<=0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"<= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">=0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">=0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<">= 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"==0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"==0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"== 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~>0.1">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~>0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
+ ?assert(rebar_prv_update:valid_vsn(<<"~> 0.1.0">>)),
+ ?assertNot(rebar_prv_update:valid_vsn(<<"> 0.1.0 and < 0.2.0">>)),
+ ok.
+
+
run(Config) ->
{ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
rebar_test_utils:run_and_check(
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index 9f19e0d..6a75f32 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -180,11 +180,14 @@ pkgs_provider(Config) ->
find_highest_matching(_Config) ->
State = rebar_state:new(),
- {ok, Vsn} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0.0">>, package_index, State),
+ {ok, Vsn} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"1.0.0">>, package_index, State),
?assertEqual(<<"1.0.1">>, Vsn),
- {ok, Vsn1} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"1.0">>, package_index, State),
+ {ok, Vsn1} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"1.0">>, package_index, State),
?assertEqual(<<"1.1.1">>, Vsn1),
- {ok, Vsn2} = rebar_packages:find_highest_matching(<<"goodpkg">>, <<"2.0">>, package_index, State),
+ {ok, Vsn2} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"2.0">>, package_index, State),
?assertEqual(<<"2.0.0">>, Vsn2).
diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl
index c1a98de..355e156 100644
--- a/test/rebar_plugins_SUITE.erl
+++ b/test/rebar_plugins_SUITE.erl
@@ -12,7 +12,8 @@
list/1,
upgrade/1,
sub_app_plugins/1,
- sub_app_plugin_overrides/1]).
+ sub_app_plugin_overrides/1,
+ project_plugins/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -34,7 +35,7 @@ end_per_testcase(_, _Config) ->
catch meck:unload().
all() ->
- [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins, sub_app_plugin_overrides].
+ [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade, sub_app_plugins, sub_app_plugin_overrides, project_plugins].
%% Tests that compiling a project installs and compiles the plugins of deps
compile_plugins(Config) ->
@@ -281,3 +282,50 @@ sub_app_plugin_overrides(Config) ->
Config, RConf, ["compile"],
{ok, [{app, Name}, {dep, Dep2Name, Vsn}, {plugin, DepName, Vsn2}, {plugin, PluginName}]}
).
+
+%% Check that project plugins are first in providers even if they override defaults but that
+%% normal plugins do not
+project_plugins(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]),
+
+ DepName = rebar_test_utils:create_random_name("dep1_"),
+ PluginName = "compile",
+ PluginName2 = "release",
+
+ Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}, {PluginName2, Vsn, []}]),
+ {SrcDeps, _} = rebar_test_utils:flat_deps(Plugins),
+ mock_git_resource:mock([{deps, SrcDeps}], create_plugin),
+
+ mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []}]},
+ {config, [{plugins, [
+ {list_to_atom(PluginName),
+ {git, "http://site.com/user/"++PluginName++".git",
+ {tag, Vsn}}}]}]}]),
+
+ RConfFile =
+ rebar_test_utils:create_config(AppDir,
+ [{deps, [
+ list_to_atom(DepName)
+ ]},
+ {project_plugins, [
+ {list_to_atom(PluginName2),
+ {git, "http://site.com/user/"++PluginName2++".git",
+ {tag, Vsn}}}]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ {ok, State} = rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name}, {plugin, PluginName}, {plugin, PluginName2}, {dep, DepName}]}
+ ),
+
+ %% Should have 2 release providers but only 1 compile provider
+ Release = [P || P <- rebar_state:providers(State), providers:impl(P) =:= release, providers:namespace(P) =:= default],
+ Compile = [P || P <- rebar_state:providers(State), providers:impl(P) =:= compile, providers:namespace(P) =:= default],
+
+ ?assertEqual(length(Release), 2),
+ ?assertEqual(length(Compile), 1).
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 5187bda..23b0178 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -3,7 +3,7 @@
-include_lib("eunit/include/eunit.hrl").
-export([init_rebar_state/1, init_rebar_state/2, run_and_check/4, check_results/3]).
-export([expand_deps/2, flat_deps/1, top_level_deps/1]).
--export([create_app/4, create_eunit_app/4, create_empty_app/4,
+-export([create_app/4, create_plugin/4, create_eunit_app/4, create_empty_app/4,
create_config/2, create_config/3, package_app/3]).
-export([create_random_name/1, create_random_vsn/0, write_src_file/2]).
@@ -82,6 +82,16 @@ create_app(AppDir, Name, Vsn, Deps) ->
write_app_src_file(AppDir, Name, Vsn, Deps),
rebar_app_info:new(Name, Vsn, AppDir, Deps).
+%% @doc Creates a dummy plugin including:
+%% - src/<file>.erl
+%% - src/<file>.app.src
+%% And returns a `rebar_app_info' object.
+create_plugin(AppDir, Name, Vsn, Deps) ->
+ write_plugin_file(AppDir, Name ++ ".erl"),
+ write_src_file(AppDir, "not_a_real_src_" ++ Name ++ ".erl"),
+ write_app_src_file(AppDir, Name, Vsn, Deps),
+ rebar_app_info:new(Name, Vsn, AppDir, Deps).
+
%% @doc Creates a dummy application including:
%% - src/<file>.erl
%% - src/<file>.app.src
@@ -365,6 +375,11 @@ check_results(AppDir, Expected, ProfileRun) ->
?assert(filelib:is_dir(Dirname))
end, Expected).
+write_plugin_file(Dir, Name) ->
+ Erl = filename:join([Dir, "src", Name]),
+ ok = filelib:ensure_dir(Erl),
+ ok = ec_file:write(Erl, plugin_src_file(Name)).
+
write_src_file(Dir, Name) ->
Erl = filename:join([Dir, "src", Name]),
ok = filelib:ensure_dir(Erl),
@@ -395,6 +410,18 @@ erl_src_file(Name) ->
"-export([main/0]).\n"
"main() -> ok.\n", [filename:basename(Name, ".erl")]).
+plugin_src_file(Name) ->
+ io_lib:format("-module('~s').\n"
+ "-export([init/1]).\n"
+ "init(State) -> \n"
+ "Provider = providers:create([\n"
+ "{name, '~s'},\n"
+ "{module, '~s'}\n"
+ "]),\n"
+ "{ok, rebar_state:add_provider(State, Provider)}.\n", [filename:basename(Name, ".erl"),
+ filename:basename(Name, ".erl"),
+ filename:basename(Name, ".erl")]).
+
erl_eunitized_src_file(Name) ->
io_lib:format("-module('~s').\n"
"-export([main/0]).\n"