summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_common_test.erl61
-rw-r--r--test/rebar_ct_SUITE.erl27
2 files changed, 51 insertions, 37 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 17358a5..cb33492 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -513,44 +513,39 @@ inject_test_dir(Opts, Dir) ->
rebar_opts:set(Opts, extra_src_dirs, ExtraSrcDirs ++ [Dir]).
translate_paths(State, Opts) ->
- case {proplists:get_value(suite, Opts), proplists:get_value(dir, Opts)} of
- {_Suites, undefined} -> translate_suites(State, Opts, []);
- {undefined, _Dirs} -> translate_dirs(State, Opts, []);
- %% both dirs and suites are defined, only translate dir paths
- _ -> translate_dirs(State, Opts, [])
+ case proplists:get_value(spec, Opts) of
+ undefined ->
+ case {proplists:get_value(suite, Opts), proplists:get_value(dir, Opts)} of
+ {_Suites, undefined} -> translate_paths(State, suite, Opts, []);
+ {undefined, _Dirs} -> translate_paths(State, dir, Opts, []);
+ %% both dirs and suites are defined, only translate dir paths
+ _ -> translate_paths(State, dir, Opts, [])
+ end;
+ _Specs ->
+ translate_paths(State, spec, Opts, [])
end.
-translate_dirs(_State, [], Acc) -> lists:reverse(Acc);
-translate_dirs(State, [{dir, Dir}|Rest], Acc) when is_integer(hd(Dir)) ->
- %% single dir
- Apps = rebar_state:project_apps(State),
- translate_dirs(State, Rest, [{dir, translate(State, Apps, Dir)}|Acc]);
-translate_dirs(State, [{dir, Dirs}|Rest], Acc) ->
- %% multiple dirs
- Apps = rebar_state:project_apps(State),
- NewDirs = {dir, lists:map(fun(Dir) -> translate(State, Apps, Dir) end, Dirs)},
- translate_dirs(State, Rest, [NewDirs|Acc]);
-translate_dirs(State, [Test|Rest], Acc) ->
- translate_dirs(State, Rest, [Test|Acc]).
-
-translate_suites(_State, [], Acc) -> lists:reverse(Acc);
-translate_suites(State, [{suite, Suite}|Rest], Acc) when is_integer(hd(Suite)) ->
- %% single suite
+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),
- translate_suites(State, Rest, [{suite, translate_suite(State, Apps, Suite)}|Acc]);
-translate_suites(State, [{suite, Suites}|Rest], Acc) ->
- %% multiple suites
+ 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),
- NewSuites = {suite, lists:map(fun(Suite) -> translate_suite(State, Apps, Suite) end, Suites)},
- translate_suites(State, Rest, [NewSuites|Acc]);
-translate_suites(State, [Test|Rest], Acc) ->
- translate_suites(State, Rest, [Test|Acc]).
-
-translate_suite(State, Apps, Suite) ->
- Dirname = filename:dirname(Suite),
- Basename = filename:basename(Suite),
+ New = {Type, lists:map(fun(File) -> translate_file(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
- "." -> Suite;
+ "." -> File;
_ -> filename:join([translate(State, Apps, Dirname), Basename])
end.
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index d913748..6339e6b 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -1248,10 +1248,10 @@ testspec(Config) ->
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
Spec1 = filename:join([AppDir, "test", "some.spec"]),
ok = filelib:ensure_dir(Spec1),
- ok = file:write_file(Spec1, "[].\n"),
+ ok = file:write_file(Spec1, "{suites,\".\",all}.\n"),
Spec2 = filename:join([AppDir, "specs", "another.spec"]),
ok = filelib:ensure_dir(Spec2),
- ok = file:write_file(Spec2, "[].\n"),
+ ok = file:write_file(Spec2, "{suites,\"../test/\",all}.\n"),
{ok,Wd} = file:get_cwd(),
ok = file:set_cwd(AppDir),
@@ -1266,23 +1266,42 @@ testspec(Config) ->
CommandProvider = providers:get_provider(ct, Providers, Namespace),
GetOptSpec = providers:opts(CommandProvider),
+ %% Testspec in "test" directory
{ok, GetOptResult1} = getopt:parse(GetOptSpec, ["--spec","test/some.spec"]),
State1 = rebar_state:command_parsed_args(State, GetOptResult1),
Tests1 = rebar_prv_common_test:prepare_tests(State1),
{ok, NewState1} = rebar_prv_common_test:compile(State1, Tests1),
+ {ok, T1} = Tests1,
+ Opts1= rebar_prv_common_test:translate_paths(NewState1, T1),
+
+ %% check thath extra src dir is added
[App1] = rebar_state:project_apps(NewState1),
["test"] = rebar_dir:extra_src_dirs(rebar_app_info:opts(App1)),
+ %% check that path is translated
+ ExpectedSpec1 = filename:join([AppDir, "_build", "test", "lib", Name,
+ "test", "some.spec"]),
+ [ExpectedSpec1] = proplists:get_value(spec, Opts1),
+
+
+ %% Testspec in directory other than "test"
{ok, GetOptResult2} = getopt:parse(GetOptSpec,
["--spec","specs/another.spec"]),
State2 = rebar_state:command_parsed_args(State, GetOptResult2),
- Tests2 = rebar_prv_common_test:prepare_tests(State2),
- {ok, NewState2} = rebar_prv_common_test:compile(State1, Tests2),
+ Tests2 = {ok, T2} =rebar_prv_common_test:prepare_tests(State2),
+ {ok, NewState2} = rebar_prv_common_test:compile(State2, Tests2),
+ Opts2= rebar_prv_common_test:translate_paths(NewState2, T2),
+ %% check thath extra src dirs are added
[App2] = rebar_state:project_apps(NewState2),
["specs","test"] =
lists:sort(rebar_dir:extra_src_dirs(rebar_app_info:opts(App2))),
+ %% check that paths are translated
+ ExpectedSpec2 = filename:join([AppDir, "_build", "test", "lib", Name,
+ "specs", "another.spec"]),
+ [ExpectedSpec2] = proplists:get_value(spec, Opts2),
+
ok = file:set_cwd(Wd),
ok.