summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/mock_pkg_resource.erl6
-rw-r--r--test/rebar_compile_SUITE.erl63
-rw-r--r--test/rebar_disable_app_SUITE.erl49
-rw-r--r--test/rebar_src_dirs_SUITE.erl (renamed from test/rebar_extra_src_dirs_SUITE.erl)95
-rw-r--r--test/rebar_test_utils.erl7
-rw-r--r--test/rebar_upgrade_SUITE.erl34
6 files changed, 235 insertions, 19 deletions
diff --git a/test/mock_pkg_resource.erl b/test/mock_pkg_resource.erl
index 9ed0962..eda863b 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}]}
@@ -73,6 +73,7 @@ mock_vsn(_Opts) ->
%% into a `rebar.config' file to describe dependencies.
mock_download(Opts) ->
Deps = proplists:get_value(pkgdeps, Opts, []),
+ Config = proplists:get_value(config, Opts, []),
meck:expect(
?MOD, download,
fun (Dir, {pkg, AppBin, Vsn}, _) ->
@@ -83,7 +84,7 @@ mock_download(Opts) ->
Dir, App, binary_to_list(Vsn),
[kernel, stdlib] ++ [element(1,D) || D <- AppDeps]
),
- rebar_test_utils:create_config(Dir, [{deps, AppDeps}]),
+ rebar_test_utils:create_config(Dir, [{deps, AppDeps}]++Config),
TarApp = App++"-"++binary_to_list(Vsn)++".tar",
Tarball = filename:join([Dir, TarApp]),
Contents = filename:join([Dir, "contents.tar.gz"]),
@@ -120,7 +121,6 @@ mock_pkg_index(Opts) ->
meck:expect(rebar_packages, get_packages,
fun(_State) -> {Dict, Digraph} end).
-
%%%%%%%%%%%%%%%
%%% Helpers %%%
%%%%%%%%%%%%%%%
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index 2dc57c5..7025eef 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -20,6 +20,7 @@
checkout_priority/1,
compile_plugins/1,
compile_global_plugins/1,
+ complex_plugins/1,
highest_version_of_pkg_dep/1,
parse_transform_test/1]).
@@ -49,7 +50,7 @@ all() ->
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, compile_global_plugins,
- highest_version_of_pkg_dep, parse_transform_test].
+ complex_plugins, highest_version_of_pkg_dep, parse_transform_test].
build_basic_app(Config) ->
AppDir = ?config(apps, Config),
@@ -408,17 +409,20 @@ compile_plugins(Config) ->
DepName = rebar_test_utils:create_random_name("dep1_"),
PluginName = rebar_test_utils:create_random_name("plugin1_"),
- mock_git_resource:mock([{config, [{plugins, [
- {list_to_atom(PluginName), Vsn}
- ]}]}]),
- mock_pkg_resource:mock([
- {pkgdeps, [{{iolist_to_binary(PluginName), iolist_to_binary(Vsn)}, []}]}
- ]),
+
+ Plugins = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Plugins)}]),
+
+ 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), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
+ list_to_atom(DepName)
]}]),
{ok, RConf} = file:consult(RConfFile),
@@ -480,6 +484,49 @@ compile_global_plugins(Config) ->
meck:unload(rebar_dir).
+%% Tests installing of plugin with transitive deps
+complex_plugins(Config) ->
+ AppDir = ?config(apps, Config),
+
+ meck:new(rebar_dir, [passthrough]),
+
+ Name = rebar_test_utils:create_random_name("app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ Vsn2 = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ DepName = rebar_test_utils:create_random_name("dep1_"),
+ DepName2 = rebar_test_utils:create_random_name("dep2_"),
+ DepName3 = rebar_test_utils:create_random_name("dep3_"),
+ PluginName = rebar_test_utils:create_random_name("plugin1_"),
+
+ Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn2, [{DepName2, Vsn,
+ [{DepName3, Vsn, []}]}]}
+ ,{DepName, Vsn, []}]),
+ mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(Deps)}]),
+
+ RConfFile =
+ rebar_test_utils:create_config(AppDir,
+ [{deps, [
+ {list_to_atom(DepName), {git, "http://site.com/user/"++DepName++".git", {tag, Vsn}}}
+ ]},
+ {plugins, [
+ {list_to_atom(PluginName), {git, "http://site.com/user/"++PluginName++".git", {tag, Vsn2}}}
+ ]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name},
+ {plugin, PluginName, Vsn2},
+ {plugin, DepName2},
+ {plugin, DepName3},
+ {dep, DepName}]}
+ ),
+
+ meck:unload(rebar_dir).
+
highest_version_of_pkg_dep(Config) ->
AppDir = ?config(apps, Config),
diff --git a/test/rebar_disable_app_SUITE.erl b/test/rebar_disable_app_SUITE.erl
new file mode 100644
index 0000000..dd71ffb
--- /dev/null
+++ b/test/rebar_disable_app_SUITE.erl
@@ -0,0 +1,49 @@
+-module(rebar_disable_app_SUITE).
+-compile(export_all).
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+-define(MOD(Name),
+ io_lib:format("-module(~s).~n-export([x/0]).~nx() -> ok.~n", [Name])).
+
+all() -> [disable_app].
+
+init_per_testcase(_, Config) ->
+ rebar_test_utils:init_rebar_state(Config).
+
+end_per_testcase(_, _Config) ->
+ ok.
+
+disable_app(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name1 = create_random_app(AppDir, "app1_"),
+ Name2 = create_random_app(AppDir, "app2_"),
+
+ RebarConfig = [{excluded_apps, [list_to_atom(Name1)]}],
+ %RebarConfig = [],
+
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig, ["compile"],
+ {ok, [{app, Name2}]}),
+
+ App1 = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin", Name1 ++ ".app"]),
+ ?assertEqual(filelib:is_file(App1), false),
+
+ App2 = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin", Name2 ++ ".app"]),
+ ?assertEqual(filelib:is_file(App2), true).
+
+%%
+%% Utils
+%%
+create_random_app(AppDir, Prefix) ->
+ Name = rebar_test_utils:create_random_name(Prefix),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_empty_app(filename:join([AppDir, "apps", Name]), Name, Vsn, [kernel, stdlib]),
+
+ ModName = rebar_test_utils:create_random_name("mod1_"),
+ Mod = filename:join([AppDir, "apps", Name, "src", ModName ++ ".erl"]),
+ ok = filelib:ensure_dir(Mod),
+ Src = ?MOD(ModName),
+ ok = ec_file:write(Mod, Src),
+ Name.
diff --git a/test/rebar_extra_src_dirs_SUITE.erl b/test/rebar_src_dirs_SUITE.erl
index a00bb2d..1804fbf 100644
--- a/test/rebar_extra_src_dirs_SUITE.erl
+++ b/test/rebar_src_dirs_SUITE.erl
@@ -1,4 +1,4 @@
--module(rebar_extra_src_dirs_SUITE).
+-module(rebar_src_dirs_SUITE).
-export([suite/0,
init_per_suite/1,
@@ -6,9 +6,15 @@
init_per_testcase/2,
end_per_testcase/2,
all/0,
+ src_dirs_at_root/1,
+ extra_src_dirs_at_root/1,
+ src_dirs_in_erl_opts/1,
+ extra_src_dirs_in_erl_opts/1,
+ src_dirs_at_root_and_in_erl_opts/1,
+ extra_src_dirs_at_root_and_in_erl_opts/1,
build_basic_app/1,
build_multi_apps/1,
- src_dir_takes_precedence/1]).
+ src_dir_takes_precedence_over_extra/1]).
-include_lib("common_test/include/ct.hrl").
@@ -27,7 +33,88 @@ init_per_testcase(_, Config) ->
end_per_testcase(_, _Config) -> ok.
all() ->
- [build_basic_app, build_multi_apps, src_dir_takes_precedence].
+ [src_dirs_at_root, extra_src_dirs_at_root,
+ src_dirs_in_erl_opts, extra_src_dirs_in_erl_opts,
+ src_dirs_at_root_and_in_erl_opts, extra_src_dirs_at_root_and_in_erl_opts,
+ build_basic_app, build_multi_apps, src_dir_takes_precedence_over_extra].
+
+src_dirs_at_root(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]),
+
+ RebarConfig = [{src_dirs, ["foo", "bar", "baz"]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ["foo", "bar", "baz"] = rebar_dir:src_dirs(State, []).
+
+extra_src_dirs_at_root(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]),
+
+ RebarConfig = [{extra_src_dirs, ["foo", "bar", "baz"]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(State, []).
+
+src_dirs_in_erl_opts(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]),
+
+ RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar", "baz"]}]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ["foo", "bar", "baz"] = rebar_dir:src_dirs(State, []).
+
+extra_src_dirs_in_erl_opts(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]),
+
+ RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar", "baz"]}]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ["foo", "bar", "baz"] = rebar_dir:extra_src_dirs(State, []).
+
+src_dirs_at_root_and_in_erl_opts(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]),
+
+ RebarConfig = [{erl_opts, [{src_dirs, ["foo", "bar"]}]}, {src_dirs, ["baz", "qux"]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ["baz", "qux", "foo", "bar"] = rebar_dir:src_dirs(State, []).
+
+extra_src_dirs_at_root_and_in_erl_opts(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]),
+
+ RebarConfig = [{erl_opts, [{extra_src_dirs, ["foo", "bar"]}]}, {extra_src_dirs, ["baz", "qux"]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+
+ ["baz", "qux", "foo", "bar"] = rebar_dir:extra_src_dirs(State, []).
build_basic_app(Config) ->
AppDir = ?config(apps, Config),
@@ -118,7 +205,7 @@ build_multi_apps(Config) ->
Mods2 = proplists:get_value(modules, KVs2),
false = lists:member(extra2, Mods2).
-src_dir_takes_precedence(Config) ->
+src_dir_takes_precedence_over_extra(Config) ->
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("app1_"),
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 68e0603..f53ba20 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -70,7 +70,8 @@ run_and_check(Config, RebarConfig, Command, Expect) ->
%% - src/<file>.app.src
%% And returns a `rebar_app_info' object.
create_app(AppDir, Name, Vsn, Deps) ->
- write_src_file(AppDir, Name),
+ write_src_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).
@@ -297,9 +298,9 @@ check_results(AppDir, Expected) ->
end, Expected).
write_src_file(Dir, Name) ->
- Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]),
+ Erl = filename:join([Dir, "src", Name]),
ok = filelib:ensure_dir(Erl),
- ok = ec_file:write(Erl, erl_src_file("not_a_real_src_" ++ Name ++ ".erl")).
+ ok = ec_file:write(Erl, erl_src_file(Name)).
write_eunitized_src_file(Dir, Name) ->
Erl = filename:join([Dir, "src", "not_a_real_src_" ++ Name ++ ".erl"]),
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"]),