summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSiri Hansen <siri@erlang.org>2016-11-28 11:45:21 +0100
committerSiri Hansen <siri@erlang.org>2016-12-07 14:36:07 +0100
commit85e00f2a434d3295d7a683838cda002403f5af17 (patch)
treedc8ee006655a88b662264ea2eb55180af8d6e2e9 /test
parent9f7e79d8157db06b3b03e033db87c2e811d938d2 (diff)
Improve merge of command line options and config options
Bug: option 'spec' is not specifically handled when merging options from the command line with options from rebar.config. Due to this, if the config specifies a 'spec', then this will take precedence over any 'dir' and/or 'suite' on the command line. This commit takes special care of all options that can be used to select tests - meaning that if any of the options 'spec', 'dir', 'suite', 'group' or 'case' are specified on the command line, then all 'spec', 'dir', 'suite', 'group' and 'case' options in rebar.config will be ignored.
Diffstat (limited to 'test')
-rw-r--r--test/rebar_ct_SUITE.erl86
1 files changed, 84 insertions, 2 deletions
diff --git a/test/rebar_ct_SUITE.erl b/test/rebar_ct_SUITE.erl
index 8e989b5..1995690 100644
--- a/test/rebar_ct_SUITE.erl
+++ b/test/rebar_ct_SUITE.erl
@@ -51,7 +51,9 @@
cover_compiled/1,
misspecified_ct_opts/1,
misspecified_ct_compile_opts/1,
- misspecified_ct_first_files/1]).
+ misspecified_ct_first_files/1,
+ testspec/1,
+ cmd_vs_cfg_opts/1]).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
@@ -67,7 +69,9 @@ all() -> [{group, basic_app},
cfg_atom_suites,
misspecified_ct_opts,
misspecified_ct_compile_opts,
- misspecified_ct_first_files].
+ misspecified_ct_first_files,
+ testspec,
+ cmd_vs_cfg_opts].
groups() -> [{basic_app, [], [basic_app_default_dirs,
basic_app_default_beams,
@@ -1234,6 +1238,84 @@ misspecified_ct_first_files(Config) ->
{badconfig, {"Value `~p' of option `~p' must be a list", {some_file, ct_first_files}}} = Error.
+testspec(Config) ->
+ C = rebar_test_utils:init_rebar_state(Config, "ct_testspec_"),
+
+ AppDir = ?config(apps, C),
+
+ Name = rebar_test_utils:create_random_name("ct_testspec_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+ Spec = filename:join([AppDir, "test", "some.spec"]),
+ ok = filelib:ensure_dir(Spec),
+ ok = file:write_file(Spec, "[].\n"),
+
+ {ok, State} = rebar_test_utils:run_and_check(C,
+ [],
+ ["as", "test", "lock"],
+ return),
+
+ Providers = rebar_state:providers(State),
+ Namespace = rebar_state:namespace(State),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+
+ {ok, GetOptResult1} = getopt:parse(GetOptSpec, ["--spec","test/some.spec"]),
+ State1 = rebar_state:command_parsed_args(State, GetOptResult1),
+ Tests1 = rebar_prv_common_test:prepare_tests(State1),
+ {ok, _} = rebar_prv_common_test:compile(State1, Tests1),
+
+ ok.
+
+cmd_vs_cfg_opts(Config) ->
+ C = rebar_test_utils:init_rebar_state(Config, "ct_cmd_vs_cfg_opts_"),
+
+ AppDir = ?config(apps, C),
+
+ Name = rebar_test_utils:create_random_name("ct_cmd_vs_cfg_opts_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ RebarConfig = [{ct_opts, [{spec,"mytest.spec"},
+ {dir,"test"},
+ {suite,"some_SUITE"},
+ {group,"some_group"},
+ {testcase,"some_test"}]}],
+
+ {ok, State} = rebar_test_utils:run_and_check(C, RebarConfig, ["as", "test", "lock"], return),
+
+ {ok, TestOpts} = rebar_prv_common_test:prepare_tests(State),
+ true = lists:member({spec, "mytest.spec"}, TestOpts),
+ true = lists:member({dir, "test"}, TestOpts),
+ true = lists:member({suite, "some_SUITE"}, TestOpts),
+ true = lists:member({group, "some_group"}, TestOpts),
+ true = lists:member({testcase, "some_test"}, TestOpts),
+
+ Providers = rebar_state:providers(State),
+ Namespace = rebar_state:namespace(State),
+ CommandProvider = providers:get_provider(ct, Providers, Namespace),
+ GetOptSpec = providers:opts(CommandProvider),
+
+ {ok, GetOptResult1} = getopt:parse(GetOptSpec, ["--spec","test/some.spec"]),
+ State1 = rebar_state:command_parsed_args(State, GetOptResult1),
+ {ok, TestOpts1} = rebar_prv_common_test:prepare_tests(State1),
+ true = lists:member({spec, ["test/some.spec"]}, TestOpts1),
+ false = lists:keymember(dir, 1, TestOpts1),
+ false = lists:keymember(suite, 1, TestOpts1),
+ false = lists:keymember(group, 1, TestOpts1),
+ false = lists:keymember(testcase, 1, TestOpts1),
+
+ {ok, GetOptResult2} = getopt:parse(GetOptSpec, ["--suite","test/some_SUITE"]),
+ State2 = rebar_state:command_parsed_args(State, GetOptResult2),
+ {ok, TestOpts2} = rebar_prv_common_test:prepare_tests(State2),
+ true = lists:member({suite, ["test/some_SUITE"]}, TestOpts2),
+ false = lists:keymember(spec, 1, TestOpts2),
+ false = lists:keymember(dir, 1, TestOpts2),
+ false = lists:keymember(group, 1, TestOpts2),
+ false = lists:keymember(testcase, 1, TestOpts2),
+
+ ok.
+
%% helper for generating test data
test_suite(Name) ->
io_lib:format("-module(~ts_SUITE).\n"