diff options
author | Alexey Romanov <alexey.v.romanov@gmail.com> | 2011-02-21 12:41:20 +0300 |
---|---|---|
committer | Alexey Romanov <alexey.v.romanov@gmail.com> | 2011-02-21 12:41:20 +0300 |
commit | 7dc371d8a3b9a6e2ab9f814c0d2536cf638ceb99 (patch) | |
tree | 174193ae08d2824164ba99e63f696a6593ee63c6 /src/rebar_ct.erl | |
parent | 2ceeb3272139b7569c8dabc215ca1e7063b0d385 (diff) | |
parent | 6056c63eed288736c912c82d6f36aa7dd055f9ca (diff) |
Merge branch 'master' of https://github.com/basho/rebar
Diffstat (limited to 'src/rebar_ct.erl')
-rw-r--r-- | src/rebar_ct.erl | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/src/rebar_ct.erl b/src/rebar_ct.erl index 316998f..8f7c71a 100644 --- a/src/rebar_ct.erl +++ b/src/rebar_ct.erl @@ -1,4 +1,4 @@ -%% -*- tab-width: 4;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ts=4 sw=4 et %% ------------------------------------------------------------------- %% @@ -71,51 +71,53 @@ run_test(TestDir, Config, _File) -> Output = " 2>&1 | tee -a " ++ RawLog end, - rebar_utils:sh(Cmd ++ Output, [{"TESTDIR", TestDir}]), + rebar_utils:sh(Cmd ++ Output, [{env,[{"TESTDIR", TestDir}]}]), check_log(RawLog). clear_log(RawLog) -> case filelib:ensure_dir("logs/index.html") of - ok -> - NowStr = rebar_utils:now_str(), - LogHeader = "--- Test run on " ++ NowStr ++ " ---\n", - ok = file:write_file(RawLog, LogHeader); - {error, Reason} -> - ?ERROR("Could not create log dir - ~p\n", [Reason]), - ?FAIL + ok -> + NowStr = rebar_utils:now_str(), + LogHeader = "--- Test run on " ++ NowStr ++ " ---\n", + ok = file:write_file(RawLog, LogHeader); + {error, Reason} -> + ?ERROR("Could not create log dir - ~p\n", [Reason]), + ?FAIL end. %% calling ct with erl does not return non-zero on failure - have to check %% log results check_log(RawLog) -> - Msg = os:cmd("grep -e 'TEST COMPLETE' -e '{error,make_failed}' " ++ RawLog), + {ok, Msg} = + rebar_utils:sh("grep -e 'TEST COMPLETE' -e '{error,make_failed}' " + ++ RawLog, [{use_stdout, false}]), MakeFailed = string:str(Msg, "{error,make_failed}") =/= 0, RunFailed = string:str(Msg, ", 0 failed") =:= 0, if MakeFailed -> - show_log(RawLog), - ?ERROR("Building tests failed\n",[]), - ?FAIL; + show_log(RawLog), + ?ERROR("Building tests failed\n",[]), + ?FAIL; RunFailed -> - show_log(RawLog), - ?ERROR("One or more tests failed\n",[]), - ?FAIL; + show_log(RawLog), + ?ERROR("One or more tests failed\n",[]), + ?FAIL; - true -> - ?CONSOLE("DONE. ~s\n", [Msg]) + true -> + ?CONSOLE("DONE. ~s\n", [Msg]) end. %% Show the log if it hasn't already been shown because verbose was on show_log(RawLog) -> ?CONSOLE("Showing log\n", []), case rebar_config:get_global(verbose, "0") of - "0" -> - {ok, Contents} = file:read_file(RawLog), - ?CONSOLE("~s", [Contents]); - _ -> - ok + "0" -> + {ok, Contents} = file:read_file(RawLog), + ?CONSOLE("~s", [Contents]); + _ -> + ok end. make_cmd(TestDir, Config) -> @@ -135,7 +137,7 @@ make_cmd(TestDir, Config) -> %% that are part of the root Erlang install are filtered out to %% avoid duplication R = code:root_dir(), - NonLibCodeDirs = [P || P <- code:get_path(), lists:prefix(R, P) == false], + NonLibCodeDirs = [P || P <- code:get_path(), not lists:prefix(R, P)], CodeDirs = [io_lib:format("\"~s\"", [Dir]) || Dir <- [EbinDir|NonLibCodeDirs]], CodePathString = string:join(CodeDirs, " "), @@ -163,21 +165,22 @@ get_cover_config(Config, Cwd) -> false -> ""; true -> - case filelib:fold_files(Cwd, ".*cover\.spec\$", true, fun collect_ct_specs/2, []) of - [] -> - ?DEBUG("No cover spec found: ~s~n", [Cwd]), - ""; - [Spec] -> - ?DEBUG("Found cover file ~w~n", [Spec]), - " -cover " ++ Spec; - Specs -> - ?ABORT("Multiple cover specs found: ~p~n", [Specs]) - end - end. + case filelib:fold_files(Cwd, ".*cover\.spec\$", + true, fun collect_ct_specs/2, []) of + [] -> + ?DEBUG("No cover spec found: ~s~n", [Cwd]), + ""; + [Spec] -> + ?DEBUG("Found cover file ~w~n", [Spec]), + " -cover " ++ Spec; + Specs -> + ?ABORT("Multiple cover specs found: ~p~n", [Specs]) + end + end. collect_ct_specs(F, Acc) -> - %% Ignore any specs under the deps/ directory. Do this pulling the dirname off the - %% the F and then splitting it into a list. + %% Ignore any specs under the deps/ directory. Do this pulling + %% the dirname off the the F and then splitting it into a list. Parts = filename:split(filename:dirname(F)), case lists:member("deps", Parts) of true -> |