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_as_SUITE.erl22
-rw-r--r--test/rebar_compile_SUITE.erl102
-rw-r--r--test/rebar_ct_SUITE.erl96
-rw-r--r--test/rebar_deps_SUITE.erl112
-rw-r--r--test/rebar_eunit_SUITE.erl23
-rw-r--r--test/rebar_file_utils_SUITE.erl21
-rw-r--r--test/rebar_hooks_SUITE.erl22
-rw-r--r--test/rebar_lock_SUITE.erl46
-rw-r--r--test/rebar_pkg_SUITE.erl28
-rw-r--r--test/rebar_plugins_SUITE.erl125
-rw-r--r--test/rebar_release_SUITE.erl79
-rw-r--r--test/rebar_test_utils.erl42
13 files changed, 668 insertions, 61 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_as_SUITE.erl b/test/rebar_as_SUITE.erl
index 99c7e30..0f37dc8 100644
--- a/test/rebar_as_SUITE.erl
+++ b/test/rebar_as_SUITE.erl
@@ -13,7 +13,8 @@
as_comma_then_space/1,
as_dir_name/1,
as_with_task_args/1,
- warn_on_empty_profile/1]).
+ warn_on_empty_profile/1,
+ clean_as_profile/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -32,7 +33,7 @@ all() -> [as_basic, as_multiple_profiles, as_multiple_tasks,
as_multiple_profiles_multiple_tasks,
as_comma_placement, as_comma_then_space,
as_dir_name, as_with_task_args,
- warn_on_empty_profile].
+ warn_on_empty_profile, clean_as_profile].
as_basic(Config) ->
AppDir = ?config(apps, Config),
@@ -166,3 +167,20 @@ warn_match(App, History) ->
false
end,
History).
+
+clean_as_profile(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("clean_as_profile_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ rebar_test_utils:run_and_check(Config,
+ [],
+ ["as", "foo", "compile"],
+ {ok, [{app, Name, valid}]}),
+
+ rebar_test_utils:run_and_check(Config,
+ [],
+ ["clean", "-a", "-p", "foo"],
+ {ok, [{app, Name, invalid}]}).
diff --git a/test/rebar_compile_SUITE.erl b/test/rebar_compile_SUITE.erl
index ef9cf97..76a3de5 100644
--- a/test/rebar_compile_SUITE.erl
+++ b/test/rebar_compile_SUITE.erl
@@ -37,7 +37,10 @@
only_default_transitive_deps/1,
clean_all/1,
override_deps/1,
- profile_override_deps/1]).
+ profile_override_deps/1,
+ deps_build_in_prod/1,
+ include_file_relative_to_working_directory/1,
+ include_file_in_src/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -58,7 +61,8 @@ all() ->
deps_in_path, checkout_priority, highest_version_of_pkg_dep,
parse_transform_test, erl_first_files_test, mib_test,
umbrella_mib_first_test, only_default_transitive_deps,
- clean_all, override_deps, profile_override_deps].
+ clean_all, override_deps, profile_override_deps, deps_build_in_prod,
+ include_file_relative_to_working_directory, include_file_in_src].
groups() ->
[{basic_app, [], [build_basic_app, paths_basic_app, clean_basic_app]},
@@ -89,7 +93,7 @@ init_per_group(basic_app, 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]),
-
+
[{app_names, [Name]}, {vsns, [Vsn]}|NewConfig];
init_per_group(release_apps, Config) ->
@@ -103,7 +107,7 @@ init_per_group(release_apps, Config) ->
Name2 = rebar_test_utils:create_random_name("relapp2_"),
Vsn2 = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(filename:join([AppDir,"apps",Name2]), Name2, Vsn2, [kernel, stdlib]),
-
+
[{app_names, [Name1, Name2]}, {vsns, [Vsn1, Vsn2]}|NewConfig];
init_per_group(checkout_apps, Config) ->
@@ -415,7 +419,7 @@ paths_basic_app(Config) ->
[Vsn] = ?config(vsns, Config),
{ok, State} = rebar_test_utils:run_and_check(Config, [], ["compile"], return),
-
+
code:add_paths(rebar_state:code_paths(State, all_deps)),
ok = application:load(list_to_atom(Name)),
Loaded = application:loaded_applications(),
@@ -1173,3 +1177,91 @@ profile_override_deps(Config) ->
{ok, [{dep, "some_dep"},{dep_not_exist, "other_dep"}]}
).
+%% verify a deps prod profile is used
+%% tested by checking prod hooks run and outputs to default profile dir for dep
+%% and prod deps are installed for dep
+deps_build_in_prod(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]),
+
+ GitDeps = rebar_test_utils:expand_deps(git, [{"asdf", "1.0.0", []}]),
+ PkgName = rebar_test_utils:create_random_name("pkg1_"),
+ {SrcDeps, _} = rebar_test_utils:flat_deps(GitDeps),
+ mock_git_resource:mock([{deps, SrcDeps},
+ {config, [{profiles, [{prod, [{pre_hooks, [{compile, "echo whatsup > randomfile"}]},
+ {deps, [list_to_atom(PkgName)]}]}]}]}]),
+
+ mock_pkg_resource:mock([{pkgdeps, [{{iolist_to_binary(PkgName), <<"0.1.0">>}, []}]}]),
+
+ Deps = rebar_test_utils:top_level_deps(GitDeps),
+ RConfFile = rebar_test_utils:create_config(AppDir, [{deps, Deps}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name}, {dep, "asdf", <<"1.0.0">>}, {dep, PkgName},
+ {file, filename:join([AppDir, "_build", "default", "lib", "asdf", "randomfile"])}]}
+ ).
+
+%% verify that the proper include path is defined
+%% according the erlang doc which states:
+%% If the filename File is absolute (possibly after variable substitution),
+%% the include file with that name is included. Otherwise, the specified file
+%% is searched for in the following directories, and in this order:
+%% * The current working directory
+%% * The directory where the module is being compiled
+%% * The directories given by the include option
+include_file_relative_to_working_directory(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]),
+
+ Src = <<"-module(test).\n"
+"\n"
+"-include(\"include/test.hrl\").\n"
+"\n"
+"test() -> ?TEST_MACRO.\n"
+"\n">>,
+ Include = <<"-define(TEST_MACRO, test).\n">>,
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
+ ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "include", "dummy"])),
+ ok = file:write_file(filename:join([AppDir, "include", "test.hrl"]), Include),
+
+ RebarConfig = [],
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["compile"],
+ {ok, [{app, Name}]}).
+
+include_file_in_src(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]),
+
+ Src = <<"-module(test).\n"
+"\n"
+"-include(\"test.hrl\").\n"
+"\n"
+"test() -> ?TEST_MACRO.\n"
+"\n">>,
+ Include = <<"-define(TEST_MACRO, test).\n">>,
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "src", "dummy"])),
+ ok = file:write_file(filename:join([AppDir, "src", "test.erl"]), Src),
+
+ ok = file:write_file(filename:join([AppDir, "src", "test.hrl"]), Include),
+
+ RebarConfig = [],
+ rebar_test_utils:run_and_check(Config, RebarConfig,
+ ["compile"],
+ {ok, [{app, Name}]}).
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 267a9ee..94ab690 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -17,6 +17,8 @@
multi_suite/1,
all_suite/1,
single_dir_and_single_suite/1,
+ suite_at_root/1,
+ suite_at_app_root/1,
data_dir_correct/1,
cmd_label/1,
cmd_config/1,
@@ -72,7 +74,9 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
single_unmanaged_suite,
multi_suite,
all_suite,
- single_dir_and_single_suite]},
+ single_dir_and_single_suite,
+ suite_at_root,
+ suite_at_app_root]},
{data_dirs, [], [data_dir_correct]},
{ct_opts, [], [cmd_label,
cmd_config,
@@ -177,6 +181,22 @@ init_per_group(dirs_and_suites, Config) ->
ok = filelib:ensure_dir(Suite3),
ok = file:write_file(Suite3, test_suite("extras")),
+ Suite4 = filename:join([AppDir, "root_SUITE.erl"]),
+ ok = file:write_file(Suite4, test_suite("root")),
+
+ ok = file:write_file(filename:join([AppDir, "root_SUITE.hrl"]), <<>>),
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "root_SUITE_data", "dummy.txt"])),
+ ok = file:write_file(filename:join([AppDir, "root_SUITE_data", "some_data.txt"]), <<>>),
+
+ Suite5 = filename:join([AppDir, "apps", Name2, "app_root_SUITE.erl"]),
+ ok = file:write_file(Suite5, test_suite("app_root")),
+
+ ok = file:write_file(filename:join([AppDir, "apps", Name2, "app_root_SUITE.hrl"]), <<>>),
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "app_root_SUITE_data", "dummy.txt"])),
+ ok = file:write_file(filename:join([AppDir, "apps", Name2, "app_root_SUITE_data", "some_data.txt"]), <<>>),
+
{ok, State} = rebar_test_utils:run_and_check(C, [], ["as", "test", "lock"], return),
[{s, State}, {appnames, [Name1, Name2]}|C];
@@ -603,10 +623,84 @@ single_dir_and_single_suite(Config) ->
Suite = proplists:get_value(suite, Opts),
["extra_SUITE"] = Suite.
+suite_at_root(Config) ->
+ AppDir = ?config(apps, Config),
+ State = ?config(s, Config),
+
+ LibDirs = rebar_dir:lib_dirs(State),
+ State1 = rebar_app_discover:do(State, LibDirs),
+
+ Providers = rebar_state:providers(State1),
+ Namespace = rebar_state:namespace(State1),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--suite=" ++ filename:join([AppDir, "root_SUITE"])]),
+
+ State2 = rebar_state:command_parsed_args(State1, GetOptResult),
+
+ Tests = rebar_prv_common_test:prepare_tests(State2),
+ {ok, NewState} = rebar_prv_common_test:compile(State2, Tests),
+ {ok, T} = Tests,
+ Opts = rebar_prv_common_test:translate_paths(NewState, T),
+
+ Suite = proplists:get_value(suite, Opts),
+ Expected = filename:join([AppDir, "_build", "test", "extras", "root_SUITE"]),
+ [Expected] = Suite,
+
+ TestHrl = filename:join([AppDir, "_build", "test", "extras", "root_SUITE.hrl"]),
+ true = filelib:is_file(TestHrl),
+
+ TestBeam = filename:join([AppDir, "_build", "test", "extras", "root_SUITE.beam"]),
+ true = filelib:is_file(TestBeam),
+
+ DataDir = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data"]),
+ true = filelib:is_dir(DataDir),
+
+ DataFile = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data", "some_data.txt"]),
+ true = filelib:is_file(DataFile).
+
+suite_at_app_root(Config) ->
+ AppDir = ?config(apps, Config),
+ [_Name1, Name2] = ?config(appnames, Config),
+ State = ?config(s, Config),
+
+ LibDirs = rebar_dir:lib_dirs(State),
+ State1 = rebar_app_discover:do(State, LibDirs),
+
+ Providers = rebar_state:providers(State1),
+ Namespace = rebar_state:namespace(State1),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--suite=" ++ filename:join([AppDir, "apps", Name2, "app_root_SUITE"])]),
+
+ State2 = rebar_state:command_parsed_args(State1, GetOptResult),
+
+ Tests = rebar_prv_common_test:prepare_tests(State2),
+ {ok, NewState} = rebar_prv_common_test:compile(State2, Tests),
+ {ok, T} = Tests,
+ Opts = rebar_prv_common_test:translate_paths(NewState, T),
+
+ Suite = proplists:get_value(suite, Opts),
+ Expected = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE"]),
+ [Expected] = Suite,
+
+ TestHrl = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE.hrl"]),
+ true = filelib:is_file(TestHrl),
+
+ TestBeam = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE.beam"]),
+ true = filelib:is_file(TestBeam),
+
+ DataDir = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE_data"]),
+ true = filelib:is_dir(DataDir),
+
+ DataFile = filename:join([AppDir, "_build", "test", "lib", Name2, "app_root_SUITE_data", "some_data.txt"]),
+ true = filelib:is_file(DataFile).
+
%% this test probably only fails when this suite is run via rebar3 with the --cover flag
data_dir_correct(Config) ->
DataDir = ?config(data_dir, Config),
Parts = filename:split(DataDir),
+ ct:pal(Parts),
["rebar_ct_SUITE_data","test","rebar","lib","test","_build"|_] = lists:reverse(Parts).
cmd_label(Config) ->
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_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl
index 1b11c5a..cb2c911 100644
--- a/test/rebar_eunit_SUITE.erl
+++ b/test/rebar_eunit_SUITE.erl
@@ -42,13 +42,10 @@ groups() ->
init_per_suite(Config) ->
PrivDir = ?config(priv_dir, Config),
DataDir = ?config(data_dir, Config),
- {ok, Cwd} = file:get_cwd(),
- file:set_cwd(PrivDir),
ok = ec_file:copy(filename:join([DataDir, "basic_app.zip"]), filename:join([PrivDir, "basic_app.zip"])),
- {ok, _} = zip:extract(filename:join([PrivDir, "basic_app.zip"])),
+ {ok, _} = zip:extract(filename:join([PrivDir, "basic_app.zip"]), [{cwd, PrivDir}]),
ok = ec_file:copy(filename:join([DataDir, "multi_app.zip"]), filename:join([PrivDir, "multi_app.zip"])),
- {ok, _} = zip:extract(filename:join([PrivDir, "multi_app.zip"])),
- file:set_cwd(Cwd),
+ {ok, _} = zip:extract(filename:join([PrivDir, "multi_app.zip"]), [{cwd, PrivDir}]),
Config.
init_per_group(basic_app, Config) ->
@@ -159,7 +156,9 @@ basic_app_exports(_Config) ->
basic_app_testset(Config) ->
Result = ?config(result, Config),
- {ok, [{application, basic_app}]} = rebar_prv_eunit:prepare_tests(Result).
+ Set = {ok, [{application, basic_app},
+ {module, basic_app_tests_helper}]},
+ Set = rebar_prv_eunit:prepare_tests(Result).
@@ -211,12 +210,14 @@ multi_app_exports(_Config) ->
%% check that the correct tests are schedule to run for project
multi_app_testset(Config) ->
- AppDir = ?config(apps, Config),
Result = ?config(result, Config),
- Set = {ok, [{application, multi_app_bar},
- {application, multi_app_baz},
- {dir, filename:join([AppDir, "test"])}]},
+ Set = {ok, [{application, multi_app_baz},
+ {application, multi_app_bar},
+ {module, multi_app_bar_tests_helper},
+ {module, multi_app_baz_tests_helper},
+ {module, multi_app_tests},
+ {module, multi_app_tests_helper}]},
Set = rebar_prv_eunit:prepare_tests(Result).
@@ -546,4 +547,4 @@ misspecified_eunit_first_files(Config) ->
{error, {rebar_prv_eunit, Error}} = rebar_test_utils:run_and_check(State, RebarConfig, ["eunit"], return),
- {badconfig, {"Value `~p' of option `~p' must be a list", {some_file, eunit_first_files}}} = Error. \ No newline at end of file
+ {badconfig, {"Value `~p' of option `~p' must be a list", {some_file, eunit_first_files}}} = Error.
diff --git a/test/rebar_file_utils_SUITE.erl b/test/rebar_file_utils_SUITE.erl
index a061325..c1f85b3 100644
--- a/test/rebar_file_utils_SUITE.erl
+++ b/test/rebar_file_utils_SUITE.erl
@@ -97,10 +97,17 @@ path_from_ancestor(_Config) ->
?assertEqual({error, badparent}, rebar_file_utils:path_from_ancestor("/foo/bar/baz", "/foo/bar/baz/qux")).
canonical_path(_Config) ->
- ?assertEqual(filename:nativename("/"), rebar_file_utils:canonical_path("/")),
- ?assertEqual(filename:nativename("/"), rebar_file_utils:canonical_path("/../../..")),
- ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/bar/..")),
- ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/../foo")),
- ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/.")),
- ?assertEqual("/foo", rebar_file_utils:canonical_path("/foo/./.")),
- ?assertEqual("/foo/bar", rebar_file_utils:canonical_path("/foo/./bar")). \ No newline at end of file
+ %% We find the root so that the name works both on unix-likes and
+ %% with Windows.
+ Root = case os:type() of
+ {win32, _} -> filename:nativename(filename:absname("/")); % C:\, with proper drive
+ _ -> "/"
+ end,
+ ?assertEqual(filename:nativename(Root), rebar_file_utils:canonical_path("/")),
+ ?assertEqual(filename:nativename(Root), rebar_file_utils:canonical_path("/../../..")),
+ ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/bar/..")),
+ ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/../foo")),
+ ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/.")),
+ ?assertEqual(Root ++ "foo", rebar_file_utils:canonical_path("/foo/./.")),
+ ?assertEqual(filename:nativename(Root ++ "foo/bar"),
+ rebar_file_utils:canonical_path("/foo/./bar")).
diff --git a/test/rebar_hooks_SUITE.erl b/test/rebar_hooks_SUITE.erl
index 188fb34..b121dd5 100644
--- a/test/rebar_hooks_SUITE.erl
+++ b/test/rebar_hooks_SUITE.erl
@@ -10,6 +10,7 @@
escriptize_artifacts/1,
run_hooks_once/1,
run_hooks_for_plugins/1,
+ eunit_app_hooks/1,
deps_hook_namespace/1]).
-include_lib("common_test/include/ct.hrl").
@@ -33,7 +34,7 @@ end_per_testcase(_, _Config) ->
all() ->
[build_and_clean_app, run_hooks_once, escriptize_artifacts,
- run_hooks_for_plugins, deps_hook_namespace].
+ run_hooks_for_plugins, deps_hook_namespace, eunit_app_hooks].
%% Test post provider hook cleans compiled project app, leaving it invalid
build_and_clean_app(Config) ->
@@ -119,6 +120,25 @@ deps_hook_namespace(Config) ->
{ok, [{dep, "some_dep"}]}
).
+%% Checks that a hook that is defined on an app (not a top level hook of a project with subapps) is run
+eunit_app_hooks(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]),
+
+ RConfFile =
+ rebar_test_utils:create_config(AppDir,
+ [
+ {escript_name, list_to_atom(Name)}
+ ,{provider_hooks, [{post, [{eunit, escriptize}]}]}
+ ]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ rebar_test_utils:run_and_check(Config, RConf,
+ ["eunit"], {ok, [{app, Name, valid}
+ ,{file, filename:join([AppDir, "_build/test/bin", Name])}]}).
+
run_hooks_for_plugins(Config) ->
AppDir = ?config(apps, Config),
diff --git a/test/rebar_lock_SUITE.erl b/test/rebar_lock_SUITE.erl
new file mode 100644
index 0000000..00875f7
--- /dev/null
+++ b/test/rebar_lock_SUITE.erl
@@ -0,0 +1,46 @@
+%%% Most locking tests are implicit in other test suites handling
+%%% dependencies.
+%%% This suite is to test the compatibility layers between various
+%%% versions of lockfiles.
+-module(rebar_lock_SUITE).
+-compile(export_all).
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+all() -> [current_version, future_versions_no_attrs, future_versions_attrs].
+
+current_version(Config) ->
+ %% Current version just dumps the locks as is on disk.
+ LockFile = filename:join(?config(priv_dir, Config), "current_version"),
+ Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
+ {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
+ {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
+ {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
+ file:write_file(LockFile, io_lib:format("~p.~n", [Locks])),
+ ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)).
+
+future_versions_no_attrs(Config) ->
+ %% Future versions will keep the same core attribute in there, but
+ %% will do so under a new format bundled with a version and potentially
+ %% some trailing attributes
+ LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
+ Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
+ {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
+ {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
+ {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
+ LockData = {"3.5.2", Locks},
+ file:write_file(LockFile, io_lib:format("~p.~n", [LockData])),
+ ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)).
+
+future_versions_attrs(Config) ->
+ %% Future versions will keep the same core attribute in there, but
+ %% will do so under a new format bundled with a version and potentially
+ %% some trailing attributes
+ LockFile = filename:join(?config(priv_dir, Config), "future_versions"),
+ Locks = [{<<"app1">>, {git,"some_url", {ref,"some_ref"}}, 2},
+ {<<"app2">>, {git,"some_url", {ref,"some_ref"}}, 0},
+ {<<"app3">>, {hg,"some_url", {ref,"some_ref"}}, 1},
+ {<<"pkg1">>,{pkg,<<"name">>,<<"0.1.6">>},3}],
+ LockData = {"3.5.2", Locks},
+ file:write_file(LockFile, io_lib:format("~p.~na.~n{b,c}.~n[d,e,f].~n", [LockData])),
+ ?assertEqual(Locks, rebar_config:consult_lock_file(LockFile)).
diff --git a/test/rebar_pkg_SUITE.erl b/test/rebar_pkg_SUITE.erl
index 37e3a5e..6a75f32 100644
--- a/test/rebar_pkg_SUITE.erl
+++ b/test/rebar_pkg_SUITE.erl
@@ -11,7 +11,8 @@
-define(good_checksum, <<"1C6CE379D191FBAB41B7905075E0BF87CBBE23C77CECE775C5A0B786B2244C35">>).
all() -> [good_uncached, good_cached, badindexchk, badpkg,
- bad_to_good, good_disconnect, bad_disconnect, pkgs_provider].
+ bad_to_good, good_disconnect, bad_disconnect, pkgs_provider,
+ find_highest_matching].
init_per_suite(Config) ->
application:start(meck),
@@ -86,7 +87,12 @@ init_per_testcase(bad_disconnect=Name, Config0) ->
meck:unload(httpc),
meck:new(httpc, [passthrough, unsticky]),
meck:expect(httpc, request, fun(_, _, _, _, _) -> {error, econnrefused} end),
- Config.
+ Config;
+init_per_testcase(Name, Config0) ->
+ Config = [{good_cache, false},
+ {pkg, {<<"goodpkg">>, <<"1.0.0">>}}
+ | Config0],
+ mock_config(Name, Config).
end_per_testcase(_, Config) ->
unmock_config(Config),
@@ -172,6 +178,19 @@ pkgs_provider(Config) ->
{ok, []}
).
+find_highest_matching(_Config) ->
+ State = rebar_state:new(),
+ {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(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"1.0">>, package_index, State),
+ ?assertEqual(<<"1.1.1">>, Vsn1),
+ {ok, Vsn2} = rebar_packages:find_highest_matching(
+ <<"test">>, <<"1.0.0">>, <<"goodpkg">>, <<"2.0">>, package_index, State),
+ ?assertEqual(<<"2.0.0">>, Vsn2).
+
+
%%%%%%%%%%%%%%%
%%% Helpers %%%
%%%%%%%%%%%%%%%
@@ -182,10 +201,13 @@ mock_config(Name, Config) ->
Tid = ets:new(registry_table, [public]),
ets:insert_new(Tid, [
{<<"badindexchk">>,[[<<"1.0.0">>]]},
- {<<"goodpkg">>,[[<<"1.0.0">>]]},
+ {<<"goodpkg">>,[[<<"1.0.0">>, <<"1.0.1">>, <<"1.1.1">>, <<"2.0.0">>]]},
{<<"badpkg">>,[[<<"1.0.0">>]]},
{{<<"badindexchk">>,<<"1.0.0">>}, [[], ?bad_checksum, [<<"rebar3">>]]},
{{<<"goodpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"1.0.1">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"1.1.1">>}, [[], ?good_checksum, [<<"rebar3">>]]},
+ {{<<"goodpkg">>,<<"2.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]},
{{<<"badpkg">>,<<"1.0.0">>}, [[], ?good_checksum, [<<"rebar3">>]]}
]),
CacheDir = filename:join([CacheRoot, "hex", "com", "test", "packages"]),
diff --git a/test/rebar_plugins_SUITE.erl b/test/rebar_plugins_SUITE.erl
index 3df3c0e..355e156 100644
--- a/test/rebar_plugins_SUITE.erl
+++ b/test/rebar_plugins_SUITE.erl
@@ -10,7 +10,10 @@
compile_global_plugins/1,
complex_plugins/1,
list/1,
- upgrade/1]).
+ upgrade/1,
+ sub_app_plugins/1,
+ sub_app_plugin_overrides/1,
+ project_plugins/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -32,7 +35,7 @@ end_per_testcase(_, _Config) ->
catch meck:unload().
all() ->
- [compile_plugins, compile_global_plugins, complex_plugins, list, upgrade].
+ [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) ->
@@ -208,3 +211,121 @@ upgrade(Config) ->
Config, RConf, ["plugins", "upgrade", PkgName],
{ok, [{app, Name}, {plugin, PkgName, <<"0.1.3">>}]}
).
+
+sub_app_plugins(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("sub_app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+
+ DepName = rebar_test_utils:create_random_name("dep1_"),
+ PluginName = rebar_test_utils:create_random_name("plugin1_"),
+
+ mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(DepName), list_to_binary(Vsn)}, []},
+ {{list_to_binary(PluginName), list_to_binary(Vsn)}, []}]}]),
+
+ SubAppsDir = filename:join([AppDir, "apps", Name]),
+
+ rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
+ rebar_test_utils:create_config(SubAppsDir, [{deps, [{list_to_binary(DepName), list_to_binary(Vsn)}]},
+ {plugins, [list_to_atom(PluginName)]}]),
+
+ RConfFile =
+ rebar_test_utils:create_config(AppDir,
+ [{deps, [
+ list_to_atom(DepName)
+ ]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ Config, RConf, ["compile"],
+ {ok, [{app, Name}, {dep, DepName}, {plugin, PluginName}]}
+ ).
+
+%% Tests that overrides in a dep that includes a plugin are applied to plugin fetching
+sub_app_plugin_overrides(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("sub_app1_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ Dep2Name = rebar_test_utils:create_random_name("dep2_"),
+
+ DepName = rebar_test_utils:create_random_name("dep1_"),
+ PluginName = rebar_test_utils:create_random_name("plugin1_"),
+ Vsn2 = rebar_test_utils:create_random_vsn(),
+
+ Deps = rebar_test_utils:expand_deps(git, [{PluginName, Vsn, [{DepName, Vsn, []}]},
+ {DepName, Vsn, []}]),
+ {SrcDeps, _} = rebar_test_utils:flat_deps(Deps),
+ mock_git_resource:mock([{deps, SrcDeps}]),
+
+ mock_pkg_resource:mock([{pkgdeps, [{{list_to_binary(Dep2Name), list_to_binary(Vsn)}, []}]},
+ {config, [{plugins, [{list_to_atom(PluginName),
+ {git, "http://site.com/user/"++PluginName++".git",
+ {tag, Vsn}}}]},
+ %% Dep2 overrides the plugin's deps to have vsn2 of dep1
+ {overrides, [{override, list_to_atom(PluginName),
+ [{deps, [{list_to_atom(DepName),
+ {git, "http://site.com/user/"++DepName++".git",
+ {tag, Vsn2}}}]}]}]}]}]),
+
+ SubAppsDir = filename:join([AppDir, "apps", Name]),
+
+ rebar_test_utils:create_app(SubAppsDir, Name, Vsn, [kernel, stdlib]),
+
+ RConfFile = rebar_test_utils:create_config(AppDir, [{deps, [{list_to_binary(Dep2Name), list_to_binary(Vsn)}]}]),
+ {ok, RConf} = file:consult(RConfFile),
+
+ %% Build with deps.
+ rebar_test_utils:run_and_check(
+ 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_release_SUITE.erl b/test/rebar_release_SUITE.erl
index e0fa5a0..1125a7e 100644
--- a/test/rebar_release_SUITE.erl
+++ b/test/rebar_release_SUITE.erl
@@ -10,7 +10,8 @@ all() -> [release,
profile_ordering_sys_config_extend,
profile_ordering_sys_config_extend_3_tuple_merge,
extend_release,
- user_output_dir].
+ user_output_dir, profile_overlays,
+ overlay_vars].
init_per_testcase(Case, Config0) ->
Config = rebar_test_utils:init_rebar_state(Config0),
@@ -193,3 +194,79 @@ user_output_dir(Config) ->
{ok, RelxState2} = rlx_prv_app_discover:do(RelxState1),
{ok, RelxState3} = rlx_prv_rel_discover:do(RelxState2),
rlx_state:get_realized_release(RelxState3, list_to_atom(Name), Vsn).
+
+profile_overlays(Config) ->
+ AppDir = ?config(apps, Config),
+ Name = ?config(name, Config),
+ Vsn = "1.0.0",
+ {ok, RebarConfig} =
+ file:consult(rebar_test_utils:create_config(AppDir,
+ [{relx, [{release, {list_to_atom(Name), Vsn},
+ [list_to_atom(Name)]},
+ {overlay, [{mkdir, "randomdir"}]},
+ {lib_dirs, [AppDir]}]},
+ {profiles, [{prod, [{relx, [{overlay, [{mkdir, "otherrandomdir"}]}]}]}]}])),
+
+ ReleaseDir = filename:join([AppDir, "./_build/prod/rel/", Name]),
+
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig,
+ ["as", "prod", "release"],
+ {ok, [{release, list_to_atom(Name), Vsn, false},
+ {dir, filename:join(ReleaseDir, "otherrandomdir")},
+ {dir, filename:join(ReleaseDir, "randomdir")}]}
+ ).
+
+overlay_vars(Config) ->
+ AppDir = ?config(apps, Config),
+ Name = ?config(name, Config),
+ Vsn = "1.0.0",
+ {ok, RebarConfig} =
+ file:consult(rebar_test_utils:create_config(AppDir,
+ [{relx, [{release, {list_to_atom(Name), Vsn},
+ [list_to_atom(Name)]},
+ {overlay, [
+ {template, filename:join([AppDir, "config/app.config"]),
+ "releases/{{release_version}}/sys.config"}
+ ]},
+ {overlay_vars, filename:join([AppDir, "config/vars.config"])},
+ {lib_dirs, [AppDir]}]}
+ ])),
+
+ ok = filelib:ensure_dir(filename:join([AppDir, "config", "dummy"])),
+
+ OverlayVars = [{var_int, 1},
+ {var_string, "\"test\""},
+ {var_bin_string, "<<\"test\">>"},
+ {var_tuple, "{t, ['atom']}"},
+ {var_list, "[a, b, c, 'd']"},
+ {var_bin, "<<23, 24, 25>>"}],
+ rebar_test_utils:create_config(AppDir,
+ filename:join([AppDir, "config", "vars.config"]),
+ OverlayVars),
+
+ AppConfig = [[{var_int, {{var_int}}},
+ {var_string, {{{var_string}}}},
+ {var_bin_string, {{{var_bin_string}}}},
+ {var_tuple, {{{var_tuple}}}},
+ {var_list, {{{var_list}}}},
+ {var_bin, {{{var_bin}}}}]],
+ rebar_test_utils:create_config(AppDir,
+ filename:join([AppDir, "config", "app.config"]),
+ AppConfig),
+
+ rebar_test_utils:run_and_check(
+ Config, RebarConfig,
+ ["release"],
+ {ok, [{release, list_to_atom(Name), Vsn, false}]}),
+
+ %% now consult the sys.config file to make sure that is has the expected
+ %% format
+ ExpectedSysconfig = [{var_int, 1},
+ {var_string, "test"},
+ {var_bin_string, <<"test">>},
+ {var_tuple, {t, ['atom']}},
+ {var_list, [a, b, c, 'd']},
+ {var_bin, <<23, 24, 25>>}],
+ {ok, [ExpectedSysconfig]} = file:consult(filename:join([AppDir, "_build/default/rel",
+ Name, "releases", Vsn, "sys.config"])).
diff --git a/test/rebar_test_utils.erl b/test/rebar_test_utils.erl
index 3943db7..23b0178 100644
--- a/test/rebar_test_utils.erl
+++ b/test/rebar_test_utils.erl
@@ -3,8 +3,8 @@
-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, create_config/2,
- package_app/3]).
+-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
@@ -104,11 +114,14 @@ create_empty_app(AppDir, Name, Vsn, Deps) ->
%% each of which will be dumped as a consult file. For example, the list
%% `[a, b, c]' will return the consult file `a. b. c.'.
create_config(AppDir, Contents) ->
- Conf = filename:join([AppDir, "rebar.config"]),
- ok = filelib:ensure_dir(Conf),
+ ConfFilename = filename:join([AppDir, "rebar.config"]),
+ create_config(AppDir, ConfFilename, Contents).
+
+create_config(_AppDir, ConfFilename, Contents) ->
+ ok = filelib:ensure_dir(ConfFilename),
Config = lists:flatten([io_lib:fwrite("~p.~n", [Term]) || Term <- Contents]),
- ok = ec_file:write(Conf, Config),
- Conf.
+ ok = ec_file:write(ConfFilename, Config),
+ ConfFilename.
%% @doc Util to create a random variation of a given name.
create_random_name(Name) ->
@@ -362,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),
@@ -392,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"