Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

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