summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rebar_cover_SUITE.erl8
-rw-r--r--test/rebar_ct_SUITE.erl2
-rw-r--r--test/rebar_dir_SUITE.erl36
-rw-r--r--test/rebar_upgrade_SUITE.erl52
4 files changed, 87 insertions, 11 deletions
diff --git a/test/rebar_cover_SUITE.erl b/test/rebar_cover_SUITE.erl
index a838d7d..841e29f 100644
--- a/test/rebar_cover_SUITE.erl
+++ b/test/rebar_cover_SUITE.erl
@@ -90,7 +90,7 @@ basic_extra_src_dirs(Config) ->
{file, _} = cover:is_compiled(Mod),
ExtraMod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
- {file, _} = cover:is_compiled(ExtraMod).
+ false = cover:is_compiled(ExtraMod).
release_extra_src_dirs(Config) ->
AppDir = ?config(apps, Config),
@@ -129,9 +129,9 @@ release_extra_src_dirs(Config) ->
{file, _} = cover:is_compiled(Mod2),
ExtraMod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
- {file, _} = cover:is_compiled(ExtraMod1),
+ false = cover:is_compiled(ExtraMod1),
ExtraMod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
- {file, _} = cover:is_compiled(ExtraMod2).
+ false = cover:is_compiled(ExtraMod2).
root_extra_src_dirs(Config) ->
AppDir = ?config(apps, Config),
@@ -160,7 +160,7 @@ root_extra_src_dirs(Config) ->
Mod2 = list_to_atom(Name2),
{file, _} = cover:is_compiled(Mod2),
- {file, _} = cover:is_compiled(extra).
+ false = cover:is_compiled(extra).
index_written(Config) ->
AppDir = ?config(apps, Config),
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 1da7571..e409c29 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -726,7 +726,7 @@ suite_at_app_root(Config) ->
data_dir_correct(Config) ->
DataDir = ?config(data_dir, Config),
Parts = filename:split(DataDir),
- ["rebar_ct_SUITE_data","test","rebar","lib","test","_build"|_] = lists:reverse(Parts).
+ ["rebar_ct_SUITE_data","test","rebar","lib",_,"_build"|_] = lists:reverse(Parts).
cmd_label(Config) ->
State = ?config(result, Config),
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 1221db7..9734830 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -6,6 +6,7 @@
-export([src_dirs/1, extra_src_dirs/1, all_src_dirs/1]).
-export([profile_src_dirs/1, profile_extra_src_dirs/1, profile_all_src_dirs/1]).
-export([retarget_path/1, alt_base_dir_abs/1, alt_base_dir_rel/1]).
+-export([global_cache_dir/1, default_global_cache_dir/1, overwrite_default_global_cache_dir/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -15,8 +16,20 @@
all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
src_dirs, extra_src_dirs, all_src_dirs,
profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs,
- retarget_path, alt_base_dir_abs, alt_base_dir_rel].
-
+ retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir,
+ default_global_cache_dir, overwrite_default_global_cache_dir].
+
+init_per_testcase(default_global_cache_dir, Config) ->
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
+ NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
+init_per_testcase(overwrite_default_global_cache_dir, Config) ->
+ os:putenv("REBAR_CACHE_DIR", ?config(priv_dir, Config)),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
+ NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
+ ,{root_dir, AppsDir}]),
+ [{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
init_per_testcase(_, Config) ->
C = rebar_test_utils:init_rebar_state(Config),
AppDir = ?config(apps, C),
@@ -162,3 +175,22 @@ alt_base_dir_rel(Config) ->
?assert(filelib:is_dir(filename:join([BaseDir, "lib", Name2, "ebin"]))),
?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".app"]))),
?assert(filelib:is_file(filename:join([BaseDir, "lib", Name2, "ebin", Name2++".beam"]))).
+
+global_cache_dir(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ DataDir = ?config(priv_dir, Config),
+ Expected = filename:join([DataDir, "cache"]),
+ ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
+
+default_global_cache_dir(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ Expected = filename:join([rebar_dir:home_dir(), ".cache", "rebar3"]),
+ ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
+
+overwrite_default_global_cache_dir(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ Expected = ?config(priv_dir, Config),
+ ?assertEqual(Expected, rebar_dir:global_cache_dir(rebar_state:opts(State))).
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index cfe1d8a..e7651a1 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -11,7 +11,7 @@ groups() ->
triplet_a, triplet_b, triplet_c,
tree_a, tree_b, tree_c, tree_c2, tree_cj, tree_ac, tree_all,
delete_d, promote, stable_lock, fwd_lock,
- compile_upgrade_parity]},
+ compile_upgrade_parity, umbrella_config]},
{git, [], [{group, all}]},
{pkg, [], [{group, all}]}].
@@ -66,6 +66,18 @@ end_per_testcase(_, Config) ->
meck:unload(),
Config.
+setup_project(Case=umbrella_config, Config0, Deps, UpDeps) ->
+ DepsType = ?config(deps_type, Config0),
+ NameRoot = atom_to_list(Case)++"_"++atom_to_list(DepsType),
+ Config = rebar_test_utils:init_rebar_state(Config0, NameRoot++"_"),
+ AppDir = filename:join([?config(apps, Config), "apps", NameRoot]),
+ rebar_test_utils:create_app(AppDir, "Root", "0.0.0", [kernel, stdlib]),
+ TopDeps = rebar_test_utils:top_level_deps(Deps),
+ TopConf = rebar_test_utils:create_config(AppDir, [{deps, []}]),
+ RebarConf = rebar_test_utils:create_config(AppDir, [{deps, TopDeps}]),
+ [{rebarconfig, TopConf},
+ {rebarumbrella, RebarConf},
+ {next_top_deps, rebar_test_utils:top_level_deps(UpDeps)} | Config];
setup_project(Case, Config0, Deps, UpDeps) ->
DepsType = ?config(deps_type, Config0),
Config = rebar_test_utils:init_rebar_state(
@@ -437,7 +449,12 @@ upgrades(compile_upgrade_parity) ->
[],
{"", [{"A","1"}, "D", "J", "E", {"I","1"},
{"B","1"}, "F", "G",
- {"C","1"}, "H"]}}.
+ {"C","1"}, "H"]}};
+upgrades(umbrella_config) ->
+ {[{"A", "1", []}],
+ [{"A", "2", []}],
+ ["A"],
+ {"A", [{"A","2"}]}}.
%% TODO: add a test that verifies that unlocking files and then
%% running the upgrade code is enough to properly upgrade things.
@@ -570,9 +587,36 @@ compile_upgrade_parity(Config) ->
?assertEqual(CompileLockData1, CompileLockData2),
?assertEqual(CompileLockData1, UpgradeLockData).
+umbrella_config(Config) ->
+ apply(?config(mock, Config), []),
+ {ok, TopConfig} = file:consult(?config(rebarconfig, Config)),
+ %% Install dependencies before re-mocking for an upgrade
+ rebar_test_utils:run_and_check(Config, TopConfig, ["lock"], {ok, []}),
+ {App, Unlocks} = ?config(expected, Config),
+ ct:pal("Upgrades: ~p -> ~p", [App, Unlocks]),
+ Expectation = case Unlocks of
+ {error, Term} -> {error, Term};
+ _ -> {ok, Unlocks}
+ end,
+
+ meck:new(rebar_prv_upgrade, [passthrough]),
+ meck:expect(rebar_prv_upgrade, do, fun(S) ->
+ apply(?config(mock_update, Config), []),
+ meck:passthrough([S])
+ end),
+ _NewRebarConf = rebar_test_utils:create_config(filename:dirname(?config(rebarumbrella, Config)),
+ [{deps, ?config(next_top_deps, Config)}]),
+ %% re-run from the top-level with the old config still in place;
+ %% detection must happen when going for umbrella apps!
+ rebar_test_utils:run_and_check(
+ Config, TopConfig, ["upgrade", App], Expectation
+ ),
+ meck:unload(rebar_prv_upgrade).
+
run(Config) ->
apply(?config(mock, Config), []),
- {ok, RebarConfig} = file:consult(?config(rebarconfig, Config)),
+ ConfigPath = ?config(rebarconfig, Config),
+ {ok, RebarConfig} = file:consult(ConfigPath),
%% Install dependencies before re-mocking for an upgrade
rebar_test_utils:run_and_check(Config, RebarConfig, ["lock"], {ok, []}),
{App, Unlocks} = ?config(expected, Config),
@@ -587,7 +631,7 @@ run(Config) ->
apply(?config(mock_update, Config), []),
meck:passthrough([S])
end),
- NewRebarConf = rebar_test_utils:create_config(?config(apps, Config),
+ NewRebarConf = rebar_test_utils:create_config(filename:dirname(ConfigPath),
[{deps, ?config(next_top_deps, Config)}]),
{ok, NewRebarConfig} = file:consult(NewRebarConf),
rebar_test_utils:run_and_check(