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.
This commit is contained in:
Tim Watson 2011-01-26 02:00:53 +00:00 committed by Tuncer Ayaz
parent 6056c63eed
commit 3db8f585f1
5 changed files with 86 additions and 22 deletions

View file

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

26
inttest/ct2/ct2_rt.erl Normal file
View file

@ -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]).

View file

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

10
inttest/ct2/foo_SUITE.erl Normal file
View file

@ -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]).

View file

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