plugin_cover.mk 5.4 KB

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