Explorar el Código

Allow single test spec in ct_opts

The option {spec,Specs} is allowed in ct_opts, but
rebar_prv_common_test:test_dirs did not take into account that Specs
could also be a string only, i.e. not a list of strings.
pull/1506/head
Siri Hansen hace 8 años
padre
commit
64b5d878af
Se han modificado 2 ficheros con 54 adiciones y 14 borrados
  1. +15
    -12
      src/rebar_prv_common_test.erl
  2. +39
    -2
      test/rebar_ct_SUITE.erl

+ 15
- 12
src/rebar_prv_common_test.erl Ver fichero

@ -431,18 +431,21 @@ test_dirs(State, Apps, Opts) ->
set_compile_dirs(State, Apps, join(Suites, Dir));
{_Suites, _Dirs} -> {error, "Only a single directory may be specified when specifying suites"}
end;
Specs0 ->
case get_dirs_from_specs(Specs0) of
{ok,{Specs,SuiteDirs}} ->
{State1,Apps1} = set_compile_dirs1(State, Apps,
{dir, SuiteDirs}),
{State2,Apps2} = set_compile_dirs1(State1, Apps1,
{spec, Specs}),
[maybe_copy_spec(State2,Apps2,S) || S <- Specs],
{ok, rebar_state:project_apps(State2, Apps2)};
Error ->
Error
end
Spec when is_integer(hd(Spec)) ->
spec_test_dirs(State, Apps, [Spec]);
Specs ->
spec_test_dirs(State, Apps, Specs)
end.
spec_test_dirs(State, Apps, Specs0) ->
case get_dirs_from_specs(Specs0) of
{ok,{Specs,SuiteDirs}} ->
{State1,Apps1} = set_compile_dirs1(State, Apps, {dir, SuiteDirs}),
{State2,Apps2} = set_compile_dirs1(State1, Apps1, {spec, Specs}),
[maybe_copy_spec(State2,Apps2,S) || S <- Specs],
{ok, rebar_state:project_apps(State2, Apps2)};
Error ->
Error
end.
join(Suite, Dir) when is_integer(hd(Suite)) ->

+ 39
- 2
test/rebar_ct_SUITE.erl Ver fichero

@ -55,7 +55,8 @@
testspec/1,
testspec_at_root/1,
testspec_parse_error/1,
cmd_vs_cfg_opts/1]).
cmd_vs_cfg_opts/1,
single_testspec_in_ct_opts/1]).
-include_lib("eunit/include/eunit.hrl").
-include_lib("common_test/include/ct.hrl").
@ -75,7 +76,8 @@ all() -> [{group, basic_app},
testspec,
testspec_at_root,
testspec_parse_error,
cmd_vs_cfg_opts].
cmd_vs_cfg_opts,
single_testspec_in_ct_opts].
groups() -> [{basic_app, [], [basic_app_default_dirs,
basic_app_default_beams,
@ -1548,6 +1550,41 @@ cmd_vs_cfg_opts(Config) ->
ok.
single_testspec_in_ct_opts(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, "{suites,\".\",all}.\n"),
{ok,Wd} = file:get_cwd(),
ok = file:set_cwd(AppDir),
RebarConfig = [{ct_opts, [{spec,"test/some.spec"}]}],
{ok, State} = rebar_test_utils:run_and_check(C, RebarConfig, ["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),
%% Testspec in "test" directory
{ok, GetOptResult1} = getopt:parse(GetOptSpec, []),
State1 = rebar_state:command_parsed_args(State, GetOptResult1),
Tests1 = rebar_prv_common_test:prepare_tests(State1),
{ok, T1} = Tests1,
"test/some.spec" = proplists:get_value(spec,T1),
{ok, _NewState} = rebar_prv_common_test:compile(State1, Tests1),
ok = file:set_cwd(Wd),
ok.
%% helper for generating test data
test_suite(Name) ->
io_lib:format("-module(~ts_SUITE).\n"

Cargando…
Cancelar
Guardar