diff --git a/src/riak_test_escript.erl b/src/riak_test_escript.erl index 9e92ff81c..f48ab8acf 100644 --- a/src/riak_test_escript.erl +++ b/src/riak_test_escript.erl @@ -25,17 +25,26 @@ -export([add_deps/1]). main(Args) -> - {ParsedArgs, HarnessArgs, Tests} = prepare(Args), - OutDir = proplists:get_value(outdir, ParsedArgs), - Results = execute(Tests, OutDir, report(ParsedArgs), HarnessArgs), - finalize(Results, ParsedArgs). + case prepare(Args) of + ok -> + ok; + {ParsedArgs, HarnessArgs, Tests} -> + OutDir = proplists:get_value(outdir, ParsedArgs), + Results = execute(Tests, OutDir, report(ParsedArgs), HarnessArgs), + finalize(Results, ParsedArgs) + end. prepare(Args) -> - {ParsedArgs, _, Tests} = ParseResults = parse_args(Args), - io:format("Tests to run: ~p~n", [Tests]), - ok = erlang_setup(ParsedArgs), - ok = test_setup(ParsedArgs), - ParseResults. + case parse_args(Args) of + {ParsedArgs, _, Tests} = ParseResults -> + io:format("Tests to run: ~p~n", [Tests]), + ok = erlang_setup(ParsedArgs), + ok = test_setup(ParsedArgs), + ParseResults; + ok -> + io:format("No tests to run.~n"), + ok + end. execute(Tests, Outdir, Report, HarnessArgs) -> TestCount = length(Tests), @@ -66,6 +75,7 @@ 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"}, + {groups, $g, "groups", string, "specifiy a list of test groups to run"}, {dir, $d, "dir", string, "run all tests in the specified directory"}, {skip, $x, "skip", string, "list of tests to skip in a directory"}, {verbose, $v, "verbose", undefined, "verbose output"}, @@ -119,23 +129,40 @@ parse_args(Args) -> help_or_parse_args({ok, {[], _}}) -> print_help(); help_or_parse_args({ok, {ParsedArgs, HarnessArgs}}) -> - help_or_parse_tests(ParsedArgs, HarnessArgs, lists:member(help, ParsedArgs)); + help_or_parse_tests(ParsedArgs, + HarnessArgs, + lists:member(help, ParsedArgs), + args_invalid(ParsedArgs)); help_or_parse_args(_) -> print_help(). -help_or_parse_tests(_, _, true) -> +help_or_parse_tests(_, _, true, _) -> + print_help(); +help_or_parse_tests(_, _, false, true) -> print_help(); -help_or_parse_tests(ParsedArgs, HarnessArgs, false) -> +help_or_parse_tests(ParsedArgs, HarnessArgs, false, false) -> %% Have to load the `riak_test' config prior to assembling the %% test metadata load_initial_config(ParsedArgs), - TestData = compose_test_data(ParsedArgs), + Groups = proplists:get_all_values(groups, ParsedArgs), + TestData = load_tests(Groups, ParsedArgs), + Tests = which_tests_to_run(report(ParsedArgs), TestData), Offset = rt_config:get(offset, undefined), Workers = rt_config:get(workers, undefined), shuffle_tests(ParsedArgs, HarnessArgs, Tests, Offset, Workers). +args_invalid(ParsedArgs) -> + case { proplists:is_defined(groups, ParsedArgs), + proplists:is_defined(tests, ParsedArgs) } of + {true, true} -> + io:format("--groups and --tests are currently mutually exclusive.~n~n"), + true; + {_, _} -> + false + end. + load_initial_config(ParsedArgs) -> %% Loads application defaults application:load(riak_test), @@ -231,9 +258,11 @@ maybe_teardown(true, TestResults, Coverage, Verbose) -> end, ok. -compose_test_data(ParsedArgs) -> +load_tests([], ParsedArgs) -> RawTestList = proplists:get_all_values(tests, ParsedArgs), - TestList = lists:foldl(fun(X, Acc) -> string:tokens(X, ", ") ++ Acc end, [], RawTestList), + TestList = lists:foldl(fun(X, Acc) -> + string:tokens(X, ", ") ++ Acc + end, [], RawTestList), %% Parse Command Line Tests {CodePaths, SpecificTests} = lists:foldl(fun extract_test_names/2, @@ -246,8 +275,35 @@ compose_test_data(ParsedArgs) -> Dirs = proplists:get_all_values(dir, ParsedArgs), SkipTests = string:tokens(proplists:get_value(skip, ParsedArgs, []), [$,]), DirTests = lists:append([load_tests_in_dir(Dir, SkipTests) || Dir <- Dirs]), - Project = list_to_binary(rt_config:get(rt_project, "undefined")), + compose_test_data(DirTests, SpecificTests, ParsedArgs); +load_tests(RawGroupList, ParsedArgs) -> + Groups = lists:foldl(fun(X, Acc) -> + string:tokens(X, ", ") ++ Acc + end, [], RawGroupList), + Dirs = proplists:get_value(dir, ParsedArgs, ["./ebin"]), + AllDirTests = lists:append([load_tests_in_dir(Dir, []) || Dir <- Dirs]), + DirTests = get_group_tests(AllDirTests, Groups), + compose_test_data(DirTests, [], ParsedArgs). + +get_group_tests(Tests, Groups) -> + lists:filter(fun(Test) -> + Mod = list_to_atom(Test), + Attrs = Mod:module_info(attributes), + match_group_attributes(Attrs, Groups) + end, Tests). + +match_group_attributes(Attributes, Groups) -> + case proplists:get_value(test_type, Attributes) of + undefined -> + false; + TestTypes -> + lists:member(true, + [ TestType == list_to_atom(Group) + || Group <- Groups, TestType <- TestTypes ]) + end. +compose_test_data(DirTests, SpecificTests, ParsedArgs) -> + Project = list_to_binary(rt_config:get(rt_project, "undefined")), Backends = case proplists:get_all_values(backend, ParsedArgs) of [] -> [undefined]; Other -> Other @@ -259,6 +315,7 @@ compose_test_data(ParsedArgs) -> TestFoldFun = test_data_fun(rt:get_version(), Project, Backends, Upgrades), lists:foldl(TestFoldFun, [], lists:usort(DirTests ++ SpecificTests)). + test_data_fun(Version, Project, Backends, Upgrades) -> fun(Test, Tests) -> [{list_to_atom(Test), @@ -492,3 +549,4 @@ so_kill_riak_maybe() -> io:format("Leaving Riak Up... "), rt:whats_up() end. + diff --git a/tests/bucket_types.erl b/tests/bucket_types.erl index 4f05ea19c..95290cfd5 100644 --- a/tests/bucket_types.erl +++ b/tests/bucket_types.erl @@ -5,6 +5,8 @@ -include_lib("eunit/include/eunit.hrl"). -include("rt.hrl"). +-test_type([bucket_types]). + properties() -> CustomConfig = rt_cluster:augment_config(riak_core, {default_bucket_props, [{n_val, 2}]}, diff --git a/tests/ensemble_basic.erl b/tests/ensemble_basic.erl index 5e2b308d2..1f2d71e04 100644 --- a/tests/ensemble_basic.erl +++ b/tests/ensemble_basic.erl @@ -22,6 +22,8 @@ -export([confirm/0]). -include_lib("eunit/include/eunit.hrl"). +-test_type([ensemble]). + confirm() -> NumNodes = 5, NVal = 5, diff --git a/tests/http_bucket_types.erl b/tests/http_bucket_types.erl index 290e40d74..809e018c9 100644 --- a/tests/http_bucket_types.erl +++ b/tests/http_bucket_types.erl @@ -6,6 +6,8 @@ -include_lib("riakc/include/riakc.hrl"). -include("rt.hrl"). +-test_type([bucket_types, http]). + properties() -> CustomConfig = rt_cluster:augment_config(riak_core, {default_bucket_props, [{n_val, 2}]},