diff options
Diffstat (limited to 'src/rebar_ct.erl')
-rw-r--r-- | src/rebar_ct.erl | 59 |
1 files changed, 50 insertions, 9 deletions
diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index e33c6c9..9951f8e 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -26,19 +26,22 @@ %% ------------------------------------------------------------------- %% %% Targets: -%% test - runs common test suites in ./test -%% int_test - runs suites in ./int_test -%% perf_test - runs suites inm ./perf_test +%% test - run common test suites in ./test +%% int_test - run suites in ./int_test +%% perf_test - run suites inm ./perf_test %% %% Global options: %% verbose=1 - show output from the common_test run as it goes -%% suites="foo,bar" - runs <test>/foo_SUITE and <test>/bar_SUITE -%% case="mycase" - runs individual test case foo_SUITE:mycase +%% suites="foo,bar" - run <test>/foo_SUITE and <test>/bar_SUITE +%% case="mycase" - run individual test case foo_SUITE:mycase %% ------------------------------------------------------------------- -module(rebar_ct). -export([ct/2]). +%% for internal use only +-export([info/2]). + -include("rebar.hrl"). %% =================================================================== @@ -53,6 +56,26 @@ ct(Config, File) -> %% =================================================================== %% Internal functions %% =================================================================== + +info(help, ct) -> + ?CONSOLE( + "Run common_test suites.~n" + "~n" + "Valid rebar.config options:~n" + " ~p~n" + " ~p~n" + " ~p~n" + " ~p~n" + "Valid command line options:~n" + " suites=foo,bar - run <test>/foo_SUITE and <test>/bar_SUITE~n" + " case=\"mycase\" - run individual test case foo_SUITE:mycase~n", + [ + {ct_dir, "itest"}, + {ct_log_dir, "test/logs"}, + {ct_extra_params, "-boot start_sasl -s myapp"}, + {ct_use_short_names, true} + ]). + run_test_if_present(TestDir, LogDir, Config, File) -> case filelib:is_dir(TestDir) of false -> @@ -85,8 +108,16 @@ run_test(TestDir, LogDir, Config, _File) -> " 2>&1 | tee -a " ++ RawLog end, - rebar_utils:sh(Cmd ++ Output, [{env,[{"TESTDIR", TestDir}]}]), - check_log(Config, RawLog). + case rebar_utils:sh(Cmd ++ Output, [{env,[{"TESTDIR", TestDir}]}, return_on_error]) of + {ok,_} -> + %% in older versions of ct_run, this could have been a failure + %% that returned a non-0 code. Check for that! + check_success_log(Config, RawLog); + {error,Res} -> + %% In newer ct_run versions, this may be a sign of a good compile + %% that failed cases. In older version, it's a worse error. + check_fail_log(Config, RawLog, Cmd ++ Output, Res) + end. clear_log(LogDir, RawLog) -> case filelib:ensure_dir(filename:join(LogDir, "index.html")) of @@ -101,7 +132,16 @@ clear_log(LogDir, RawLog) -> %% calling ct with erl does not return non-zero on failure - have to check %% log results -check_log(Config, RawLog) -> +check_success_log(Config, RawLog) -> + check_log(Config, RawLog, fun(Msg) -> ?CONSOLE("DONE.\n~s\n", [Msg]) end). + +check_fail_log(Config, RawLog, Command, {Rc, Output}) -> + check_log(Config, RawLog, fun(_Msg) -> + ?ABORT("~s failed with error: ~w and output:~n~s~n", + [Command, Rc, Output]) + end). + +check_log(Config,RawLog,Fun) -> {ok, Msg} = rebar_utils:sh("grep -e 'TEST COMPLETE' -e '{error,make_failed}' " ++ RawLog, [{use_stdout, false}]), @@ -119,9 +159,10 @@ check_log(Config, RawLog) -> ?FAIL; true -> - ?CONSOLE("DONE.\n~s\n", [Msg]) + Fun(Msg) end. + %% Show the log if it hasn't already been shown because verbose was on show_log(Config, RawLog) -> ?CONSOLE("Showing log\n", []), |