mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Initial cleanup pass on rebar_ct; removing other targets in favor of "ct" (ala how eunit support works)
This commit is contained in:
parent
c2b58ac62f
commit
8d14f3193d
1 changed files with 50 additions and 59 deletions
109
src/rebar_ct.erl
109
src/rebar_ct.erl
|
@ -37,11 +37,7 @@
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
-module(rebar_ct).
|
-module(rebar_ct).
|
||||||
|
|
||||||
-export([test/2,
|
-export([ct/2]).
|
||||||
int_test/2,
|
|
||||||
perf_test/2]).
|
|
||||||
|
|
||||||
-compile([export_all]).
|
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
|
@ -49,14 +45,9 @@
|
||||||
%% Public API
|
%% Public API
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
test(Config, File) ->
|
ct(Config, File) ->
|
||||||
run_test_if_present("test", Config, File).
|
run_test_if_present("test", Config, File).
|
||||||
|
|
||||||
int_test(Config, File) ->
|
|
||||||
run_test_if_present("int_test", Config, File).
|
|
||||||
|
|
||||||
perf_test(Config, File) ->
|
|
||||||
run_test_if_present("perf_test", Config, File).
|
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
@ -64,29 +55,29 @@ perf_test(Config, File) ->
|
||||||
run_test_if_present(TestDir, Config, File) ->
|
run_test_if_present(TestDir, Config, File) ->
|
||||||
case filelib:is_dir(TestDir) of
|
case filelib:is_dir(TestDir) of
|
||||||
false ->
|
false ->
|
||||||
?WARN("~s directory not present - skipping\n", [TestDir]),
|
?WARN("~s directory not present - skipping\n", [TestDir]),
|
||||||
ok;
|
ok;
|
||||||
true ->
|
true ->
|
||||||
run_test(TestDir, Config, File)
|
run_test(TestDir, Config, File)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
run_test(TestDir, Config, _File) ->
|
run_test(TestDir, Config, _File) ->
|
||||||
{Cmd, RawLog} = make_cmd(TestDir, Config),
|
{Cmd, RawLog} = make_cmd(TestDir, Config),
|
||||||
clear_log(RawLog),
|
clear_log(RawLog),
|
||||||
case rebar_config:get_global(verbose, "0") of
|
case rebar_config:get_global(verbose, "0") of
|
||||||
"0" ->
|
"0" ->
|
||||||
Output = " >> " ++ RawLog ++ " 2>&1";
|
Output = " >> " ++ RawLog ++ " 2>&1";
|
||||||
_ ->
|
_ ->
|
||||||
Output = " 2>&1 | tee -a " ++ RawLog
|
Output = " 2>&1 | tee -a " ++ RawLog
|
||||||
end,
|
end,
|
||||||
|
|
||||||
case rebar_utils:sh(Cmd ++ Output, [{"TESTDIR", TestDir}]) of
|
case rebar_utils:sh(Cmd ++ Output, [{"TESTDIR", TestDir}]) of
|
||||||
ok ->
|
ok ->
|
||||||
check_log(RawLog);
|
check_log(RawLog);
|
||||||
{error, _Rc} ->
|
{error, _Rc} ->
|
||||||
show_log(RawLog),
|
show_log(RawLog),
|
||||||
?ERROR("Executing tests failed.\n", []),
|
?ERROR("Executing tests failed.\n", []),
|
||||||
?FAIL
|
?FAIL
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,32 +125,32 @@ show_log(RawLog) ->
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_cmd(TestDir, _Config) ->
|
make_cmd(TestDir, _Config) ->
|
||||||
{ok, Cwd} = file:get_cwd(),
|
Cwd = rebar_utils:get_cwd(),
|
||||||
LogDir = filename:join(Cwd, "logs"),
|
LogDir = filename:join(Cwd, "logs"),
|
||||||
Ebin = filename:join(Cwd, "ebin"),
|
EbinDir = filename:absname(filename:join(Cwd, "ebin")),
|
||||||
IncludeDir = filename:join(Cwd, "include"),
|
IncludeDir = filename:join(Cwd, "include"),
|
||||||
case filelib:is_dir(IncludeDir) of
|
case filelib:is_dir(IncludeDir) of
|
||||||
true ->
|
true ->
|
||||||
Include = " -I \"" ++ IncludeDir ++ "\"";
|
Include = " -I \"" ++ IncludeDir ++ "\"";
|
||||||
false ->
|
false ->
|
||||||
Include = ""
|
Include = ""
|
||||||
end,
|
end,
|
||||||
|
|
||||||
Cmd = lists:flatten(io_lib:format("erl " % should we expand ERL_PATH?
|
Cmd = ?FMT("erl " % should we expand ERL_PATH?
|
||||||
" -noshell -pa \"~s\" ~s"
|
" -noshell -pa \"~s\" ~s"
|
||||||
" -s ct_run script_start -s erlang halt"
|
" -s ct_run script_start -s erlang halt"
|
||||||
" -name test@~s"
|
" -name test@~s"
|
||||||
" -logdir \"~s\""
|
" -logdir \"~s\""
|
||||||
" -env TEST_DIR \"~s\"",
|
" -env TEST_DIR \"~s\"",
|
||||||
[Ebin,
|
[EbinDir,
|
||||||
Include,
|
Include,
|
||||||
net_adm:localhost(),
|
net_adm:localhost(),
|
||||||
LogDir,
|
LogDir,
|
||||||
filename:join(Cwd, TestDir)])) ++
|
filename:join(Cwd, TestDir)]) ++
|
||||||
get_ct_config_file(TestDir) ++
|
get_ct_config_file(TestDir) ++
|
||||||
get_config_file(TestDir) ++
|
get_config_file(TestDir) ++
|
||||||
get_suite(TestDir) ++
|
get_suite(TestDir) ++
|
||||||
get_case(),
|
get_case(),
|
||||||
RawLog = filename:join(LogDir, "raw.log"),
|
RawLog = filename:join(LogDir, "raw.log"),
|
||||||
{Cmd, RawLog}.
|
{Cmd, RawLog}.
|
||||||
|
|
||||||
|
@ -184,23 +175,23 @@ get_config_file(TestDir) ->
|
||||||
|
|
||||||
get_suite(TestDir) ->
|
get_suite(TestDir) ->
|
||||||
case rebar_config:get_global(suite, undefined) of
|
case rebar_config:get_global(suite, undefined) of
|
||||||
undefined ->
|
undefined ->
|
||||||
" -dir " ++ TestDir;
|
" -dir " ++ TestDir;
|
||||||
Suite ->
|
Suite ->
|
||||||
Filename = filename:join(TestDir, Suite ++ "_SUITE.erl"),
|
Filename = filename:join(TestDir, Suite ++ "_SUITE.erl"),
|
||||||
case filelib:is_regular(Filename) of
|
case filelib:is_regular(Filename) of
|
||||||
false ->
|
false ->
|
||||||
?ERROR("Suite ~s not found\n", [Suite]),
|
?ERROR("Suite ~s not found\n", [Suite]),
|
||||||
?FAIL;
|
?FAIL;
|
||||||
true ->
|
true ->
|
||||||
" -suite " ++ Filename
|
" -suite " ++ Filename
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_case() ->
|
get_case() ->
|
||||||
case rebar_config:get_global('case', undefined) of
|
case rebar_config:get_global('case', undefined) of
|
||||||
undefined ->
|
undefined ->
|
||||||
"";
|
"";
|
||||||
Case ->
|
Case ->
|
||||||
" -case " ++ Case
|
" -case " ++ Case
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in a new issue