summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/rebar_dir_SUITE.erl31
-rw-r--r--test/rebar_discover_SUITE.erl69
-rw-r--r--test/rebar_edoc_SUITE.erl10
-rw-r--r--test/rebar_edoc_SUITE_data/foo/apps/foo/rebar.config1
-rw-r--r--test/rebar_edoc_SUITE_data/foo/rebar.config1
5 files changed, 110 insertions, 2 deletions
diff --git a/test/rebar_dir_SUITE.erl b/test/rebar_dir_SUITE.erl
index 81051e6..2a5d0ca 100644
--- a/test/rebar_dir_SUITE.erl
+++ b/test/rebar_dir_SUITE.erl
@@ -10,6 +10,7 @@
-export([profile_src_dir_opts/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]).
+-export([default_global_config/1, overwrite_default_global_config/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -21,7 +22,8 @@ all() -> [default_src_dirs, default_extra_src_dirs, default_all_src_dirs,
profile_src_dirs, profile_extra_src_dirs, profile_all_src_dirs,
profile_src_dir_opts, top_src_dirs,
retarget_path, alt_base_dir_abs, alt_base_dir_rel, global_cache_dir,
- default_global_cache_dir, overwrite_default_global_cache_dir].
+ default_global_cache_dir, overwrite_default_global_cache_dir,
+ default_global_config, overwrite_default_global_config].
init_per_testcase(default_global_cache_dir, Config) ->
[{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, _State} | Config] = rebar_test_utils:init_rebar_state(Config),
@@ -34,6 +36,19 @@ init_per_testcase(overwrite_default_global_cache_dir, Config) ->
NewState = rebar_state:new([{base_dir, filename:join([AppsDir, "_build"])}
,{root_dir, AppsDir}]),
[{apps, AppsDir}, {checkouts, CheckoutsDir}, {state, NewState} | Config];
+init_per_testcase(default_global_config, 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_config, Config) ->
+ ConfDir = filename:join([?config(priv_dir, Config), "custom"]),
+ ok = file:make_dir(ConfDir),
+ os:putenv("REBAR_GLOBAL_CONFIG_DIR", ConfDir),
+ [{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),
@@ -282,3 +297,17 @@ overwrite_default_global_cache_dir(Config) ->
{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))).
+
+default_global_config(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ ConfDir = ?config(priv_dir, Config),
+ Expected = filename:join([ConfDir, ".config", "rebar3", "rebar.config"]),
+ ?assertEqual(Expected, rebar_dir:global_config(State)).
+
+overwrite_default_global_config(Config) ->
+ RebarConfig = [{erl_opts, []}],
+ {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"], return),
+ Expected = filename:join([os:getenv("REBAR_GLOBAL_CONFIG_DIR"), ".config", "rebar3", "rebar.config"]),
+ rebar_dir:global_config(State),
+ ?assertEqual(Expected, rebar_dir:global_config(State)).
diff --git a/test/rebar_discover_SUITE.erl b/test/rebar_discover_SUITE.erl
new file mode 100644
index 0000000..3fdd34b
--- /dev/null
+++ b/test/rebar_discover_SUITE.erl
@@ -0,0 +1,69 @@
+-module(rebar_discover_SUITE).
+-compile(export_all).
+
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+
+all() ->
+ [empty_app_src, bad_app_src, invalid_app_src].
+ %% note: invalid .app files without a .app.src also present
+ %% has rebar3 just ignoring the directory as not OTP-related.
+
+
+init_per_testcase(_, Config) ->
+ NewConfig = rebar_test_utils:init_rebar_state(Config, "discover_app_"),
+ AppDir = ?config(apps, NewConfig),
+
+ 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].
+
+end_per_testcase(_, Config) ->
+ Config.
+
+empty_app_src() ->
+ [{doc, "when there's an empty .app.src file, exit with a good error "
+ "message rather than an uncaught exception"}].
+empty_app_src(Config) ->
+ AppDir = ?config(apps, Config),
+ [Name] = ?config(app_names, Config),
+ AppSrc = filename:join([AppDir, "src", Name ++ ".app.src"]),
+ ok = file:write_file(AppSrc, ""),
+ ?assertEqual(
+ {error, {rebar_app_discover, {cannot_read_app_file, AppSrc}}},
+ rebar_test_utils:run_and_check(Config, [], ["compile"], return)
+ ),
+ ok.
+
+bad_app_src() ->
+ [{doc, "when there's a syntactically invalid "
+ ".app.src file, exit with a good error "
+ "message rather than an uncaught exception"}].
+bad_app_src(Config) ->
+ AppDir = ?config(apps, Config),
+ [Name] = ?config(app_names, Config),
+ AppSrc = filename:join([AppDir, "src", Name ++ ".app.src"]),
+ ok = file:write_file(AppSrc, "bad term file :("),
+ ?assertMatch(
+ {error, {rebar_app_discover, {bad_term_file, AppSrc, _}}},
+ rebar_test_utils:run_and_check(Config, [], ["compile"], return)
+ ),
+ ok.
+
+invalid_app_src() ->
+ [{doc, "when there's a syntactically valid but semantically invalid "
+ ".app.src file, exit with a good error "
+ "message rather than an uncaught exception"}].
+invalid_app_src(Config) ->
+ AppDir = ?config(apps, Config),
+ [Name] = ?config(app_names, Config),
+ AppSrc = filename:join([AppDir, "src", Name ++ ".app.src"]),
+ ok = file:write_file(AppSrc, "{applications, name_but_no_args}."),
+ ?assertEqual(
+ {error, {rebar_app_discover, {cannot_read_app_file, AppSrc}}},
+ rebar_test_utils:run_and_check(Config, [], ["compile"], return)
+ ),
+ ok.
+
diff --git a/test/rebar_edoc_SUITE.erl b/test/rebar_edoc_SUITE.erl
index 64ec0c8..2f0fad0 100644
--- a/test/rebar_edoc_SUITE.erl
+++ b/test/rebar_edoc_SUITE.erl
@@ -52,7 +52,15 @@ multiapp(Config) ->
"barer1")),
?assert(file_content_matches(
filename:join([AppsDir, "apps", "foo", "doc", "foo.html"]),
- "apps/bar1/doc/bar1.html")).
+ "apps/bar1/doc/bar1.html")),
+ %% Options such from rebar.config in the app themselves are
+ %% respected
+ ?assert(file_content_matches(
+ filename:join([AppsDir, "apps", "foo", "doc", "overview-summary.html"]),
+ "foo_custom_title"
+ )),
+ ok.
+
error_survival(Config) ->
RebarConfig = [],
diff --git a/test/rebar_edoc_SUITE_data/foo/apps/foo/rebar.config b/test/rebar_edoc_SUITE_data/foo/apps/foo/rebar.config
new file mode 100644
index 0000000..970d4e2
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/foo/apps/foo/rebar.config
@@ -0,0 +1 @@
+{edoc_opts, [{title, "foo_custom_title"}]}.
diff --git a/test/rebar_edoc_SUITE_data/foo/rebar.config b/test/rebar_edoc_SUITE_data/foo/rebar.config
new file mode 100644
index 0000000..b5d44fa
--- /dev/null
+++ b/test/rebar_edoc_SUITE_data/foo/rebar.config
@@ -0,0 +1 @@
+{edoc_opts, [{title, "forced wrong title to be overridden"}]}.