plugin_eunit.mk 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # EUnit plugin.
  2. EUNIT_CASES = all apps-only check fun mod test-dir tests
  3. EUNIT_TARGETS = $(addprefix eunit-,$(EUNIT_CASES))
  4. EUNIT_CLEAN_TARGETS = $(addprefix clean-,$(EUNIT_TARGETS))
  5. .PHONY: eunit $(EUNIT_TARGETS) clean-eunit $(EUNIT_CLEAN_TARGETS)
  6. clean-eunit: $(EUNIT_CLEAN_TARGETS)
  7. $(EUNIT_CLEAN_TARGETS):
  8. $t rm -rf $(APP_TO_CLEAN)
  9. eunit: $(EUNIT_TARGETS)
  10. eunit-all: build clean-eunit-all
  11. $i "Bootstrap a new OTP application named $(APP)"
  12. $t mkdir $(APP)/
  13. $t cp ../erlang.mk $(APP)/
  14. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  15. $i "Check that EUnit detects no tests"
  16. $t $(MAKE) -C $(APP) eunit | grep -q "There were no tests to run."
  17. $i "Generate a module containing EUnit tests"
  18. $t printf "%s\n" \
  19. "-module($(APP))." \
  20. "-ifdef(TEST)." \
  21. "-include_lib(\"eunit/include/eunit.hrl\")." \
  22. "ok_test() -> ok." \
  23. "-endif." > $(APP)/src/$(APP).erl
  24. $i "Build the project cleanly"
  25. $t $(MAKE) -C $(APP) clean $v
  26. $t $(MAKE) -C $(APP) $v
  27. $i "Check that no EUnit test cases were exported"
  28. $t $(ERL) -pa $(APP)/ebin -eval 'code:load_file($(APP)), false = erlang:function_exported($(APP), ok_test, 0), halt()'
  29. $i "Check that EUnit runs tests"
  30. $t $(MAKE) -C $(APP) eunit | grep -q "Test passed."
  31. $i "Add a failing test to the module"
  32. $t printf "%s\n" \
  33. "-ifdef(TEST)." \
  34. "bad_test() -> throw(fail)." \
  35. "-endif." >> $(APP)/src/$(APP).erl
  36. $i "Check that EUnit errors out"
  37. $t ! $(MAKE) -C $(APP) eunit $v
  38. eunit-apps-only: build clean-eunit-apps-only
  39. $i "Create a multi application repository with no root application"
  40. $t mkdir $(APP)/
  41. $t cp ../erlang.mk $(APP)/
  42. $t echo "include erlang.mk" > $(APP)/Makefile
  43. $i "Create a new application named my_app"
  44. $t $(MAKE) -C $(APP) new-app in=my_app $v
  45. $i "Create a new library named my_lib"
  46. $t $(MAKE) -C $(APP) new-lib in=my_lib $v
  47. $i "Check that EUnit detects no tests"
  48. $t $(MAKE) -C $(APP) eunit | grep -q "There were no tests to run."
  49. $i "Generate a module containing EUnit tests in my_app"
  50. $t printf "%s\n" \
  51. "-module(my_app)." \
  52. "-ifdef(TEST)." \
  53. "-include_lib(\"eunit/include/eunit.hrl\")." \
  54. "ok_test() -> ok." \
  55. "-endif." > $(APP)/apps/my_app/src/my_app.erl
  56. $i "Generate a module containing EUnit tests in my_lib"
  57. $t printf "%s\n" \
  58. "-module(my_lib)." \
  59. "-ifdef(TEST)." \
  60. "-include_lib(\"eunit/include/eunit.hrl\")." \
  61. "ok_test() -> ok." \
  62. "-endif." > $(APP)/apps/my_lib/src/my_lib.erl
  63. $i "Check that EUnit runs tests"
  64. $t $(MAKE) -C $(APP) eunit | grep -q "Test passed."
  65. eunit-check: build clean-eunit-check
  66. $i "Bootstrap a new OTP application named $(APP)"
  67. $t mkdir $(APP)/
  68. $t cp ../erlang.mk $(APP)/
  69. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  70. $i "Generate a module containing EUnit tests"
  71. $t printf "%s\n" \
  72. "-module($(APP))." \
  73. "-ifdef(TEST)." \
  74. "-include_lib(\"eunit/include/eunit.hrl\")." \
  75. "ok_test() -> ok." \
  76. "-endif." > $(APP)/src/$(APP).erl
  77. $i "Check that EUnit runs on 'make check'"
  78. $t $(MAKE) -C $(APP) check | grep -q "Test passed."
  79. eunit-fun: build clean-eunit-fun
  80. $i "Bootstrap a new OTP application named $(APP)"
  81. $t mkdir $(APP)/
  82. $t cp ../erlang.mk $(APP)/
  83. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  84. $i "Generate a module containing EUnit tests"
  85. $t printf "%s\n" \
  86. "-module($(APP))." \
  87. "-ifdef(TEST)." \
  88. "-include_lib(\"eunit/include/eunit.hrl\")." \
  89. "ok_test() -> ok." \
  90. "bad_test() -> throw(fail)." \
  91. "-endif." > $(APP)/src/$(APP).erl
  92. $i "Check that we can run EUnit on a specific test"
  93. $t $(MAKE) -C $(APP) eunit t=$(APP):ok_test $v
  94. eunit-mod: build clean-eunit-mod
  95. $i "Bootstrap a new OTP application named $(APP)"
  96. $t mkdir $(APP)/
  97. $t cp ../erlang.mk $(APP)/
  98. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  99. $i "Generate a module containing EUnit tests"
  100. $t printf "%s\n" \
  101. "-module($(APP))." \
  102. "-ifdef(TEST)." \
  103. "-include_lib(\"eunit/include/eunit.hrl\")." \
  104. "ok_test() -> ok." \
  105. "-endif." > $(APP)/src/$(APP).erl
  106. $i "Generate a module containing failing EUnit tests"
  107. $t printf "%s\n" \
  108. "-module($(APP)_fail)." \
  109. "-ifdef(TEST)." \
  110. "-include_lib(\"eunit/include/eunit.hrl\")." \
  111. "bad_test() -> throw(fail)." \
  112. "-endif." > $(APP)/src/$(APP)_fail.erl
  113. $i "Check that we can run EUnit on a specific module"
  114. $t $(MAKE) -C $(APP) eunit t=$(APP) $v
  115. eunit-test-dir: build clean-eunit-test-dir
  116. $i "Bootstrap a new OTP application named $(APP)"
  117. $t mkdir $(APP)/
  118. $t cp ../erlang.mk $(APP)/
  119. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  120. $i "Generate a module containing EUnit tests"
  121. $t printf "%s\n" \
  122. "-module($(APP))." \
  123. "-ifdef(TEST)." \
  124. "-include_lib(\"eunit/include/eunit.hrl\")." \
  125. "log_test() -> os:cmd(\"echo $(APP) >> eunit.log\")." \
  126. "-endif." > $(APP)/src/$(APP).erl
  127. $i "Generate a module containing EUnit tests in TEST_DIR"
  128. $t mkdir $(APP)/test
  129. $t printf "%s\n" \
  130. "-module($(APP)_tests)." \
  131. "-include_lib(\"eunit/include/eunit.hrl\")." \
  132. "log_test() -> os:cmd(\"echo $(APP)_tests >> eunit.log\")." > $(APP)/test/$(APP)_tests.erl
  133. $i "Check that EUnit runs both tests"
  134. $t $(MAKE) -C $(APP) eunit | grep -q "2 tests passed."
  135. $i "Check that tests were both run only once"
  136. $t printf "%s\n" $(APP) $(APP)_tests | cmp $(APP)/eunit.log -
  137. eunit-tests: build clean-eunit-tests
  138. $i "Bootstrap a new OTP application named $(APP)"
  139. $t mkdir $(APP)/
  140. $t cp ../erlang.mk $(APP)/
  141. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  142. $i "Generate a module containing EUnit tests"
  143. $t printf "%s\n" \
  144. "-module($(APP))." \
  145. "-ifdef(TEST)." \
  146. "-include_lib(\"eunit/include/eunit.hrl\")." \
  147. "ok_test() -> ok." \
  148. "-endif." > $(APP)/src/$(APP).erl
  149. $i "Check that EUnit runs on 'make tests'"
  150. $t $(MAKE) -C $(APP) tests | grep -q "Test passed."