mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Fix tests= option not running generator tests
This commit is contained in:
parent
fa6618f2b4
commit
60516dc406
2 changed files with 38 additions and 3 deletions
|
@ -220,7 +220,16 @@ build_tests(Config, Modules) ->
|
||||||
?CONSOLE(" Running test function(s):~n", []),
|
?CONSOLE(" Running test function(s):~n", []),
|
||||||
F = fun({M, F2}, Acc) ->
|
F = fun({M, F2}, Acc) ->
|
||||||
?CONSOLE(" ~p:~p/0~n", [M, F2]),
|
?CONSOLE(" ~p:~p/0~n", [M, F2]),
|
||||||
[eunit_test:function_wrapper(M, F2)|Acc]
|
FNameStr = atom_to_list(F2),
|
||||||
|
NewFunction = case re:run(FNameStr, "_test_") =/= nomatch of
|
||||||
|
true ->
|
||||||
|
%% Generator
|
||||||
|
{generator, eunit_test:function_wrapper(M, F2)};
|
||||||
|
_ ->
|
||||||
|
%% Normal test
|
||||||
|
eunit_test:function_wrapper(M, F2)
|
||||||
|
end,
|
||||||
|
[NewFunction|Acc]
|
||||||
end,
|
end,
|
||||||
lists:foldl(F, [], RawTests)
|
lists:foldl(F, [], RawTests)
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,6 +118,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},
|
end},
|
||||||
|
{"Ensure EUnit runs a specific generator test defined in a selected suite",
|
||||||
|
setup, fun() ->
|
||||||
|
setup_project_with_multiple_modules(),
|
||||||
|
rebar("-v eunit suites=myapp_mymod3 tests=mygenerator")
|
||||||
|
end,
|
||||||
|
fun teardown/1,
|
||||||
|
fun(RebarOut) ->
|
||||||
|
[{"Selected suite's generator test is found and run",
|
||||||
|
?_assert(string:str(RebarOut,
|
||||||
|
"myapp_mymod3:mygenerator_test_/0") =/= 0)},
|
||||||
|
|
||||||
|
{"Selected suite's generator test raises an error",
|
||||||
|
?_assert(string:str(RebarOut,
|
||||||
|
"assertEqual_failed") =/= 0)},
|
||||||
|
|
||||||
|
{"Selected suite tests is run once",
|
||||||
|
?_assert(string:str(RebarOut, "Failed: 1.") =/= 0)}]
|
||||||
|
end},
|
||||||
{"Ensure EUnit runs specific tests defined in selected suites",
|
{"Ensure EUnit runs specific tests defined in selected suites",
|
||||||
setup, fun() ->
|
setup, fun() ->
|
||||||
setup_project_with_multiple_modules(),
|
setup_project_with_multiple_modules(),
|
||||||
|
@ -289,6 +307,13 @@ basic_setup_test_() ->
|
||||||
"myfunc2_test() -> ?assertMatch(ok, myapp_mymod2:myfunc2()).\n",
|
"myfunc2_test() -> ?assertMatch(ok, myapp_mymod2:myfunc2()).\n",
|
||||||
"common_name_test() -> ?assert(true).\n"]).
|
"common_name_test() -> ?assert(true).\n"]).
|
||||||
|
|
||||||
|
-define(myapp_mymod3,
|
||||||
|
["-module(myapp_mymod3).\n",
|
||||||
|
"-export([myfunc3/0]).\n",
|
||||||
|
"-include_lib(\"eunit/include/eunit.hrl\").\n",
|
||||||
|
"myfunc3() -> ok.\n",
|
||||||
|
"mygenerator_test_() -> [?_assertEqual(true, false)].\n"]).
|
||||||
|
|
||||||
-define(mysuite,
|
-define(mysuite,
|
||||||
["-module(mysuite).\n",
|
["-module(mysuite).\n",
|
||||||
"-export([all_test_/0]).\n",
|
"-export([all_test_/0]).\n",
|
||||||
|
@ -320,7 +345,8 @@ setup_basic_project() ->
|
||||||
setup_project_with_multiple_modules() ->
|
setup_project_with_multiple_modules() ->
|
||||||
setup_basic_project(),
|
setup_basic_project(),
|
||||||
ok = file:write_file("test/myapp_mymod2_tests.erl", ?myapp_mymod2_tests),
|
ok = file:write_file("test/myapp_mymod2_tests.erl", ?myapp_mymod2_tests),
|
||||||
ok = file:write_file("src/myapp_mymod2.erl", ?myapp_mymod2).
|
ok = file:write_file("src/myapp_mymod2.erl", ?myapp_mymod2),
|
||||||
|
ok = file:write_file("src/myapp_mymod3.erl", ?myapp_mymod3).
|
||||||
|
|
||||||
setup_cover_project() ->
|
setup_cover_project() ->
|
||||||
setup_basic_project(),
|
setup_basic_project(),
|
||||||
|
|
Loading…
Reference in a new issue