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.erl50
-rw-r--r--test/rebar_deps_SUITE.erl73
-rw-r--r--test/rebar_upgrade_SUITE.erl52
4 files changed, 170 insertions, 13 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..c10875b 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -41,6 +41,7 @@
cmd_scale_timetraps/1,
cmd_create_priv_dir/1,
cmd_include_dir/1,
+ cmd_sys_config/1,
cfg_opts/1,
cfg_arbitrary_opts/1,
cfg_test_spec/1,
@@ -51,6 +52,7 @@
misspecified_ct_compile_opts/1,
misspecified_ct_first_files/1]).
+-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
all() -> [{group, basic_app},
@@ -102,7 +104,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
cmd_multiply_timetraps,
cmd_scale_timetraps,
cmd_create_priv_dir,
- cmd_include_dir]},
+ cmd_include_dir,
+ cmd_sys_config]},
{cover, [], [cover_compiled]}].
init_per_group(basic_app, Config) ->
@@ -726,7 +729,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),
@@ -1020,7 +1023,41 @@ cmd_include_dir(Config) ->
CompileOpts = proplists:get_value(options, Info),
true = lists:member({i, "foo/bar/baz"}, CompileOpts),
true = lists:member({i, "qux"}, CompileOpts).
-
+
+cmd_sys_config(Config) ->
+ State = ?config(result, Config),
+ AppDir = ?config(apps, Config),
+ Name = ?config(name, Config),
+ AppName = list_to_atom(Name),
+
+ {ok, _} = rebar_prv_common_test:prepare_tests(State),
+ ?assertEqual(undefined, application:get_env(AppName, key)),
+
+ CfgFile = filename:join([AppDir, "config", "cfg_sys.config"]),
+ ok = filelib:ensure_dir(CfgFile),
+ ok = file:write_file(CfgFile, cfg_sys_config_file(AppName)),
+ RebarConfig = [{ct_opts, [{sys_config, CfgFile}]}],
+ {ok, State1} = rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "test", "lock"], return),
+
+ {ok, _} = rebar_prv_common_test:prepare_tests(State1),
+ ?assertEqual({ok, cfg_value}, application:get_env(AppName, key)),
+
+ Providers = rebar_state:providers(State1),
+ Namespace = rebar_state:namespace(State1),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+
+ CmdFile = filename:join([AppDir, "config", "cmd_sys.config"]),
+ ok = filelib:ensure_dir(CmdFile),
+ ok = file:write_file(CmdFile, cmd_sys_config_file(AppName)),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--sys_config="++CmdFile]),
+ State2 = rebar_state:command_parsed_args(State1, GetOptResult),
+
+ {ok, _} = rebar_prv_common_test:prepare_tests(State2),
+
+ ?assertEqual({ok ,cmd_value}, application:get_env(AppName, key)).
+
+
cfg_opts(Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_opts_"),
@@ -1181,10 +1218,15 @@ misspecified_ct_first_files(Config) ->
{badconfig, {"Value `~p' of option `~p' must be a list", {some_file, ct_first_files}}} = Error.
-
%% helper for generating test data
test_suite(Name) ->
io_lib:format("-module(~ts_SUITE).\n"
"-compile(export_all).\n"
"all() -> [some_test].\n"
"some_test(_) -> ok.\n", [Name]).
+
+cmd_sys_config_file(AppName) ->
+ io_lib:format("[{~s, [{key, cmd_value}]}].", [AppName]).
+
+cfg_sys_config_file(AppName) ->
+ io_lib:format("[{~s, [{key, cfg_value}]}].", [AppName]).
diff --git a/test/rebar_deps_SUITE.erl b/test/rebar_deps_SUITE.erl
index c95854a..aa2e7b2 100644
--- a/test/rebar_deps_SUITE.erl
+++ b/test/rebar_deps_SUITE.erl
@@ -3,7 +3,11 @@
-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, semver_matching_lt, semver_matching_lte, semver_matching_gt, valid_version, {group, git}, {group, pkg}].
+all() -> [sub_app_deps, newly_added_dep, newly_added_after_empty_lock,
+ http_proxy_settings, https_proxy_settings,
+ http_os_proxy_settings, https_os_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,
@@ -82,6 +86,47 @@ init_per_testcase(https_proxy_settings, Config) ->
rebar_test_utils:create_config(GlobalConfigDir,
[{https_proxy, "http://localhost:1234"}
]),
+ %% Add a bad value by default to show config overtakes default
+ os:putenv("https_proxy", "unparseable-garbage"),
+ rebar_test_utils:init_rebar_state(Config)
+ end;
+init_per_testcase(http_os_proxy_settings, Config) ->
+ %% Create private rebar.config
+ Priv = ?config(priv_dir, Config),
+ GlobalDir = filename:join(Priv, "global"),
+ GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
+ GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
+
+ meck:new(rebar_dir, [passthrough]),
+ meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
+ meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
+
+ %% Insert proxy variables into os env, but not config
+ os:putenv("http_proxy", "http://localhost:1234"),
+ rebar_test_utils:create_config(GlobalConfigDir, []),
+ rebar_test_utils:init_rebar_state(Config);
+init_per_testcase(https_os_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,
+ if not SupportsHttpsProxy ->
+ {skip, https_proxy_unsupported_before_R16};
+ SupportsHttpsProxy ->
+ %% Create private rebar.config
+ Priv = ?config(priv_dir, Config),
+ GlobalDir = filename:join(Priv, "global"),
+ GlobalConfigDir = filename:join([GlobalDir, ".config", "rebar3"]),
+ GlobalConfig = filename:join([GlobalDir, ".config", "rebar3", "rebar.config"]),
+
+ meck:new(rebar_dir, [passthrough]),
+ meck:expect(rebar_dir, global_config, fun() -> GlobalConfig end),
+ meck:expect(rebar_dir, global_cache_dir, fun(_) -> GlobalDir end),
+
+ %% Insert proxy variables into os env, not in config
+ os:putenv("https_proxy", "http://localhost:1234"),
+ rebar_test_utils:create_config(GlobalConfigDir, []),
rebar_test_utils:init_rebar_state(Config)
end;
init_per_testcase(Case, Config) ->
@@ -97,11 +142,20 @@ init_per_testcase(Case, Config) ->
| setup_project(Case, Config, rebar_test_utils:expand_deps(DepsType, Deps))].
end_per_testcase(https_proxy_settings, Config) ->
+ os:putenv("https_proxy", ""),
meck:unload(rebar_dir),
Config;
end_per_testcase(http_proxy_settings, Config) ->
meck:unload(rebar_dir),
Config;
+end_per_testcase(http_os_proxy_settings, Config) ->
+ os:putenv("http_proxy", ""),
+ meck:unload(rebar_dir),
+ Config;
+end_per_testcase(https_os_proxy_settings, Config) ->
+ os:putenv("https_proxy", ""),
+ meck:unload(rebar_dir),
+ Config;
end_per_testcase(_, Config) ->
meck:unload(),
Config.
@@ -311,6 +365,23 @@ https_proxy_settings(_Config) ->
?assertEqual({ok,{{"localhost", 1234}, []}},
httpc:get_option(https_proxy, rebar)).
+http_os_proxy_settings(_Config) ->
+ %% Load config
+ rebar_utils:set_httpc_options(),
+ rebar3:init_config(),
+
+ %% Assert variable is right
+ ?assertEqual({ok,{{"localhost", 1234}, []}},
+ httpc:get_option(proxy, rebar)).
+
+https_os_proxy_settings(_Config) ->
+ %% Load config
+ rebar_utils:set_httpc_options(),
+ rebar3:init_config(),
+
+ %% Assert variable is right
+ ?assertEqual({ok,{{"localhost", 1234}, []}},
+ httpc:get_option(https_proxy, rebar)).
semver_matching_lt(_Config) ->
Dep = <<"test">>,
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(