瀏覽代碼

Merge pull request #2299 from tolbrino/tb-fix-empty-ct-invocation

Fix use of `ct` on projects without CT suites and configuration
pull/2313/head
Fred Hebert 5 年之前
committed by GitHub
父節點
當前提交
a913070f93
沒有發現已知的金鑰在資料庫的簽署中 GPG Key ID: 4AEE18F83AFDEB23
共有 2 個文件被更改,包括 51 次插入15 次删除
  1. +31
    -14
      src/rebar_prv_common_test.erl
  2. +20
    -1
      test/rebar_ct_SUITE.erl

+ 31
- 14
src/rebar_prv_common_test.erl 查看文件

@ -127,17 +127,23 @@ symlink_to_last_ct_logs(State) ->
LogDir = filename:join([rebar_dir:base_dir(State), "logs"]),
{ok, Filenames} = file:list_dir(LogDir),
CtRunDirs = lists:filter(fun(S) -> re:run(S, "ct_run", [unicode]) /= nomatch end, Filenames),
NewestDir = lists:last(lists:sort(CtRunDirs)),
Target = filename:join([LogDir, "last"]),
Existing = filename:join([LogDir, NewestDir]),
case rebar_file_utils:symlink_or_copy(Existing, Target) of
ok -> ok;
exists ->
%% in case the symlink already exists we remove it
%% and make a new updated one
rebar_file_utils:rm_rf(Target),
rebar_file_utils:symlink_or_copy(Existing, Target);
Reason -> ?DEBUG("Warning, couldn't make a symlink to ~ts, reason: ~p.", [Target, Reason])
case CtRunDirs of
[] ->
% If for some reason there are no such directories, we should not try to set up a link either.
ok;
_ ->
NewestDir = lists:last(lists:sort(CtRunDirs)),
Target = filename:join([LogDir, "last"]),
Existing = filename:join([LogDir, NewestDir]),
case rebar_file_utils:symlink_or_copy(Existing, Target) of
ok -> ok;
exists ->
%% in case the symlink already exists we remove it
%% and make a new updated one
rebar_file_utils:rm_rf(Target),
rebar_file_utils:symlink_or_copy(Existing, Target);
Reason -> ?DEBUG("Warning, couldn't make a symlink to ~ts, reason: ~p.", [Target, Reason])
end
end.
setup_name(State) ->
@ -335,7 +341,7 @@ sys_config_list(CmdOpts, CfgOpts) ->
discover_tests(State, ProjectApps, Opts) ->
case is_any_defined([spec,dir,suite],Opts) of
%% no tests defined, try using `$APP/test` and `$ROOT/test` as dirs
false -> {ok, [default_tests(State, ProjectApps)|Opts]};
false -> {ok, default_tests(State, ProjectApps) ++ Opts};
true -> {ok, Opts}
end.
@ -346,9 +352,18 @@ default_tests(State, ProjectApps) ->
case filelib:is_dir(BareTest) andalso not lists:any(F, ProjectApps) of
%% `test` dir at root of project is already scheduled to be
%% included or `test` does not exist
false -> {dir, AppTests};
false ->
%% The rest of the call-chain expects the list of tests to not be
%% empty, thus we drop the parameter in that case entirely.
case AppTests of
[] ->
[];
_ ->
[{dir, AppTests}]
end;
%% need to add `test` dir at root to dirs to be included
true -> {dir, AppTests ++ [BareTest]}
true ->
[{dir, AppTests ++ [BareTest]}]
end.
application_dirs([], []) -> [];
@ -484,6 +499,8 @@ test_dirs(State, Apps, Opts) ->
case proplists:get_value(spec, Opts) of
undefined ->
case {proplists:get_value(suite, Opts), proplists:get_value(dir, Opts)} of
{undefined, undefined} ->
{ok, rebar_state:project_apps(State, Apps)};
{Suites, undefined} -> set_compile_dirs(State, Apps, {suite, Suites});
{undefined, Dirs} -> set_compile_dirs(State, Apps, {dir, Dirs});
{Suites, Dir} when is_integer(hd(Dir)) ->

+ 20
- 1
test/rebar_ct_SUITE.erl 查看文件

@ -10,6 +10,7 @@
multi_app_default_dirs/1,
multi_app_default_beams/1,
multi_app_ct_macro/1,
no_ct_suite/1,
single_app_dir/1,
single_extra_dir/1,
single_unmanaged_dir/1,
@ -80,7 +81,8 @@ all() -> [{group, basic_app},
testspec_parse_error,
cmd_vs_cfg_opts,
single_testspec_in_ct_opts,
compile_only].
compile_only,
no_ct_suite].
groups() -> [{basic_app, [], [basic_app_default_dirs,
basic_app_default_beams,
@ -339,6 +341,23 @@ multi_app_ct_macro(Config) ->
true = lists:member({d, 'COMMON_TEST'}, ErlOpts)
end, Apps).
no_ct_suite(Config0) ->
Config = rebar_test_utils:init_rebar_state(Config0),
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("no_ct_suite_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
{ok, State} = rebar_test_utils:run_and_check(Config, [], ["as", "test", "lock"], return),
{ok, Opts} = rebar_prv_common_test:prepare_tests(State),
undefined = proplists:get_value(dir, Opts),
undefined = proplists:get_value(suite, Opts),
undefined = proplists:get_value(spec, Opts),
ok.
single_app_dir(Config) ->
AppDir = ?config(apps, Config),
[Name1, _Name2] = ?config(appnames, Config),

Loading…
取消
儲存