plugin_cover.mk 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. # Common Test plugin.
  2. COVER_TARGETS = $(call list_targets,cover)
  3. .PHONY: cover $(COVER_TARGETS)
  4. cover: $(COVER_TARGETS)
  5. cover-ct: build clean
  6. $i "Bootstrap a new OTP application named $(APP)"
  7. $t mkdir $(APP)/
  8. $t cp ../erlang.mk $(APP)/
  9. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  10. $i "Generate a Common Test suite"
  11. $t mkdir $(APP)/test
  12. $t printf "%s\n" \
  13. "-module($(APP)_SUITE)." \
  14. "-export([all/0, ok/1])." \
  15. "all() -> [ok]." \
  16. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  17. $i "Run Common Test with code coverage enabled"
  18. $t $(MAKE) -C $(APP) ct COVER=1 $v
  19. $i "Check that the generated files exist"
  20. $t test -f $(APP)/ct.coverdata
  21. $t test -f $(APP)/test/ct.cover.spec
  22. $i "Check that the generated files are removed on clean"
  23. $t $(MAKE) -C $(APP) clean $v
  24. $t test ! -e $(APP)/ct.coverdata
  25. $t test ! -e $(APP)/test/ct.cover.spec
  26. cover-custom-dir: build clean
  27. $i "Bootstrap a new OTP application named $(APP)"
  28. $t mkdir $(APP)/
  29. $t cp ../erlang.mk $(APP)/
  30. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  31. $i "Set COVER_DATA_DIR in the Makefile"
  32. $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DATA_DIR = custom_dir\n"}' $(APP)/Makefile
  33. $i "Generate a module containing EUnit tests"
  34. $t printf "%s\n" \
  35. "-module($(APP))." \
  36. "-ifdef(TEST)." \
  37. "-include_lib(\"eunit/include/eunit.hrl\")." \
  38. "ok_test() -> ok." \
  39. "-endif." > $(APP)/src/$(APP).erl
  40. $i "Generate a Common Test suite"
  41. $t mkdir $(APP)/test
  42. $t printf "%s\n" \
  43. "-module($(APP)_SUITE)." \
  44. "-export([all/0, ok/1])." \
  45. "all() -> [ok]." \
  46. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  47. $i "Run Common Test with code coverage enabled"
  48. $t $(MAKE) -C $(APP) ct COVER=1 $v
  49. $i "Run EUnit with code coverage enabled"
  50. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  51. $i "Check that the generated file exists"
  52. $t test -f $(APP)/custom_dir/ct.coverdata
  53. $t test -f $(APP)/custom_dir/eunit.coverdata
  54. $i "Merge coverdata files into all.coverdata"
  55. $t $(MAKE) -C $(APP) all.coverdata $v
  56. $t test -f $(APP)/custom_dir/all.coverdata
  57. $i "Check that the generated file is removed on clean"
  58. $t $(MAKE) -C $(APP) clean $v
  59. $t test ! -e $(APP)/custom_dir/eunit.coverdata
  60. $t test ! -e $(APP)/custom_dir/ct.coverdata
  61. $t test ! -e $(APP)/custom_dir/all.coverdata
  62. $i "Check that the custom dir is removed on distclean"
  63. $t $(MAKE) -C $(APP) distclean $v
  64. $t test ! -e $(APP)/custom_dir/
  65. $i "Check that the custom dir is not removed if not empty"
  66. $t mkdir $(APP)/custom_dir
  67. $t touch $(APP)/custom_dir/file
  68. $t $(MAKE) -C $(APP) distclean $v
  69. $t test -f $(APP)/custom_dir/file
  70. cover-eunit: build clean
  71. $i "Bootstrap a new OTP application named $(APP)"
  72. $t mkdir $(APP)/
  73. $t cp ../erlang.mk $(APP)/
  74. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  75. $i "Generate a module containing EUnit tests"
  76. $t printf "%s\n" \
  77. "-module($(APP))." \
  78. "-ifdef(TEST)." \
  79. "-include_lib(\"eunit/include/eunit.hrl\")." \
  80. "ok_test() -> ok." \
  81. "-endif." > $(APP)/src/$(APP).erl
  82. $i "Run EUnit with code coverage enabled"
  83. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  84. $i "Check that the generated file exists"
  85. $t test -f $(APP)/eunit.coverdata
  86. $i "Check that the generated file is removed on clean"
  87. $t $(MAKE) -C $(APP) clean $v
  88. $t test ! -e $(APP)/eunit.coverdata
  89. cover-eunit-apps-only: build clean
  90. $i "Create a multi application repository with no root application"
  91. $t mkdir $(APP)/
  92. $t cp ../erlang.mk $(APP)/
  93. $t echo "include erlang.mk" > $(APP)/Makefile
  94. $i "Create a new application named my_app"
  95. $t $(MAKE) -C $(APP) new-app in=my_app $v
  96. $i "Generate a module containing EUnit tests in my_app"
  97. $t printf "%s\n" \
  98. "-module(my_app)." \
  99. "-ifdef(TEST)." \
  100. "-include_lib(\"eunit/include/eunit.hrl\")." \
  101. "ok_test() -> ok." \
  102. "-endif." > $(APP)/apps/my_app/src/my_app.erl
  103. $i "Run EUnit with code coverage enabled"
  104. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  105. $i "Check that no file was generated in the top-level directory"
  106. $t ! test -f $(APP)/eunit.coverdata
  107. $i "Check that the generated file exists"
  108. $t test -f $(APP)/apps/my_app/eunit.coverdata
  109. cover-report-and-merge: build clean
  110. $i "Bootstrap a new OTP application named $(APP)"
  111. $t mkdir $(APP)/
  112. $t cp ../erlang.mk $(APP)/
  113. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  114. $i "Generate a Common Test suite"
  115. $t mkdir $(APP)/test
  116. $t printf "%s\n" \
  117. "-module($(APP)_SUITE)." \
  118. "-export([all/0, ok/1])." \
  119. "all() -> [ok]." \
  120. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  121. $i "Generate a module containing EUnit tests"
  122. $t printf "%s\n" \
  123. "-module($(APP))." \
  124. "-ifdef(TEST)." \
  125. "-include_lib(\"eunit/include/eunit.hrl\")." \
  126. "ok_test() -> ok." \
  127. "-endif." > $(APP)/src/$(APP).erl
  128. $i "Run tests with code coverage enabled"
  129. $t $(MAKE) -C $(APP) tests COVER=1 $v
  130. $i "Check that the generated files exist"
  131. $t test -f $(APP)/cover/$(APP).COVER.html
  132. $t test -f $(APP)/cover/index.html
  133. $t test -f $(APP)/ct.coverdata
  134. $t test -f $(APP)/eunit.coverdata
  135. $t test -f $(APP)/test/ct.cover.spec
  136. $i "Merge coverdata files into all.coverdata"
  137. $t $(MAKE) -C $(APP) all.coverdata $v
  138. $t test -f $(APP)/all.coverdata
  139. $i "Check that the generated files are removed on clean"
  140. $t $(MAKE) -C $(APP) clean $v
  141. $t test ! -e $(APP)/all.coverdata
  142. $t test ! -e $(APP)/ct.coverdata
  143. $t test ! -e $(APP)/eunit.coverdata
  144. $t test ! -e $(APP)/test/ct.cover.spec
  145. $i "Check that the cover report is removed on distclean"
  146. $t $(MAKE) -C $(APP) distclean $v
  147. $t test ! -e $(APP)/cover/