mirror of
https://github.com/valitydev/riak_test.git
synced 2024-11-06 08:35:22 +00:00
Added file output
This commit is contained in:
parent
ef62d699c1
commit
dee961d8f6
3
.gitignore
vendored
3
.gitignore
vendored
@ -3,4 +3,5 @@ ebin
|
||||
log
|
||||
riak_test
|
||||
.eunit
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
out
|
||||
|
@ -14,13 +14,16 @@ cli_options() ->
|
||||
{config, $c, "conf", string, "specifies the project configuration"},
|
||||
{tests, $t, "tests", string, "specifies which tests to run"},
|
||||
{suites, $s, "suites", string, "which suites to run"},
|
||||
{dir, $d, "dir", string, "run all tests in the specified directory"}
|
||||
{dir, $d, "dir", string, "run all tests in the specified directory"},
|
||||
{verbose, $v, "verbose", undefined, "verbose output"},
|
||||
{outdir, $o, "outdir", string, "output directory"}
|
||||
].
|
||||
|
||||
|
||||
main(Args) ->
|
||||
{ok, {ParsedArgs, HarnessArgs}} = getopt:parse(cli_options(), Args),
|
||||
|
||||
Verbose = proplists:is_defined(verbose, ParsedArgs),
|
||||
Config = proplists:get_value(config, ParsedArgs),
|
||||
SpecificTests = proplists:get_all_values(tests, ParsedArgs),
|
||||
Suites = proplists:get_all_values(suites, ParsedArgs),
|
||||
@ -55,33 +58,52 @@ main(Args) ->
|
||||
|
||||
%% Start Lager
|
||||
application:load(lager),
|
||||
LagerLevel = rt:config(rt_lager_level, debug),
|
||||
application:set_env(lager, handlers, [{lager_console_backend, LagerLevel}]),
|
||||
%% Fileoutput
|
||||
Outdir = proplists:get_value(outdir, ParsedArgs),
|
||||
ConsoleLagerLevel = case Outdir of
|
||||
undefined -> rt:config(rt_lager_level, debug);
|
||||
_ ->
|
||||
filelib:ensure_dir(Outdir),
|
||||
notice
|
||||
end,
|
||||
|
||||
application:set_env(lager, handlers, [{lager_console_backend, ConsoleLagerLevel}]),
|
||||
lager:start(),
|
||||
|
||||
%% rt:set_config(rtdev_path, Path),
|
||||
%% rt:set_config(rt_max_wait_time, 180000),
|
||||
%% rt:set_config(rt_retry_delay, 500),
|
||||
%% rt:set_config(rt_harness, rtbe),
|
||||
TestResults = [ run_test(Test, HarnessArgs) || Test <- Tests],
|
||||
|
||||
TestResults = [ run_test(Test, Outdir, HarnessArgs) || Test <- Tests],
|
||||
|
||||
print_summary(TestResults),
|
||||
print_summary(TestResults, Verbose),
|
||||
ok.
|
||||
|
||||
run_test(Test, HarnessArgs) ->
|
||||
run_test(Test, Outdir, HarnessArgs) ->
|
||||
rt:setup_harness(Test, HarnessArgs),
|
||||
TestA = list_to_atom(Test),
|
||||
SingleTestResult = riak_test_runner:confirm(TestA),
|
||||
SingleTestResult = riak_test_runner:confirm(TestA, Outdir),
|
||||
rt:cleanup_harness(),
|
||||
SingleTestResult.
|
||||
|
||||
print_summary(TestResults) ->
|
||||
print_summary(TestResults, Verbose) ->
|
||||
io:format("~nTest Results:~n"),
|
||||
|
||||
Results = [ [ atom_to_list(proplists:get_value(test, SingleTestResult)),
|
||||
proplists:get_value(status, SingleTestResult)] || SingleTestResult <- TestResults],
|
||||
Results = [
|
||||
[ atom_to_list(proplists:get_value(test, SingleTestResult)),
|
||||
proplists:get_value(status, SingleTestResult),
|
||||
proplists:get_value(reason, SingleTestResult)]
|
||||
|| SingleTestResult <- TestResults],
|
||||
Width = test_name_width(Results),
|
||||
[ io:format("~s: ~s~n", [string:left(Name, Width), Result]) || [Name, Result] <- Results],
|
||||
|
||||
Print = fun(Test, Status, Reason) ->
|
||||
case {Status, Verbose} of
|
||||
{fail, true} -> io:format("~s: ~s ~p~n", [string:left(Test, Width), Status, Reason]);
|
||||
_ -> io:format("~s: ~s~n", [string:left(Test, Width), Status])
|
||||
end
|
||||
end,
|
||||
[ Print(Test, Status, Reason) || [Test, Status, Reason] <- Results],
|
||||
|
||||
PassCount = length(lists:filter(fun(X) -> proplists:get_value(status, X) =:= pass end, TestResults)),
|
||||
FailCount = length(lists:filter(fun(X) -> proplists:get_value(status, X) =:= fail end, TestResults)),
|
||||
|
@ -1,44 +1,52 @@
|
||||
-module(riak_test_runner).
|
||||
%% @doc riak_test_runner runs a riak_test module's run/0 function.
|
||||
-export([confirm/1]).
|
||||
-export([confirm/2]).
|
||||
|
||||
-spec(confirm(atom()) -> [tuple()]).
|
||||
-spec(confirm(atom(), string()) -> [tuple()]).
|
||||
%% @doc Runs a module's run/0 function after setting up a log capturing backend for lager.
|
||||
%% It then cleans up that backend and returns the logs as part of the return proplist.
|
||||
confirm(TestModule) ->
|
||||
start_lager_backend(),
|
||||
confirm(TestModule, Outdir) ->
|
||||
start_lager_backend(TestModule, Outdir),
|
||||
|
||||
%% Check for api compatibility
|
||||
Result = case proplists:get_value(confirm,
|
||||
{Status, Reason} = case proplists:get_value(confirm,
|
||||
proplists:get_value(exports, TestModule:module_info()),
|
||||
-1) of
|
||||
0 ->
|
||||
lager:info("Running Test ~s", [TestModule]),
|
||||
lager:notice("Running Test ~s", [TestModule]),
|
||||
execute(TestModule);
|
||||
_ ->
|
||||
lager:info("~s is not a runable test", [TestModule]),
|
||||
not_a_runable_test
|
||||
{not_a_runable_test, undefined}
|
||||
end,
|
||||
|
||||
lager:info("~s Test Run Complete", [TestModule]),
|
||||
lager:notice("~s Test Run Complete", [TestModule]),
|
||||
{ok, Log} = stop_lager_backend(),
|
||||
|
||||
[{test, TestModule}, {status, Result}, {log, Log}].
|
||||
RetList = [{test, TestModule}, {status, Status}, {log, Log}],
|
||||
case Status of
|
||||
fail -> RetList ++ [{reason, Reason}];
|
||||
_ -> RetList
|
||||
end.
|
||||
|
||||
|
||||
start_lager_backend() ->
|
||||
LagerLevel = rt:config(rt_lager_level, debug),
|
||||
gen_event:add_handler(lager_event, riak_test_lager_backend, [LagerLevel, false]).
|
||||
start_lager_backend(TestModule, Outdir) ->
|
||||
case Outdir of
|
||||
undefined -> ok;
|
||||
_ -> gen_event:add_handler(lager_event, lager_file_backend, {Outdir ++ "/" ++ atom_to_list(TestModule) ++ ".dat_test_output", debug, 10485760, "$D0", 1})
|
||||
end,
|
||||
gen_event:add_handler(lager_event, riak_test_lager_backend, [debug, false]).
|
||||
|
||||
stop_lager_backend() ->
|
||||
gen_event:delete_handler(lager_event, lager_file_backend, []),
|
||||
gen_event:delete_handler(lager_event, riak_test_lager_backend, []).
|
||||
|
||||
execute(TestModule) ->
|
||||
try TestModule:confirm() of
|
||||
ReturnVal -> ReturnVal
|
||||
ReturnVal -> {ReturnVal, undefined}
|
||||
catch
|
||||
error:Error ->
|
||||
lager:warning("~s failed: ~p", [TestModule, Error]),
|
||||
fail
|
||||
{fail, Error}
|
||||
end.
|
||||
|
@ -29,9 +29,6 @@ run_git(Path, Cmd) ->
|
||||
os:cmd(gitcmd(Path, Cmd)).
|
||||
|
||||
run_riak(N, Path, Cmd) ->
|
||||
%% io:format("~p~n", [riakcmd(Path, N, Cmd)]),
|
||||
%%?debugFmt("RR: ~p~n", [[N,Path,Cmd]]),
|
||||
%%?debugFmt("~p~n", [os:cmd(riakcmd(Path, N, Cmd))]).
|
||||
lager:info("Running: ~s", [riakcmd(Path, N, Cmd)]),
|
||||
os:cmd(riakcmd(Path, N, Cmd)).
|
||||
|
||||
@ -201,7 +198,7 @@ admin(Node, Args) ->
|
||||
Cmd = riak_admin_cmd(Path, N, Args),
|
||||
lager:debug("Running: ~s", [Cmd]),
|
||||
Result = os:cmd(Cmd),
|
||||
io:format("~s", [Result]),
|
||||
lager:debug("~s", [Result]),
|
||||
ok.
|
||||
|
||||
node_id(Node) ->
|
||||
|
Loading…
Reference in New Issue
Block a user