summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2016-10-17 22:07:51 -0400
committerGitHub <noreply@github.com>2016-10-17 22:07:51 -0400
commit7f8e1c8294f83911e247e438a948f12ae42c1fe2 (patch)
tree4b4fb10894af2bc130d11c6ba69ef55f3273ff29
parent4e7b765645d7eb49da750ed59bb917d41cd08a66 (diff)
parent14956eaf168dd20b0b1da1c05a82d66da77ec37c (diff)
Merge pull request #1357 from erlang/ct_spec
experimental: allow test specifications to be passed via the command line
-rw-r--r--src/rebar_prv_common_test.erl11
-rw-r--r--test/rebar_ct_SUITE.erl54
2 files changed, 43 insertions, 22 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 46bd1a7..b91c90f 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -139,6 +139,8 @@ transform_opts([{testcase, Cases}|Rest], Acc) ->
transform_opts(Rest, [{testcase, split_string(Cases)}|Acc]);
transform_opts([{config, Configs}|Rest], Acc) ->
transform_opts(Rest, [{config, split_string(Configs)}|Acc]);
+transform_opts([{spec, Specs}|Rest], Acc) ->
+ transform_opts(Rest, [{spec, split_string(Specs)}|Acc]);
transform_opts([{include, Includes}|Rest], Acc) ->
transform_opts(Rest, [{include, split_string(Includes)}|Acc]);
transform_opts([{logopts, LogOpts}|Rest], Acc) ->
@@ -174,9 +176,6 @@ cfgopts(State) ->
end.
ensure_opts([], Acc) -> lists:reverse(Acc);
-ensure_opts([{test_spec, _}|Rest], Acc) ->
- ?WARN("Test specs not supported. See http://www.rebar3.org/docs/running-tests#common-test", []),
- ensure_opts(Rest, Acc);
ensure_opts([{cover, _}|Rest], Acc) ->
?WARN("Cover specs not supported. See http://www.rebar3.org/docs/running-tests#common-test", []),
ensure_opts(Rest, Acc);
@@ -650,6 +649,8 @@ ct_opts(_State) ->
{testcase, undefined, "case", string, help(testcase)}, %% comma-seperated list
{label, undefined, "label", string, help(label)}, %% String
{config, undefined, "config", string, help(config)}, %% comma-seperated list
+ {spec, undefined, "spec", string, help(spec)}, %% comma-seperated list
+ {join_specs, undefined, "join_specs", boolean, help(join_specs)},
{allow_user_terms, undefined, "allow_user_terms", boolean, help(allow_user_terms)}, %% Bool
{logdir, undefined, "logdir", string, help(logdir)}, %% dir
{logopts, undefined, "logopts", string, help(logopts)}, %% comma seperated list
@@ -688,6 +689,10 @@ help(label) ->
"Test label";
help(config) ->
"List of config files";
+help(spec) ->
+ "List of test specifications";
+help(join_specs) ->
+ "Merge all test specifications and perform a single test run";
help(sys_config) ->
"List of application config files";
help(allow_user_terms) ->
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index c10875b..8e989b5 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -24,6 +24,8 @@
data_dir_correct/1,
cmd_label/1,
cmd_config/1,
+ cmd_spec/1,
+ cmd_join_specs/1,
cmd_allow_user_terms/1,
cmd_logdir/1,
cmd_logopts/1,
@@ -44,7 +46,6 @@
cmd_sys_config/1,
cfg_opts/1,
cfg_arbitrary_opts/1,
- cfg_test_spec/1,
cfg_cover_spec/1,
cfg_atom_suites/1,
cover_compiled/1,
@@ -62,7 +63,7 @@ all() -> [{group, basic_app},
{group, ct_opts},
{group, cover},
cfg_opts, cfg_arbitrary_opts,
- cfg_test_spec, cfg_cover_spec,
+ cfg_cover_spec,
cfg_atom_suites,
misspecified_ct_opts,
misspecified_ct_compile_opts,
@@ -88,6 +89,8 @@ groups() -> [{basic_app, [], [basic_app_default_dirs,
{data_dirs, [], [data_dir_correct]},
{ct_opts, [], [cmd_label,
cmd_config,
+ cmd_spec,
+ cmd_join_specs,
cmd_allow_user_terms,
cmd_logdir,
cmd_logopts,
@@ -761,6 +764,36 @@ cmd_config(Config) ->
true = lists:member({config, ["config/foo", "config/bar", "config/baz"]}, TestOpts).
+cmd_spec(Config) ->
+ State = ?config(result, Config),
+
+ Providers = rebar_state:providers(State),
+ Namespace = rebar_state:namespace(State),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--spec=foo.spec,bar.spec,baz.spec"]),
+
+ NewState = rebar_state:command_parsed_args(State, GetOptResult),
+
+ {ok, TestOpts} = rebar_prv_common_test:prepare_tests(NewState),
+
+ true = lists:member({spec, ["foo.spec", "bar.spec", "baz.spec"]}, TestOpts).
+
+cmd_join_specs(Config) ->
+ State = ?config(result, Config),
+
+ Providers = rebar_state:providers(State),
+ Namespace = rebar_state:namespace(State),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+ {ok, GetOptResult} = getopt:parse(GetOptSpec, ["--join_specs=true"]),
+
+ NewState = rebar_state:command_parsed_args(State, GetOptResult),
+
+ {ok, TestOpts} = rebar_prv_common_test:prepare_tests(NewState),
+
+ true = lists:member({join_specs, true}, TestOpts).
+
cmd_allow_user_terms(Config) ->
State = ?config(result, Config),
@@ -1096,23 +1129,6 @@ cfg_arbitrary_opts(Config) ->
true = lists:member({bar, 2}, TestOpts),
true = lists:member({baz, 3}, TestOpts).
-cfg_test_spec(Config) ->
- C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_test_spec_opts_"),
-
- AppDir = ?config(apps, C),
-
- Name = rebar_test_utils:create_random_name("ct_cfg_test_spec_opts_"),
- Vsn = rebar_test_utils:create_random_vsn(),
- rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
-
- RebarConfig = [{ct_opts, [Opt = {test_spec, "spec/foo.spec"}]}],
-
- {ok, State} = rebar_test_utils:run_and_check(C, RebarConfig, ["as", "test", "lock"], return),
-
- {ok, TestOpts} = rebar_prv_common_test:prepare_tests(State),
-
- false = lists:member(Opt, TestOpts).
-
cfg_cover_spec(Config) ->
C = rebar_test_utils:init_rebar_state(Config, "ct_cfg_cover_spec_opts_"),