From a9d06554e98a571889d79fd487498579c4916dcb Mon Sep 17 00:00:00 2001 From: omarkj Date: Thu, 18 Sep 2014 23:00:20 -0700 Subject: Add common_test provider. --- src/rebar.app.src | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rebar.app.src b/src/rebar.app.src index 2e21351..3164b73 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -36,6 +36,7 @@ rebar_prv_update, rebar_prv_release, rebar_prv_version, + rebar_prv_common_test, rebar_prv_help]} ]} ]}. -- cgit v1.1 From f3b5adfb717b90eaa2d1ba634b79c323a0e09c8a Mon Sep 17 00:00:00 2001 From: omarkj Date: Thu, 18 Sep 2014 23:00:35 -0700 Subject: CT Provider. --- src/rebar_prv_common_test.erl | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/rebar_prv_common_test.erl diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl new file mode 100644 index 0000000..a8d7e31 --- /dev/null +++ b/src/rebar_prv_common_test.erl @@ -0,0 +1,59 @@ +%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ts=4 sw=4 et + +-module(rebar_prv_common_test). + +-behaviour(rebar_provider). + +-export([init/1, + do/1]). + +-include("rebar.hrl"). + +-define(PROVIDER, ct). +-define(DEPS, [compile]). + +%% =================================================================== +%% Public API +%% =================================================================== + +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + State1 = rebar_state:add_provider(State, + #provider{name = ?PROVIDER, + provider_impl = ?MODULE, + bare = false, + deps = ?DEPS, + example = "rebar ct", + short_desc = "Run common tests", + desc = "", + opts = []}), + {ok, State1}. + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()}. +do(State) -> + % Run common tests. + % CommandArguments = rebar_state:command_args(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}. + +ensure_logdir(Logdir) -> + case ec_file:is_dir(Logdir) of + true -> + ok; + false -> + ec_file:mkdir_path(Logdir) + end. -- cgit v1.1 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(-) 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 From 58f4019fa62a73e335967870f6605182d7386830 Mon Sep 17 00:00:00 2001 From: omarkj Date: Thu, 25 Sep 2014 11:27:17 -0700 Subject: common tests -> Common Tests --- src/rebar_prv_common_test.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 958822f..b880d77 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -25,7 +25,7 @@ init(State) -> bare = false, deps = ?DEPS, example = "rebar ct", - short_desc = "Run common tests", + short_desc = "Run Common Tests", desc = "", opts = []}), {ok, State1}. -- cgit v1.1