plugin_cover.mk 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # Common Test plugin.
  2. COVER_CASES = ct 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-eunit: 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 "Generate a module containing EUnit tests"
  33. $t printf "%s\n" \
  34. "-module($(APP))." \
  35. "-ifdef(TEST)." \
  36. "-include_lib(\"eunit/include/eunit.hrl\")." \
  37. "ok_test() -> ok." \
  38. "-endif." > $(APP)/src/$(APP).erl
  39. $i "Run EUnit with code coverage enabled"
  40. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  41. $i "Check that the generated file exists"
  42. $t test -f $(APP)/eunit.coverdata
  43. $i "Check that the generated file is removed on clean"
  44. $t $(MAKE) -C $(APP) clean $v
  45. $t test ! -e $(APP)/eunit.coverdata
  46. cover-report-and-merge: build clean
  47. $i "Bootstrap a new OTP application named $(APP)"
  48. $t mkdir $(APP)/
  49. $t cp ../erlang.mk $(APP)/
  50. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  51. $i "Generate a Common Test suite"
  52. $t mkdir $(APP)/test
  53. $t printf "%s\n" \
  54. "-module($(APP)_SUITE)." \
  55. "-export([all/0, ok/1])." \
  56. "all() -> [ok]." \
  57. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  58. $i "Generate a module containing EUnit tests"
  59. $t printf "%s\n" \
  60. "-module($(APP))." \
  61. "-ifdef(TEST)." \
  62. "-include_lib(\"eunit/include/eunit.hrl\")." \
  63. "ok_test() -> ok." \
  64. "-endif." > $(APP)/src/$(APP).erl
  65. $i "Run tests with code coverage enabled"
  66. $t $(MAKE) -C $(APP) tests COVER=1 $v
  67. $i "Check that the generated files exist"
  68. $t test -f $(APP)/cover/$(APP).COVER.html
  69. $t test -f $(APP)/cover/index.html
  70. $t test -f $(APP)/ct.coverdata
  71. $t test -f $(APP)/eunit.coverdata
  72. $t test -f $(APP)/test/ct.cover.spec
  73. $i "Merge coverdata files into all.coverdata"
  74. $t $(MAKE) -C $(APP) all.coverdata $v
  75. $t test -f $(APP)/all.coverdata
  76. $i "Check that the generated files are removed on clean"
  77. $t $(MAKE) -C $(APP) clean $v
  78. $t test ! -e $(APP)/all.coverdata
  79. $t test ! -e $(APP)/ct.coverdata
  80. $t test ! -e $(APP)/eunit.coverdata
  81. $t test ! -e $(APP)/test/ct.cover.spec
  82. $i "Check that the cover report is removed on distclean"
  83. $t $(MAKE) -C $(APP) distclean $v
  84. $t test ! -e $(APP)/cover/