summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiri Hansen <siri@erlang.org>2016-12-13 12:51:01 +0100
committerSiri Hansen <siri@erlang.org>2016-12-13 12:51:01 +0100
commita18340c6eed6e62237c4ec63f15daacfe86dc86c (patch)
tree3f9bf6f204ea1f03da63e92a0f6eaa7e63791d2f
parente427a835301c41a1403cf6b9e6c363ceae3e781c (diff)
Allow using relative path to suite in project root
-rw-r--r--src/rebar_prv_common_test.erl15
-rw-r--r--test/rebar_ct_SUITE.erl55
2 files changed, 54 insertions, 16 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index cb33492..9db8106 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -529,26 +529,13 @@ translate_paths(_State, _Type, [], Acc) -> lists:reverse(Acc);
translate_paths(State, Type, [{Type, Val}|Rest], Acc) when is_integer(hd(Val)) ->
%% single file or dir
translate_paths(State, Type, [{Type, [Val]}|Rest], Acc);
-translate_paths(State, dir, [{dir, Dirs}|Rest], Acc) ->
- Apps = rebar_state:project_apps(State),
- New = {dir, lists:map(fun(Dir) -> translate(State, Apps, Dir) end, Dirs)},
- translate_paths(State, dir, Rest, [New|Acc]);
translate_paths(State, Type, [{Type, Files}|Rest], Acc) ->
- %% Type = suites | specs
Apps = rebar_state:project_apps(State),
- New = {Type, lists:map(fun(File) -> translate_file(State, Apps, File) end, Files)},
+ New = {Type, lists:map(fun(File) -> translate(State, Apps, File) end, Files)},
translate_paths(State, Type, Rest, [New|Acc]);
translate_paths(State, Type, [Test|Rest], Acc) ->
translate_paths(State, Type, Rest, [Test|Acc]).
-translate_file(State, Apps, File) ->
- Dirname = filename:dirname(File),
- Basename = filename:basename(File),
- case Dirname of
- "." -> File;
- _ -> filename:join([translate(State, Apps, Dirname), Basename])
- end.
-
translate(State, [App|Rest], Path) ->
case rebar_file_utils:path_from_ancestor(Path, rebar_app_info:dir(App)) of
{ok, P} -> filename:join([rebar_app_info:out_dir(App), P]);
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 6339e6b..a47ea58 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -693,7 +693,33 @@ suite_at_root(Config) ->
true = filelib:is_dir(DataDir),
DataFile = filename:join([AppDir, "_build", "test", "extras", "root_SUITE_data", "some_data.txt"]),
- true = filelib:is_file(DataFile).
+ true = filelib:is_file(DataFile),
+
+ %% Same test again, but using relative path to the suite from the
+ %% project root
+ {ok,Cwd} = file:get_cwd(),
+ ok = file:set_cwd(AppDir),
+ rebar_file_utils:rm_rf("_build"),
+
+ {ok, GetOptResult2} = getopt:parse(GetOptSpec, ["--suite=" ++ "root_SUITE"]),
+
+ State3 = rebar_state:command_parsed_args(State1, GetOptResult2),
+
+ Tests2 = rebar_prv_common_test:prepare_tests(State3),
+ {ok, NewState2} = rebar_prv_common_test:compile(State3, Tests2),
+ {ok, T2} = Tests2,
+ Opts2 = rebar_prv_common_test:translate_paths(NewState2, T2),
+
+ ok = file:set_cwd(Cwd),
+
+ Suite2 = proplists:get_value(suite, Opts2),
+ [Expected] = Suite2,
+ true = filelib:is_file(TestHrl),
+ true = filelib:is_file(TestBeam),
+ true = filelib:is_dir(DataDir),
+ true = filelib:is_file(DataFile),
+
+ ok.
suite_at_app_root(Config) ->
AppDir = ?config(apps, Config),
@@ -730,7 +756,32 @@ suite_at_app_root(Config) ->
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).
+ true = filelib:is_file(DataFile),
+
+ %% Same test again using relative path to the suite from the project root
+ {ok,Cwd} = file:get_cwd(),
+ ok = file:set_cwd(AppDir),
+ rebar_file_utils:rm_rf("_build"),
+
+ {ok, GetOptResult2} = getopt:parse(GetOptSpec, ["--suite=" ++ filename:join(["apps", Name2, "app_root_SUITE"])]),
+
+ State3 = rebar_state:command_parsed_args(State1, GetOptResult2),
+
+ Tests2 = rebar_prv_common_test:prepare_tests(State3),
+ {ok, NewState2} = rebar_prv_common_test:compile(State3, Tests2),
+ {ok, T2} = Tests2,
+ Opts2 = rebar_prv_common_test:translate_paths(NewState2, T2),
+
+ ok = file:set_cwd(Cwd),
+
+ Suite2 = proplists:get_value(suite, Opts2),
+ [Expected] = Suite2,
+ true = filelib:is_file(TestHrl),
+ true = filelib:is_file(TestBeam),
+ true = filelib:is_dir(DataDir),
+ true = filelib:is_file(DataFile),
+
+ ok.
%% this test probably only fails when this suite is run via rebar3 with the --cover flag
data_dir_correct(Config) ->