summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_common_test.erl3
-rw-r--r--test/rebar_ct_SUITE.erl45
2 files changed, 46 insertions, 2 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 2a76ebb..1136e08 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -381,7 +381,8 @@ maybe_inject_test_dir(State, AppAcc, [App|Rest], Dir) ->
%% the current compiler tries to compile all subdirs including priv
%% instead copy only files ending in `.erl' and directories
%% ending in `_SUITE_data' into the `_build/PROFILE/extras' dir
- ExtrasDir = filename:join([rebar_dir:base_dir(State), "extras"]),
+ {ok, RelAppDir} = rebar_file_utils:path_from_ancestor(rebar_app_info:dir(App), rebar_state:dir(State)),
+ ExtrasDir = filename:join([rebar_dir:base_dir(State), "extras", RelAppDir]),
ok = copy_bare_suites(Dir, ExtrasDir),
Opts = inject_test_dir(rebar_state:opts(State), ExtrasDir),
{rebar_state:opts(State, Opts), AppAcc};
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 41a7c80..d572cc2 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -18,6 +18,7 @@
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,
@@ -74,7 +75,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
multi_suite,
all_suite,
single_dir_and_single_suite,
- suite_at_root]},
+ suite_at_root,
+ suite_at_app_root]},
{data_dirs, [], [data_dir_correct]},
{ct_opts, [], [cmd_label,
cmd_config,
@@ -187,6 +189,14 @@ init_per_group(dirs_and_suites, Config) ->
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];
@@ -646,6 +656,39 @@ suite_at_root(Config) ->
DataDir = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data"]),
true = filelib:is_dir(DataDir).
+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", "extras", "apps", Name2, "app_root_SUITE"]),
+ [Expected] = Suite,
+
+ TestHrl = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.hrl"]),
+ true = filelib:is_file(TestHrl),
+
+ TestBeam = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE.beam"]),
+ true = filelib:is_file(TestBeam),
+
+ DataDir = filename:join([AppDir, "_build", "test", "extras", "apps", Name2, "app_root_SUITE_data"]),
+ true = filelib:is_dir(DataDir).
%% this test probably only fails when this suite is run via rebar3 with the --cover flag
data_dir_correct(Config) ->