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.

234 lines
9.0 KiB

  1. -module(rebar_cover_SUITE).
  2. -export([suite/0,
  3. init_per_suite/1,
  4. end_per_suite/1,
  5. init_per_testcase/2,
  6. all/0,
  7. flag_coverdata_written/1,
  8. config_coverdata_written/1,
  9. basic_extra_src_dirs/1,
  10. release_extra_src_dirs/1,
  11. root_extra_src_dirs/1,
  12. index_written/1,
  13. flag_verbose/1,
  14. config_verbose/1,
  15. excl_mods/1]).
  16. -include_lib("common_test/include/ct.hrl").
  17. -include_lib("eunit/include/eunit.hrl").
  18. -include_lib("kernel/include/file.hrl").
  19. suite() ->
  20. [].
  21. init_per_suite(Config) ->
  22. Config.
  23. end_per_suite(_Config) ->
  24. ok.
  25. init_per_testcase(_, Config) ->
  26. rebar_test_utils:init_rebar_state(Config, "cover_").
  27. all() ->
  28. [flag_coverdata_written, config_coverdata_written,
  29. basic_extra_src_dirs, release_extra_src_dirs,
  30. root_extra_src_dirs,
  31. index_written,
  32. flag_verbose, config_verbose,
  33. excl_mods].
  34. flag_coverdata_written(Config) ->
  35. AppDir = ?config(apps, Config),
  36. Name = rebar_test_utils:create_random_name("cover_"),
  37. Vsn = rebar_test_utils:create_random_vsn(),
  38. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  39. RebarConfig = [{erl_opts, [{d, some_define}]}],
  40. rebar_test_utils:run_and_check(Config,
  41. RebarConfig,
  42. ["eunit", "--cover"],
  43. {ok, [{app, Name}]}),
  44. true = filelib:is_file(filename:join([AppDir, "_build", "test", "cover", "eunit.coverdata"])).
  45. config_coverdata_written(Config) ->
  46. AppDir = ?config(apps, Config),
  47. Name = rebar_test_utils:create_random_name("cover_"),
  48. Vsn = rebar_test_utils:create_random_vsn(),
  49. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  50. RebarConfig = [{erl_opts, [{d, some_define}]}, {cover_enabled, true}],
  51. rebar_test_utils:run_and_check(Config,
  52. RebarConfig,
  53. ["eunit"],
  54. {ok, [{app, Name}]}),
  55. true = filelib:is_file(filename:join([AppDir, "_build", "test", "cover", "eunit.coverdata"])).
  56. basic_extra_src_dirs(Config) ->
  57. AppDir = ?config(apps, Config),
  58. Name = rebar_test_utils:create_random_name("cover_extra_"),
  59. Vsn = rebar_test_utils:create_random_vsn(),
  60. rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
  61. ExtraSrc = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name]),
  62. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  63. ok = file:write_file(filename:join([AppDir, "extra", io_lib:format("~ts_extra.erl", [Name])]),
  64. ExtraSrc),
  65. RebarConfig = [{erl_opts, [{d, some_define}]}, {extra_src_dirs, ["extra"]}],
  66. rebar_test_utils:run_and_check(Config,
  67. RebarConfig,
  68. ["eunit", "--cover"],
  69. {ok, [{app, Name}]}),
  70. Mod = list_to_atom(Name),
  71. {file, _} = cover:is_compiled(Mod),
  72. ExtraMod = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name]))),
  73. false = cover:is_compiled(ExtraMod).
  74. release_extra_src_dirs(Config) ->
  75. AppDir = ?config(apps, Config),
  76. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  77. Vsn1 = rebar_test_utils:create_random_vsn(),
  78. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  79. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  80. Vsn2 = rebar_test_utils:create_random_vsn(),
  81. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  82. ExtraOne = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name1]),
  83. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name1, "extra", "dummy"])),
  84. ok = file:write_file(filename:join([AppDir, "apps", Name1, "extra",
  85. io_lib:format("~ts_extra.erl", [Name1])]),
  86. ExtraOne),
  87. ExtraTwo = io_lib:format("-module(~ts_extra).\n-export([ok/0]).\nok() -> ok.\n", [Name2]),
  88. ok = filelib:ensure_dir(filename:join([AppDir, "apps", Name2, "extra", "dummy"])),
  89. ok = file:write_file(filename:join([AppDir, "apps", Name2, "extra",
  90. io_lib:format("~ts_extra.erl", [Name2])]),
  91. ExtraTwo),
  92. RebarConfig = [{erl_opts, [{d, some_define}]}, {extra_src_dirs, ["extra"]}],
  93. rebar_test_utils:run_and_check(Config,
  94. RebarConfig,
  95. ["eunit", "--cover"],
  96. {ok, [{app, Name1}, {app, Name2}]}),
  97. Mod1 = list_to_atom(Name1),
  98. {file, _} = cover:is_compiled(Mod1),
  99. Mod2 = list_to_atom(Name2),
  100. {file, _} = cover:is_compiled(Mod2),
  101. ExtraMod1 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name1]))),
  102. false = cover:is_compiled(ExtraMod1),
  103. ExtraMod2 = list_to_atom(lists:flatten(io_lib:format("~ts_extra", [Name2]))),
  104. false = cover:is_compiled(ExtraMod2).
  105. root_extra_src_dirs(Config) ->
  106. AppDir = ?config(apps, Config),
  107. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  108. Vsn1 = rebar_test_utils:create_random_vsn(),
  109. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  110. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  111. Vsn2 = rebar_test_utils:create_random_vsn(),
  112. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  113. Extra = <<"-module(extra).\n-export([ok/0]).\nok() -> ok.\n">>,
  114. ok = filelib:ensure_dir(filename:join([AppDir, "extra", "dummy"])),
  115. ok = file:write_file(filename:join([AppDir, "extra", "extra.erl"]), Extra),
  116. RebarConfig = [{erl_opts, [{d, some_define}]}, {extra_src_dirs, ["extra"]}],
  117. rebar_test_utils:run_and_check(Config,
  118. RebarConfig,
  119. ["eunit", "--cover"],
  120. {ok, [{app, Name1}, {app, Name2}]}),
  121. Mod1 = list_to_atom(Name1),
  122. {file, _} = cover:is_compiled(Mod1),
  123. Mod2 = list_to_atom(Name2),
  124. {file, _} = cover:is_compiled(Mod2),
  125. false = cover:is_compiled(extra).
  126. index_written(Config) ->
  127. AppDir = ?config(apps, Config),
  128. Name = rebar_test_utils:create_random_name("cover_"),
  129. Vsn = rebar_test_utils:create_random_vsn(),
  130. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  131. RebarConfig = [{erl_opts, [{d, some_define}]}],
  132. rebar_test_utils:run_and_check(Config,
  133. RebarConfig,
  134. ["do", "eunit", "--cover", ",", "cover"],
  135. {ok, [{app, Name}]}),
  136. true = filelib:is_file(filename:join([AppDir, "_build", "test", "cover", "index.html"])).
  137. flag_verbose(Config) ->
  138. AppDir = ?config(apps, Config),
  139. Name = rebar_test_utils:create_random_name("cover_"),
  140. Vsn = rebar_test_utils:create_random_vsn(),
  141. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  142. RebarConfig = [{erl_opts, [{d, some_define}]}],
  143. rebar_test_utils:run_and_check(Config,
  144. RebarConfig,
  145. ["do", "eunit", "--cover", ",", "cover", "--verbose"],
  146. {ok, [{app, Name}]}),
  147. true = filelib:is_file(filename:join([AppDir, "_build", "test", "cover", "index.html"])).
  148. config_verbose(Config) ->
  149. AppDir = ?config(apps, Config),
  150. Name = rebar_test_utils:create_random_name("cover_"),
  151. Vsn = rebar_test_utils:create_random_vsn(),
  152. rebar_test_utils:create_eunit_app(AppDir, Name, Vsn, [kernel, stdlib]),
  153. RebarConfig = [{erl_opts, [{d, some_define}]}, {cover_opts, [verbose]}],
  154. rebar_test_utils:run_and_check(Config,
  155. RebarConfig,
  156. ["do", "eunit", "--cover", ",", "cover"],
  157. {ok, [{app, Name}]}),
  158. true = filelib:is_file(filename:join([AppDir, "_build", "test", "cover", "index.html"])).
  159. excl_mods(Config) ->
  160. AppDir = ?config(apps, Config),
  161. Name1 = rebar_test_utils:create_random_name("relapp1_"),
  162. Vsn1 = rebar_test_utils:create_random_vsn(),
  163. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name1]), Name1, Vsn1, [kernel, stdlib]),
  164. Name2 = rebar_test_utils:create_random_name("relapp2_"),
  165. Vsn2 = rebar_test_utils:create_random_vsn(),
  166. rebar_test_utils:create_app(filename:join([AppDir, "apps", Name2]), Name2, Vsn2, [kernel, stdlib]),
  167. Mod1 = list_to_atom(Name1),
  168. Mod2 = list_to_atom(Name2),
  169. RebarConfig = [{erl_opts, [{d, some_define}]},
  170. {cover_excl_mods, [Mod2]}],
  171. rebar_test_utils:run_and_check(Config,
  172. RebarConfig,
  173. ["eunit", "--cover"],
  174. {ok, [{app, Name1}, {app, Name2}]}),
  175. {file, _} = cover:is_compiled(Mod1),
  176. false = cover:is_compiled(Mod2).