From f9a941f2da1cd2667709323f456f4866902a2e79 Mon Sep 17 00:00:00 2001 From: omarkj Date: Fri, 19 Sep 2014 00:38:05 -0700 Subject: Enable ct. --- src/rebar_prv_common_test.erl | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index a8d7e31..958822f 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -32,23 +32,29 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()}. do(State) -> - % Run common tests. - % CommandArguments = rebar_state:command_args(State), + Opts = build_options(State), + ct:run_test(Opts), + {ok, State}. + +build_options(State) -> + Arguments = rebar_state:command_args(State), + Opts = parse_args(Arguments, []), + lists:keymerge(1, Opts, defaults(State)). + +defaults(State) -> Logdir = filename:join([rebar_state:dir(State), "logs"]), ok = ensure_logdir(Logdir), - % @todo check for test dir, figure out how Tristan does nice errors Testdir = filename:join([rebar_state:dir(State), "test"]), - case ec_file:is_dir(Testdir) of - false -> - ?INFO("Test directory ~s does not exist:\n", - [Testdir]), - ?FAIL; - _ -> ok - end, - Opts = [{dir, Testdir}, - {logdir, Logdir}], - ct:run_test(Opts), - {ok, State}. + ok = ensure_testdir(Testdir), + [{dir, Testdir}, + {logdir, Logdir}]. + +parse_args([], Opts) -> + Opts; +parse_args([Pair|Rest], Opts) -> + [Key, Val] = string:tokens(Pair, "="), + Key0 = list_to_atom(Key), + parse_args(Rest, [{Key0, string:tokens(Val, " ")}|Opts]). ensure_logdir(Logdir) -> case ec_file:is_dir(Logdir) of @@ -57,3 +63,12 @@ ensure_logdir(Logdir) -> false -> ec_file:mkdir_path(Logdir) end. + +ensure_testdir(Testdir) -> + case ec_file:is_dir(Testdir) of + false -> + ?INFO("Test directory ~s does not exist:\n", + [Testdir]), + ?FAIL; + _ -> ok + end. -- cgit v1.1