mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Add ct_log_dir option, skip test dir with no SUITE
When rebar ct executes with its default common test directory of "test", it will generate a hardcoded "logs" directory in every application with a test directory present, causing an overlap with eunit's test framework so even test directories with only eunit tests will be processed by ct.
This commit is contained in:
parent
888bbc8ee2
commit
f1d35f9d06
2 changed files with 21 additions and 10 deletions
|
@ -86,6 +86,9 @@
|
||||||
%% Override the default "test" directory in which SUITEs are located
|
%% Override the default "test" directory in which SUITEs are located
|
||||||
{ct_dir, "itest"}.
|
{ct_dir, "itest"}.
|
||||||
|
|
||||||
|
%% Override the default "logs" directory in which SUITEs are logged
|
||||||
|
{ct_log_dir, "test/logs"}.
|
||||||
|
|
||||||
%% Option to pass extra parameters when launching Common Test
|
%% Option to pass extra parameters when launching Common Test
|
||||||
{ct_extra_params, "-boot start_sasl -s myapp"}.
|
{ct_extra_params, "-boot start_sasl -s myapp"}.
|
||||||
|
|
||||||
|
|
|
@ -47,23 +47,31 @@
|
||||||
|
|
||||||
ct(Config, File) ->
|
ct(Config, File) ->
|
||||||
TestDir = rebar_config:get_local(Config, ct_dir, "test"),
|
TestDir = rebar_config:get_local(Config, ct_dir, "test"),
|
||||||
run_test_if_present(TestDir, Config, File).
|
LogDir = rebar_config:get_local(Config, ct_log_dir, "logs"),
|
||||||
|
run_test_if_present(TestDir, LogDir, Config, File).
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
run_test_if_present(TestDir, Config, File) ->
|
run_test_if_present(TestDir, LogDir, 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)
|
case filelib:wildcard(TestDir ++ "/*_SUITE.erl") of
|
||||||
|
[] ->
|
||||||
|
?WARN("~s directory present, but no common_test"
|
||||||
|
++ " SUITES - skipping\n", [TestDir]),
|
||||||
|
ok;
|
||||||
|
_ ->
|
||||||
|
run_test(TestDir, LogDir, Config, File)
|
||||||
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
run_test(TestDir, Config, _File) ->
|
run_test(TestDir, LogDir, Config, _File) ->
|
||||||
{Cmd, RawLog} = make_cmd(TestDir, Config),
|
{Cmd, RawLog} = make_cmd(TestDir, LogDir, Config),
|
||||||
clear_log(RawLog),
|
clear_log(LogDir, RawLog),
|
||||||
case rebar_config:is_verbose(Config) of
|
case rebar_config:is_verbose(Config) of
|
||||||
false ->
|
false ->
|
||||||
Output = " >> " ++ RawLog ++ " 2>&1";
|
Output = " >> " ++ RawLog ++ " 2>&1";
|
||||||
|
@ -75,8 +83,8 @@ run_test(TestDir, Config, _File) ->
|
||||||
check_log(Config, RawLog).
|
check_log(Config, RawLog).
|
||||||
|
|
||||||
|
|
||||||
clear_log(RawLog) ->
|
clear_log(LogDir, RawLog) ->
|
||||||
case filelib:ensure_dir("logs/index.html") of
|
case filelib:ensure_dir(filename:join(LogDir, "index.html")) of
|
||||||
ok ->
|
ok ->
|
||||||
NowStr = rebar_utils:now_str(),
|
NowStr = rebar_utils:now_str(),
|
||||||
LogHeader = "--- Test run on " ++ NowStr ++ " ---\n",
|
LogHeader = "--- Test run on " ++ NowStr ++ " ---\n",
|
||||||
|
@ -120,9 +128,9 @@ show_log(Config, RawLog) ->
|
||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
make_cmd(TestDir, Config) ->
|
make_cmd(TestDir, RawLogDir, Config) ->
|
||||||
Cwd = rebar_utils:get_cwd(),
|
Cwd = rebar_utils:get_cwd(),
|
||||||
LogDir = filename:join(Cwd, "logs"),
|
LogDir = filename:join(Cwd, RawLogDir),
|
||||||
EbinDir = filename:absname(filename:join(Cwd, "ebin")),
|
EbinDir = filename:absname(filename:join(Cwd, "ebin")),
|
||||||
IncludeDir = filename:join(Cwd, "include"),
|
IncludeDir = filename:join(Cwd, "include"),
|
||||||
Include = case filelib:is_dir(IncludeDir) of
|
Include = case filelib:is_dir(IncludeDir) of
|
||||||
|
|
Loading…
Reference in a new issue