You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

194 line
8.2 KiB

  1. -module(rebar_eunit_SUITE).
  2. -export([suite/0,
  3. init_per_suite/1,
  4. end_per_suite/1,
  5. init_per_testcase/2,
  6. all/0]).
  7. -export([test_basic_app/1,
  8. test_multi_app/1,
  9. test_profile/1,
  10. test_basic_exports/1,
  11. test_multi_exports/1,
  12. test_basic_defines/1,
  13. test_multi_defines/1]).
  14. -include_lib("common_test/include/ct.hrl").
  15. -include_lib("eunit/include/eunit.hrl").
  16. -include_lib("kernel/include/file.hrl").
  17. suite() ->
  18. [].
  19. init_per_suite(Config) ->
  20. Config.
  21. end_per_suite(_Config) ->
  22. ok.
  23. init_per_testcase(_, Config) ->
  24. rebar_test_utils:init_rebar_state(Config, "eunit_").
  25. all() ->
  26. [test_basic_app, test_multi_app, test_profile,
  27. test_basic_exports, test_multi_exports,
  28. test_basic_defines, test_multi_defines].
  29. test_basic_app(Config) ->
  30. AppDir = ?config(apps, Config),
  31. Name = rebar_test_utils:create_random_name("basic_"),
  32. Vsn = rebar_test_utils:create_random_vsn(),
  33. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  34. RebarConfig = [{erl_opts, [{d, some_define}]}],
  35. rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}).
  36. test_multi_app(Config) ->
  37. AppDir = ?config(apps, Config),
  38. Name1 = rebar_test_utils:create_random_name("multi_app1_"),
  39. Vsn1 = rebar_test_utils:create_random_vsn(),
  40. rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]),
  41. Name1,
  42. Vsn1,
  43. [kernel, stdlib]),
  44. Name2 = rebar_test_utils:create_random_name("multi_app2_"),
  45. Vsn2 = rebar_test_utils:create_random_vsn(),
  46. rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]),
  47. Name2,
  48. Vsn2,
  49. [kernel, stdlib]),
  50. RebarConfig = [{erl_opts, [{d, some_define}]}],
  51. rebar_test_utils:run_and_check(Config,
  52. RebarConfig,
  53. ["eunit"],
  54. {ok, [{app, Name1}, {app, Name2}]}).
  55. test_profile(Config) ->
  56. AppDir = ?config(apps, Config),
  57. Name = rebar_test_utils:create_random_name("profile_"),
  58. Vsn = rebar_test_utils:create_random_vsn(),
  59. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  60. RebarConfig = [{erl_opts, [{d, some_define}]},
  61. {profiles, [{test, [{erl_opts, [debug_info]}]}]}],
  62. rebar_test_utils:run_and_check(Config,
  63. RebarConfig,
  64. ["as", "test", "eunit"],
  65. {ok, [{app, Name}]}).
  66. test_basic_exports(Config) ->
  67. AppDir = ?config(apps, Config),
  68. Name = rebar_test_utils:create_random_name("basic_exports_"),
  69. Vsn = rebar_test_utils:create_random_vsn(),
  70. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  71. RebarConfig = [{erl_opts, [{d, some_define}]}],
  72. rebar_test_utils:run_and_check(Config,
  73. RebarConfig,
  74. ["eunit"],
  75. {ok, [{app, Name}]}),
  76. App = list_to_atom("not_a_real_src_" ++ Name),
  77. Suite = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"),
  78. AppExports = App:module_info(exports),
  79. SuiteExports = Suite:module_info(exports),
  80. AppExpect = [{some_test_, 0}],
  81. SuiteExpect = [{some_test_, 0}, {define_test_, 0}],
  82. lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports) end, AppExpect),
  83. lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports) end, SuiteExpect).
  84. test_multi_exports(Config) ->
  85. AppDir = ?config(apps, Config),
  86. Name1 = rebar_test_utils:create_random_name("multi_exports_app1_"),
  87. Vsn1 = rebar_test_utils:create_random_vsn(),
  88. rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]),
  89. Name1,
  90. Vsn1,
  91. [kernel, stdlib]),
  92. Name2 = rebar_test_utils:create_random_name("multi_exports_app2_"),
  93. Vsn2 = rebar_test_utils:create_random_vsn(),
  94. rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]),
  95. Name2,
  96. Vsn2,
  97. [kernel, stdlib]),
  98. RebarConfig = [{erl_opts, [{d, some_define}]}],
  99. rebar_test_utils:run_and_check(Config,
  100. RebarConfig,
  101. ["eunit"],
  102. {ok, [{app, Name1}, {app, Name2}]}),
  103. App1 = list_to_atom("not_a_real_src_" ++ Name1),
  104. Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"),
  105. AppExports1 = App1:module_info(exports),
  106. SuiteExports1 = Suite1:module_info(exports),
  107. App2 = list_to_atom("not_a_real_src_" ++ Name2),
  108. Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"),
  109. AppExports2 = App2:module_info(exports),
  110. SuiteExports2 = Suite2:module_info(exports),
  111. AppExpect = [{some_test_, 0}],
  112. SuiteExpect = [{some_test_, 0}, {define_test_, 0}],
  113. lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports1) end, AppExpect),
  114. lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports1) end, SuiteExpect),
  115. lists:foreach(fun(Expect) -> true = lists:member(Expect, AppExports2) end, AppExpect),
  116. lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteExports2) end, SuiteExpect).
  117. test_basic_defines(Config) ->
  118. AppDir = ?config(apps, Config),
  119. Name = rebar_test_utils:create_random_name("basic_"),
  120. Vsn = rebar_test_utils:create_random_vsn(),
  121. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  122. RebarConfig = [{erl_opts, [{d, some_define}]}],
  123. rebar_test_utils:run_and_check(Config, RebarConfig, ["eunit"], {ok, [{app, Name}]}),
  124. App = list_to_atom("not_a_real_src_" ++ Name),
  125. Suite = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"),
  126. AppOpts = proplists:get_value(options, App:module_info(compile), []),
  127. SuiteOpts = proplists:get_value(options, Suite:module_info(compile), []),
  128. Expect = [{d, some_define}],
  129. lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts) end, Expect),
  130. lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts) end, Expect).
  131. test_multi_defines(Config) ->
  132. AppDir = ?config(apps, Config),
  133. Name1 = rebar_test_utils:create_random_name("multi_app1_"),
  134. Vsn1 = rebar_test_utils:create_random_vsn(),
  135. rebar_test_utils:create_eunit_app(filename:join([AppDir,Name1]),
  136. Name1,
  137. Vsn1,
  138. [kernel, stdlib]),
  139. Name2 = rebar_test_utils:create_random_name("multi_app2_"),
  140. Vsn2 = rebar_test_utils:create_random_vsn(),
  141. rebar_test_utils:create_eunit_app(filename:join([AppDir,Name2]),
  142. Name2,
  143. Vsn2,
  144. [kernel, stdlib]),
  145. RebarConfig = [{erl_opts, [{d, some_define}]}],
  146. rebar_test_utils:run_and_check(Config,
  147. RebarConfig,
  148. ["eunit"],
  149. {ok, [{app, Name1}, {app, Name2}]}),
  150. App1 = list_to_atom("not_a_real_src_" ++ Name1),
  151. Suite1 = list_to_atom("not_a_real_src_" ++ Name1 ++ "_tests"),
  152. AppOpts1 = proplists:get_value(options, App1:module_info(compile), []),
  153. SuiteOpts1 = proplists:get_value(options, Suite1:module_info(compile), []),
  154. App2 = list_to_atom("not_a_real_src_" ++ Name2),
  155. Suite2 = list_to_atom("not_a_real_src_" ++ Name2 ++ "_tests"),
  156. AppOpts2 = proplists:get_value(options, App2:module_info(compile), []),
  157. SuiteOpts2 = proplists:get_value(options, Suite2:module_info(compile), []),
  158. Expect = [{d, some_define}],
  159. lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts1) end, Expect),
  160. lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts1) end, Expect),
  161. lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts2) end, Expect),
  162. lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts2) end, Expect).