浏览代码

Add -spec support to rebar_ct command line

This change adds support for executing ct test runs based on test
specificiations, which was missing previously. The rebar_ct module
now looks for any number of files with a name ending in `test.spec`
and if it finds one or more, passes these after the `-spec` argument
to ct_run instead of explicitly configuring the config, user config
and coverage config variables.

When no specifications are found, then the module behaves as it did
before this change, and both the ct1 and (new) ct2 integration tests
appear to show this is a backwards compatible patch.
pull/3/head
Tim Watson 14 年前
提交者 Tuncer Ayaz
父节点
当前提交
3db8f585f1
共有 5 个文件被更改,包括 86 次插入22 次删除
  1. +0
    -1
      include/rebar.hrl
  2. +26
    -0
      inttest/ct2/ct2_rt.erl
  3. +1
    -0
      inttest/ct2/foo.test.spec
  4. +10
    -0
      inttest/ct2/foo_SUITE.erl
  5. +49
    -21
      src/rebar_ct.erl

+ 0
- 1
include/rebar.hrl 查看文件

@ -15,4 +15,3 @@
-define(ERROR(Str, Args), rebar_log:log(error, Str, Args)).
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).

+ 26
- 0
inttest/ct2/ct2_rt.erl 查看文件

@ -0,0 +1,26 @@
-module(ct2_rt).
-compile(export_all).
files() ->
[{create, "ebin/foo.app", app(foo)},
{copy, "../../rebar", "rebar"},
{copy, "foo.test.spec", "test/foo.test.spec"},
{copy, "foo_SUITE.erl", "test/foo_SUITE.erl"}].
run(_Dir) ->
{ok, _} = retest:sh("./rebar compile ct -v"),
ok.
%%
%% Generate the contents of a simple .app file
%%
app(Name) ->
App = {application, Name,
[{description, atom_to_list(Name)},
{vsn, "1"},
{modules, []},
{registered, []},
{applications, [kernel, stdlib]}]},
io_lib:format("~p.\n", [App]).

+ 1
- 0
inttest/ct2/foo.test.spec 查看文件

@ -0,0 +1 @@
{suites, "test", all}.

+ 10
- 0
inttest/ct2/foo_SUITE.erl 查看文件

@ -0,0 +1,10 @@
-module(foo_SUITE).
-include_lib("common_test/include/ct.hrl").
-compile(export_all).
all() -> [foo].
foo(Config) ->
io:format("Test: ~p\n", [Config]).

+ 49
- 21
src/rebar_ct.erl 查看文件

@ -141,32 +141,57 @@ make_cmd(TestDir, Config) ->
CodeDirs = [io_lib:format("\"~s\"", [Dir]) ||
Dir <- [EbinDir|NonLibCodeDirs]],
CodePathString = string:join(CodeDirs, " "),
Cmd = ?FMT("erl " % should we expand ERL_PATH?
" -noshell -pa ~s ~s"
" -s ct_run script_start -s erlang halt"
" -name test@~s"
" -logdir \"~s\""
" -env TEST_DIR \"~s\"",
[CodePathString,
Include,
net_adm:localhost(),
LogDir,
filename:join(Cwd, TestDir)]) ++
get_cover_config(Config, Cwd) ++
get_ct_config_file(TestDir) ++
get_config_file(TestDir) ++
get_suite(TestDir) ++
get_case(),
Cmd = case get_ct_specs(Cwd) of
undefined ->
?FMT("erl " % should we expand ERL_PATH?
" -noshell -pa ~s ~s"
" -s ct_run script_start -s erlang halt"
" -name test@~s"
" -logdir \"~s\""
" -env TEST_DIR \"~s\"",
[CodePathString,
Include,
net_adm:localhost(),
LogDir,
filename:join(Cwd, TestDir)]) ++
get_cover_config(Config, Cwd) ++
get_ct_config_file(TestDir) ++
get_config_file(TestDir) ++
get_suite(TestDir) ++
get_case();
SpecFlags ->
?FMT("erl " % should we expand ERL_PATH?
" -noshell -pa ~s ~s"
" -s ct_run script_start -s erlang halt"
" -name test@~s"
" -logdir \"~s\""
" -env TEST_DIR \"~s\"",
[CodePathString,
Include,
net_adm:localhost(),
LogDir,
filename:join(Cwd, TestDir)]) ++
SpecFlags ++ get_cover_config(Config, Cwd)
end,
RawLog = filename:join(LogDir, "raw.log"),
{Cmd, RawLog}.
get_ct_specs(Cwd) ->
case collect_glob(Cwd, ".*\.test\.spec\$") of
[] -> undefined;
[Spec] ->
" -spec " ++ Spec;
Specs ->
" -spec " ++
lists:flatten([io_lib:format("~s ", [Spec]) || Spec <- Specs])
end.
get_cover_config(Config, Cwd) ->
case rebar_config:get_local(Config, cover_enabled, false) of
false ->
"";
true ->
case filelib:fold_files(Cwd, ".*cover\.spec\$",
true, fun collect_ct_specs/2, []) of
case collect_glob(Cwd, ".*cover\.spec\$") of
[] ->
?DEBUG("No cover spec found: ~s~n", [Cwd]),
"";
@ -178,15 +203,18 @@ get_cover_config(Config, Cwd) ->
end
end.
collect_ct_specs(F, Acc) ->
collect_glob(Cwd, Glob) ->
filelib:fold_files(Cwd, Glob, true, fun collect_files/2, []).
collect_files(F, Acc) ->
%% Ignore any specs under the deps/ directory. Do this pulling
%% the dirname off the the F and then splitting it into a list.
Parts = filename:split(filename:dirname(F)),
case lists:member("deps", Parts) of
true ->
Acc; % There is a directory named "deps" in path
Acc; % There is a directory named "deps" in path
false ->
[F | Acc] % No "deps" directory in path
[F | Acc] % No "deps" directory in path
end.
get_ct_config_file(TestDir) ->

正在加载...
取消
保存