瀏覽代碼

Add directory of testspec as extra_src_dir

This is necessary in order to automatically get the testspec included
as an artifact (i.e. copied to the _build dir) in the case when it is
stored in another directory than 'test'.
pull/1407/head
Siri Hansen 8 年之前
父節點
當前提交
a0e7ff2eb9
共有 2 個檔案被更改,包括 32 行新增12 行删除
  1. +8
    -8
      src/rebar_prv_common_test.erl
  2. +24
    -4
      test/rebar_ct_SUITE.erl

+ 8
- 8
src/rebar_prv_common_test.erl 查看文件

@ -429,9 +429,9 @@ test_dirs(State, Apps, Opts) ->
set_compile_dirs(State, Apps, join(Suites, Dir));
{_Suites, _Dirs} -> {error, "Only a single directory may be specified when specifying suites"}
end;
_Specs ->
%% Currently not adding any directories from the spec files.
{ok, rebar_state:project_apps(State, Apps)}
Specs ->
set_compile_dirs(State, Apps, {spec, Specs})
end.
join(Suite, Dir) when is_integer(hd(Suite)) ->
@ -451,15 +451,15 @@ set_compile_dirs(State, Apps, {dir, Dirs}) ->
F = fun(Dir, {S, A}) -> maybe_inject_test_dir(S, [], A, Dir) end,
{NewState, NewApps} = lists:foldl(F, {State, Apps}, Dirs),
{ok, rebar_state:project_apps(NewState, NewApps)};
set_compile_dirs(State, Apps, {suite, Suites}) ->
%% suites with dir component
Dirs = find_suite_dirs(Suites),
set_compile_dirs(State, Apps, {Type, Files}) when Type==spec; Type==suite ->
%% specs or suites with dir component
Dirs = find_file_dirs(Files),
F = fun(Dir, {S, A}) -> maybe_inject_test_dir(S, [], A, Dir) end,
{NewState, NewApps} = lists:foldl(F, {State, Apps}, Dirs),
{ok, rebar_state:project_apps(NewState, NewApps)}.
find_suite_dirs(Suites) ->
AllDirs = lists:map(fun(S) -> filename:dirname(filename:absname(S)) end, Suites),
find_file_dirs(Files) ->
AllDirs = lists:map(fun(F) -> filename:dirname(filename:absname(F)) end, Files),
%% eliminate duplicates
lists:usort(AllDirs).

+ 24
- 4
test/rebar_ct_SUITE.erl 查看文件

@ -1246,9 +1246,15 @@ testspec(Config) ->
Name = rebar_test_utils:create_random_name("ct_testspec_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
Spec = filename:join([AppDir, "test", "some.spec"]),
ok = filelib:ensure_dir(Spec),
ok = file:write_file(Spec, "[].\n"),
Spec1 = filename:join([AppDir, "test", "some.spec"]),
ok = filelib:ensure_dir(Spec1),
ok = file:write_file(Spec1, "[].\n"),
Spec2 = filename:join([AppDir, "specs", "another.spec"]),
ok = filelib:ensure_dir(Spec2),
ok = file:write_file(Spec2, "[].\n"),
{ok,Wd} = file:get_cwd(),
ok = file:set_cwd(AppDir),
{ok, State} = rebar_test_utils:run_and_check(C,
[],
@ -1263,7 +1269,21 @@ testspec(Config) ->
{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, _} = rebar_prv_common_test:compile(State1, Tests1),
{ok, NewState1} = rebar_prv_common_test:compile(State1, Tests1),
[App1] = rebar_state:project_apps(NewState1),
["test"] = rebar_dir:extra_src_dirs(rebar_app_info:opts(App1)),
{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),
[App2] = rebar_state:project_apps(NewState2),
["specs","test"] =
lists:sort(rebar_dir:extra_src_dirs(rebar_app_info:opts(App2))),
ok = file:set_cwd(Wd),
ok.

Loading…
取消
儲存