diff options
author | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2015-03-20 06:33:17 -0700 |
---|---|---|
committer | alisdair sullivan <alisdairsullivan@yahoo.ca> | 2015-03-24 22:00:51 -0700 |
commit | 069ed62690a3208c7a80ca440b5ae3efa6c7ad5e (patch) | |
tree | a1fffa1eb6fbf0b5d43e3d7b1c6a10ea3fe4cf77 /test/rebar_eunit_SUITE.erl | |
parent | deebd23a88e1c89647c864846dfc6a69df02b045 (diff) |
add a more direct way to generate an `eunitized` test app to
test utils and add better eunit tests
Diffstat (limited to 'test/rebar_eunit_SUITE.erl')
-rw-r--r-- | test/rebar_eunit_SUITE.erl | 159 |
1 files changed, 152 insertions, 7 deletions
diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index bf6b8ec..39dc30c 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -4,9 +4,14 @@ init_per_suite/1, end_per_suite/1, init_per_testcase/2, - all/0, - test_basic_app/1, - test_profile/1]). + all/0]). +-export([test_basic_app/1, + test_multi_app/1, + test_profile/1, + test_basic_exports/1, + test_multi_exports/1, + test_basic_defines/1, + test_multi_defines/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -25,25 +30,165 @@ init_per_testcase(_, Config) -> rebar_test_utils:init_rebar_state(Config, "eunit_"). all() -> - [test_basic_app, test_profile]. + [test_basic_app, test_multi_app, test_profile, + test_basic_exports, test_multi_exports, + test_basic_defines, test_multi_defines]. test_basic_app(Config) -> AppDir = ?config(apps, Config), Name = rebar_test_utils:create_random_name("basic_"), Vsn = rebar_test_utils:create_random_vsn(), - rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), RebarConfig = [{erl_opts, [{d, some_define}]}], rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}). +test_multi_app(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_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_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"], + {ok, [{app, Name1}, {app, Name2}]}). + test_profile(Config) -> AppDir = ?config(apps, Config), - Name = rebar_test_utils:create_random_name("basic_"), + Name = rebar_test_utils:create_random_name("profile_"), Vsn = rebar_test_utils:create_random_vsn(), rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), RebarConfig = [{erl_opts, [{d, some_define}]}, {profiles, [{test, [{erl_opts, [debug_info]}]}]}], - rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "test", "eunit"], {ok, [{app, Name}]}). + rebar_test_utils:run_and_check(Config, + RebarConfig, + ["as", "test", "eunit"], + {ok, [{app, Name}]}). + +test_basic_exports(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("basic_exports_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + rebar_test_utils:run_and_check(Config, + RebarConfig, + ["eunit"], + {ok, [{app, Name}]}), + + App = list_to_atom("not_a_real_src_" ++ Name), + Suite = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), + AppExports = App:module_info(exports), + SuiteExports = Suite:module_info(exports), + AppExpect = [{some_test_, 0}], + SuiteExpect = [{some_test_, 0}, {define_test_, 0}], + lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports) end, AppExpect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports) end, SuiteExpect). + +test_multi_exports(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"], + {ok, [{app, Name1}, {app, Name2}]}), + + App1 = list_to_atom("not_a_real_src_" ++ Name1), + Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), + AppExports1 = App1:module_info(exports), + SuiteExports1 = Suite1:module_info(exports), + App2 = list_to_atom("not_a_real_src_" ++ Name2), + Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), + AppExports2 = App2:module_info(exports), + SuiteExports2 = Suite2:module_info(exports), + AppExpect = [{some_test_, 0}], + SuiteExpect = [{some_test_, 0}, {define_test_, 0}], + lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports1) end, AppExpect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports1) end, SuiteExpect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports2) end, AppExpect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports2) end, SuiteExpect). + +test_basic_defines(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("basic_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]), + + RebarConfig = [{erl_opts, [{d, some_define}]}], + rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}), + + App = list_to_atom("not_a_real_src_" ++ Name), + Suite = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"), + AppOpts = proplists:get_value(options, App:module_info(compile), []), + SuiteOpts = proplists:get_value(options, Suite:module_info(compile), []), + Expect = [{d, some_define}], + lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts) end, Expect), + lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts) end, Expect). + +test_multi_defines(Config) -> + AppDir = ?config(apps, Config), + + Name1 = rebar_test_utils:create_random_name("multi_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_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"], + {ok, [{app, Name1}, {app, Name2}]}), + + App1 = list_to_atom("not_a_real_src_" ++ Name1), + Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"), + AppOpts1 = proplists:get_value(options, App1:module_info(compile), []), + SuiteOpts1 = proplists:get_value(options, Suite1:module_info(compile), []), + App2 = list_to_atom("not_a_real_src_" ++ Name2), + Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"), + AppOpts2 = proplists:get_value(options, App2:module_info(compile), []), + SuiteOpts2 = proplists:get_value(options, Suite2:module_info(compile), []), + Expect = [{d, some_define}], + lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts1) end, Expect), + 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). |