plugin_cover.mk 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # Common Test plugin.
  2. COVER_CASES = ct custom-dir eunit 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-report-and-merge: build clean
  91. $i "Bootstrap a new OTP application named $(APP)"
  92. $t mkdir $(APP)/
  93. $t cp ../erlang.mk $(APP)/
  94. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  95. $i "Generate a Common Test suite"
  96. $t mkdir $(APP)/test
  97. $t printf "%s\n" \
  98. "-module($(APP)_SUITE)." \
  99. "-export([all/0, ok/1])." \
  100. "all() -> [ok]." \
  101. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  102. $i "Generate a module containing EUnit tests"
  103. $t printf "%s\n" \
  104. "-module($(APP))." \
  105. "-ifdef(TEST)." \
  106. "-include_lib(\"eunit/include/eunit.hrl\")." \
  107. "ok_test() -> ok." \
  108. "-endif." > $(APP)/src/$(APP).erl
  109. $i "Run tests with code coverage enabled"
  110. $t $(MAKE) -C $(APP) tests COVER=1 $v
  111. $i "Check that the generated files exist"
  112. $t test -f $(APP)/cover/$(APP).COVER.html
  113. $t test -f $(APP)/cover/index.html
  114. $t test -f $(APP)/ct.coverdata
  115. $t test -f $(APP)/eunit.coverdata
  116. $t test -f $(APP)/test/ct.cover.spec
  117. $i "Merge coverdata files into all.coverdata"
  118. $t $(MAKE) -C $(APP) all.coverdata $v
  119. $t test -f $(APP)/all.coverdata
  120. $i "Check that the generated files are removed on clean"
  121. $t $(MAKE) -C $(APP) clean $v
  122. $t test ! -e $(APP)/all.coverdata
  123. $t test ! -e $(APP)/ct.coverdata
  124. $t test ! -e $(APP)/eunit.coverdata
  125. $t test ! -e $(APP)/test/ct.cover.spec
  126. $i "Check that the cover report is removed on distclean"
  127. $t $(MAKE) -C $(APP) distclean $v
  128. $t test ! -e $(APP)/cover/