plugin_cover.mk 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. cover-eunit: build clean
  67. $i "Bootstrap a new OTP application named $(APP)"
  68. $t mkdir $(APP)/
  69. $t cp ../erlang.mk $(APP)/
  70. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  71. $i "Generate a module containing EUnit tests"
  72. $t printf "%s\n" \
  73. "-module($(APP))." \
  74. "-ifdef(TEST)." \
  75. "-include_lib(\"eunit/include/eunit.hrl\")." \
  76. "ok_test() -> ok." \
  77. "-endif." > $(APP)/src/$(APP).erl
  78. $i "Run EUnit with code coverage enabled"
  79. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  80. $i "Check that the generated file exists"
  81. $t test -f $(APP)/eunit.coverdata
  82. $i "Check that the generated file is removed on clean"
  83. $t $(MAKE) -C $(APP) clean $v
  84. $t test ! -e $(APP)/eunit.coverdata
  85. cover-report-and-merge: build clean
  86. $i "Bootstrap a new OTP application named $(APP)"
  87. $t mkdir $(APP)/
  88. $t cp ../erlang.mk $(APP)/
  89. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  90. $i "Generate a Common Test suite"
  91. $t mkdir $(APP)/test
  92. $t printf "%s\n" \
  93. "-module($(APP)_SUITE)." \
  94. "-export([all/0, ok/1])." \
  95. "all() -> [ok]." \
  96. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  97. $i "Generate a module containing EUnit tests"
  98. $t printf "%s\n" \
  99. "-module($(APP))." \
  100. "-ifdef(TEST)." \
  101. "-include_lib(\"eunit/include/eunit.hrl\")." \
  102. "ok_test() -> ok." \
  103. "-endif." > $(APP)/src/$(APP).erl
  104. $i "Run tests with code coverage enabled"
  105. $t $(MAKE) -C $(APP) tests COVER=1 $v
  106. $i "Check that the generated files exist"
  107. $t test -f $(APP)/cover/$(APP).COVER.html
  108. $t test -f $(APP)/cover/index.html
  109. $t test -f $(APP)/ct.coverdata
  110. $t test -f $(APP)/eunit.coverdata
  111. $t test -f $(APP)/test/ct.cover.spec
  112. $i "Merge coverdata files into all.coverdata"
  113. $t $(MAKE) -C $(APP) all.coverdata $v
  114. $t test -f $(APP)/all.coverdata
  115. $i "Check that the generated files are removed on clean"
  116. $t $(MAKE) -C $(APP) clean $v
  117. $t test ! -e $(APP)/all.coverdata
  118. $t test ! -e $(APP)/ct.coverdata
  119. $t test ! -e $(APP)/eunit.coverdata
  120. $t test ! -e $(APP)/test/ct.cover.spec
  121. $i "Check that the cover report is removed on distclean"
  122. $t $(MAKE) -C $(APP) distclean $v
  123. $t test ! -e $(APP)/cover/