Add experimental tests= filter without eunit suites

This commit is contained in:
Roberto Ostinelli 2012-08-19 14:23:06 -07:00 committed by Tuncer Ayaz
parent 9dd8e7f2ee
commit fa6618f2b4
3 changed files with 40 additions and 9 deletions

View file

@ -300,6 +300,11 @@ generate-appups previous_release=path Generate appup files
eunit [suites=foo] Run eunit tests [foo.erl and test/foo_tests.erl] eunit [suites=foo] Run eunit tests [foo.erl and test/foo_tests.erl]
[suites=foo] [tests=bar] Run specific eunit tests [first test name starting [suites=foo] [tests=bar] Run specific eunit tests [first test name starting
with 'bar' in foo.erl and test/foo_tests.erl] with 'bar' in foo.erl and test/foo_tests.erl]
[tests=bar] For every existing suite, run the first test whose
name starts with bar and, if no such test exists,
run the test whose name starts with bar in
the suite's _tests module
ct [suites=] [case=] Run common_test suites ct [suites=] [case=] Run common_test suites
qc Test QuickCheck properties qc Test QuickCheck properties

View file

@ -51,6 +51,12 @@
%% suites="foo,bar" tests="baz"- runs first test with name starting %% suites="foo,bar" tests="baz"- runs first test with name starting
%% with 'baz' in foo.erl, test/foo_tests.erl and tests in bar.erl, %% with 'baz' in foo.erl, test/foo_tests.erl and tests in bar.erl,
%% test/bar_tests.erl %% test/bar_tests.erl
%% </li>
%% <li>
%% tests="baz"- For every existing suite, run the first test whose
%% name starts with bar and, if no such test exists, run the test
%% whose name starts with bar in the suite's _tests module
%% </li>
%% </ul> %% </ul>
%% Additionally, for projects that have separate folders for the core %% Additionally, for projects that have separate folders for the core
%% implementation, and for the unit tests, then the following %% implementation, and for the unit tests, then the following
@ -112,7 +118,8 @@ run_eunit(Config, CodePath, SrcErls) ->
%% Get modules to be run in eunit %% Get modules to be run in eunit
AllModules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- AllBeamFiles], AllModules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- AllBeamFiles],
{SuitesProvided, FilteredModules} = filter_suites(Config, AllModules), {SuitesProvided, FilteredModules} = filter_suites(Config, AllModules),
%% TODO: make tests= work with no suites= provided
%% build the tests
Tests = get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules), Tests = get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules),
SrcModules = [rebar_utils:erl_to_mod(M) || M <- SrcErls], SrcModules = [rebar_utils:erl_to_mod(M) || M <- SrcErls],
@ -174,7 +181,7 @@ filter_suites1(Modules, Suites) ->
[M || M <- Modules, lists:member(M, Suites)]. [M || M <- Modules, lists:member(M, Suites)].
get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules) -> get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules) ->
case SuitesProvided of Modules = case SuitesProvided of
false -> false ->
%% No specific suites have been provided, use ModuleBeamFiles %% No specific suites have been provided, use ModuleBeamFiles
%% which filters out "*_tests" modules so eunit won't doubly run %% which filters out "*_tests" modules so eunit won't doubly run
@ -194,18 +201,19 @@ get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules) ->
%% public interface of the main module (and no other code)." %% public interface of the main module (and no other code)."
[rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- ModuleBeamFiles]; [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- ModuleBeamFiles];
true -> true ->
%% Specific suites have been provided, return the existing modules %% Specific suites have been provided, return the filtered modules
build_tests(Config, FilteredModules) FilteredModules
end. end,
build_tests(Config, Modules).
build_tests(Config, SuitesModules) -> build_tests(Config, Modules) ->
RawFunctions = rebar_utils:get_experimental_global(Config, tests, ""), RawFunctions = rebar_utils:get_experimental_global(Config, tests, ""),
Tests = [list_to_atom(F1) || F1 <- string:tokens(RawFunctions, ",")], Tests = [list_to_atom(F1) || F1 <- string:tokens(RawFunctions, ",")],
case Tests of case Tests of
[] -> [] ->
SuitesModules; Modules;
Functions -> Functions ->
case build_tests1(SuitesModules, Functions, []) of case build_tests1(Modules, Functions, []) of
[] -> [] ->
[]; [];
RawTests -> RawTests ->

View file

@ -138,7 +138,7 @@ eunit_with_suites_and_tests_test_() ->
{"Selected suite tests are run once", {"Selected suite tests are run once",
?_assert(string:str(RebarOut, "All 3 tests passed") =/= 0)}] ?_assert(string:str(RebarOut, "All 3 tests passed") =/= 0)}]
end}, end},
{"Ensure EUnit runs specific test in _tests suites", {"Ensure EUnit runs specific test in a _tests suite",
setup, setup,
fun() -> fun() ->
setup_project_with_multiple_modules(), setup_project_with_multiple_modules(),
@ -155,6 +155,24 @@ eunit_with_suites_and_tests_test_() ->
{"Selected suite tests is run once", {"Selected suite tests is run once",
?_assert(string:str(RebarOut, "Test passed") =/= 0)}] ?_assert(string:str(RebarOut, "Test passed") =/= 0)}]
end},
{"Ensure EUnit runs a specific test without a specified suite",
setup,
fun() ->
setup_project_with_multiple_modules(),
rebar("-v eunit tests=myprivate")
end,
fun teardown/1,
fun(RebarOut) ->
[{"Only selected suite tests are found and run",
[?_assert(string:str(RebarOut,
"myapp_mymod:myprivate_test/0") =/= 0),
?_assert(string:str(RebarOut,
"myapp_mymod2:myprivate2_test/0")
=/= 0)]},
{"Selected suite tests is run once",
?_assert(string:str(RebarOut, "All 2 tests passed") =/= 0)}]
end}]. end}].
cover_test_() -> cover_test_() ->