diff options
author | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2015-03-23 16:12:19 -0700 |
---|---|---|
committer | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2015-03-24 22:01:28 -0700 |
commit | c5bc19b021da907e36135c174d85896be3043218 (patch) | |
tree | 340e18707d331bcc5b3b8d25bdd03bda86fdb93a /test | |
parent | 069ed62690a3208c7a80ca440b5ae3efa6c7ad5e (diff) |
add `--app=...` and `--suite=...` options for the eunit provider to
run subsets of test suites
Diffstat (limited to 'test')
-rw-r--r-- | test/rebar_eunit_SUITE.erl | 198 |
1 files changed, 196 insertions, 2 deletions
diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index 39dc30c..33df773 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -11,7 +11,14 @@ test_basic_exports/1, test_multi_exports/1, test_basic_defines/1, - test_multi_defines/1]). + test_multi_defines/1, + test_single_app_flag/1, + test_multiple_app_flag/1, + test_nonexistent_app_flag/1, + test_single_suite_flag/1, + test_suite_in_app_flag/1, + test_suite_in_wrong_app_flag/1, + test_nonexistent_suite_flag/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -32,7 +39,10 @@ init_per_testcase(_, Config) -> all() -> [test_basic_app, test_multi_app, test_profile, test_basic_exports, test_multi_exports, - test_basic_defines, test_multi_defines]. + test_basic_defines, test_multi_defines, + test_single_app_flag, test_multiple_app_flag, test_nonexistent_app_flag, + test_single_suite_flag, test_suite_in_app_flag, + test_suite_in_wrong_app_flag, test_nonexistent_suite_flag]. test_basic_app(Config) -> AppDir = ?config(apps, Config), @@ -192,3 +202,187 @@ test_multi_defines(Config) -> lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts1) end, Expect), lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts2) end, Expect), lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts2) end, Expect). + +test_single_app_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", "--app=" ++ Name1], + {ok, [{app, Name1}, {app, Name2}]}), + + Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), + {module, Suite1} = code:ensure_loaded(Suite1), + Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), + {error, nofile} = code:ensure_loaded(Suite2). + +test_multiple_app_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", "--app=" ++ Name1 ++ "," ++ Name2], + {ok, [{app, Name1}, {app, Name2}]}), + + Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), + {module, Suite1} = code:ensure_loaded(Suite1), + Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), + {module, Suite2} = code:ensure_loaded(Suite2). + +test_nonexistent_app_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + {error, {_, Error}} = rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", "--app=not_a_real_app"], + return), + + Error = {error_running_tests, "Application `not_a_real_app' not found in project."}. + +test_single_suite_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", "--suite=not_a_real_src_" ++ Name1], + {ok, [{app, Name1}, {app, Name2}]}), + + Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), + {module, Suite1} = code:ensure_loaded(Suite1). + +test_suite_in_app_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", + "--app=" ++ Name1, + "--suite=not_a_real_src_" ++ Name1], + {ok, [{app, Name1}, {app, Name2}]}), + + Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), + {module, Suite1} = code:ensure_loaded(Suite1), + Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), + {error, nofile} = code:ensure_loaded(Suite2). + +test_suite_in_wrong_app_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + {error, {_, Error}} = rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", + "--app=" ++ Name1, + "--suite=not_a_real_src_" ++ Name2], + return), + + Error = {error_running_tests, "Module `not_a_real_src_" ++ + Name2 ++ + "' not found in applications."}. + +test_nonexistent_suite_flag(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"), + Vsn1 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]), + Name1, + Vsn1, + [kernel, stdlib]), + Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"), + Vsn2 = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]), + Name2, + Vsn2, + [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + {error, {_, Error}} = rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit", "--suite=not_a_real_module"], + return), + + Error = {error_running_tests, "Module `not_a_real_module' not found in applications."}. |