plugin_ct.mk 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. # Common Test plugin.
  2. CT_CASES = all apps-only case check group opts suite tests
  3. CT_TARGETS = $(addprefix ct-,$(CT_CASES))
  4. .PHONY: ct $(CT_TARGETS)
  5. ct: $(CT_TARGETS)
  6. ct-all: 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 $v
  11. $i "Check that Common Test detects no tests"
  12. $t $(MAKE) -C $(APP) ct | grep -q "Nothing to be done for 'ct'."
  13. $i "Generate a Common Test suite"
  14. $t mkdir $(APP)/test
  15. $t printf "%s\n" \
  16. "-module($(APP)_SUITE)." \
  17. "-export([all/0, ok/1])." \
  18. "all() -> [ok]." \
  19. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  20. $i "Check that Common Test runs tests"
  21. # We can't pipe CT's output without it crashing, so let's check that
  22. # the command succeeds and log files are created instead.
  23. $t test ! -e $(APP)/logs/index.html
  24. $t $(MAKE) -C $(APP) ct $v
  25. $t test -f $(APP)/logs/index.html
  26. $i "Generate a Common Test suite with a failing test case"
  27. $t printf "%s\n" \
  28. "-module($(APP)_fail_SUITE)." \
  29. "-export([all/0, fail/1])." \
  30. "all() -> [fail]." \
  31. "fail(_) -> throw(fail)." > $(APP)/test/$(APP)_fail_SUITE.erl
  32. $i "Check that Common Test errors out"
  33. $t ! $(MAKE) -C $(APP) ct $v
  34. $i "Check that logs are kept on clean"
  35. $t $(MAKE) -C $(APP) clean $v
  36. $t test -f $(APP)/logs/index.html
  37. $i "Check that logs are deleted on distclean"
  38. $t $(MAKE) -C $(APP) distclean $v
  39. $t test ! -e $(APP)/logs/index.html
  40. ct-apps-only: build clean
  41. $i "Create a multi application repository with no root application"
  42. $t mkdir $(APP)/
  43. $t cp ../erlang.mk $(APP)/
  44. $t echo "include erlang.mk" > $(APP)/Makefile
  45. $i "Create a new application named my_app"
  46. $t $(MAKE) -C $(APP) new-app in=my_app $v
  47. $i "Create a new library named my_lib"
  48. $t $(MAKE) -C $(APP) new-lib in=my_lib $v
  49. $i "Populate my_lib"
  50. $t printf "%s\n" \
  51. "-module(my_lib)." \
  52. "-export([random_int/0])." \
  53. "random_int() -> 4." > $(APP)/apps/my_lib/src/my_lib.erl
  54. $i "Check that Common Test detects no tests"
  55. $t $(MAKE) -C $(APP) ct | grep -q "Nothing to be done for 'ct'."
  56. $i "Generate a Common Test suite in my_app"
  57. $t mkdir $(APP)/apps/my_app/test
  58. $t printf "%s\n" \
  59. "-module(my_app_SUITE)." \
  60. "-export([all/0, ok/1, call_my_lib/1])." \
  61. "all() -> [ok, call_my_lib]." \
  62. "ok(_) -> ok." \
  63. "call_my_lib(_) -> 4 = my_lib:random_int()." > $(APP)/apps/my_app/test/my_app_SUITE.erl
  64. $i "Generate a Common Test suite in my_lib"
  65. $t mkdir $(APP)/apps/my_lib/test
  66. $t printf "%s\n" \
  67. "-module(my_lib_SUITE)." \
  68. "-export([all/0, ok/1])." \
  69. "all() -> [ok]." \
  70. "ok(_) -> ok." > $(APP)/apps/my_lib/test/my_lib_SUITE.erl
  71. $i "Check that Common Test runs tests"
  72. # We can't pipe CT's output without it crashing, so let's check that
  73. # the command succeeds and log files are created instead.
  74. $t test ! -e $(APP)/apps/my_app/logs/index.html
  75. $t test ! -e $(APP)/apps/my_lib/logs/index.html
  76. $t $(MAKE) -C $(APP) ct $v
  77. $t test -f $(APP)/apps/my_app/logs/index.html
  78. $t test -f $(APP)/apps/my_lib/logs/index.html
  79. ct-case: build clean
  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 Common Test suite with two cases"
  85. $t mkdir $(APP)/test
  86. $t printf "%s\n" \
  87. "-module($(APP)_SUITE)." \
  88. "-export([all/0, groups/0, ok/1, bad/1])." \
  89. "all() -> [{group, mygroup}]." \
  90. "groups() -> [{mygroup, [ok, bad]}]." \
  91. "ok(_) -> ok." \
  92. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  93. $i "Check that we can run Common Test on a specific test case"
  94. $t $(MAKE) -C $(APP) ct-$(APP) t=mygroup:ok $v
  95. ct-check: build clean
  96. $i "Bootstrap a new OTP application named $(APP)"
  97. $t mkdir $(APP)/
  98. $t cp ../erlang.mk $(APP)/
  99. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  100. $i "Generate a Common Test suite"
  101. $t mkdir $(APP)/test
  102. $t printf "%s\n" \
  103. "-module($(APP)_SUITE)." \
  104. "-export([all/0, ok/1])." \
  105. "all() -> [ok]." \
  106. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  107. $i "Check that Common Test runs on 'make check'"
  108. $t test ! -e $(APP)/logs/index.html
  109. $t $(MAKE) -C $(APP) check $v
  110. $t test -f $(APP)/logs/index.html
  111. ct-group: build clean
  112. $i "Bootstrap a new OTP application named $(APP)"
  113. $t mkdir $(APP)/
  114. $t cp ../erlang.mk $(APP)/
  115. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  116. $i "Generate a Common Test suite with two groups"
  117. $t mkdir $(APP)/test
  118. $t printf "%s\n" \
  119. "-module($(APP)_SUITE)." \
  120. "-export([all/0, groups/0, ok/1, bad/1])." \
  121. "all() -> [{group, okgroup}, {group, badgroup}]." \
  122. "groups() -> [{okgroup, [ok]}, {badgroup, [bad]}]." \
  123. "ok(_) -> ok." \
  124. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  125. $i "Check that we can run Common Test on a specific group"
  126. $t $(MAKE) -C $(APP) ct-$(APP) t=okgroup $v
  127. ct-opts: build clean
  128. $i "Bootstrap a new OTP application named $(APP)"
  129. $t mkdir $(APP)/
  130. $t cp ../erlang.mk $(APP)/
  131. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  132. $i "Set CT_OPTS in the Makefile"
  133. $t perl -ni.bak -e 'print;if ($$.==1) {print "CT_OPTS = -label hello_ct_opts\n"}' $(APP)/Makefile
  134. $i "Generate a Common Test suite"
  135. $t mkdir $(APP)/test
  136. $t printf "%s\n" \
  137. "-module($(APP)_SUITE)." \
  138. "-export([all/0, ok/1])." \
  139. "all() -> [ok]." \
  140. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  141. $i "Run Common Test"
  142. $t $(MAKE) -C $(APP) ct $v
  143. $i "Check that Common Test uses options from CT_OPTS"
  144. $t grep -q hello_ct_opts $(APP)/logs/index.html
  145. ct-suite: build clean
  146. $i "Bootstrap a new OTP application named $(APP)"
  147. $t mkdir $(APP)/
  148. $t cp ../erlang.mk $(APP)/
  149. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  150. $i "Generate two Common Test suites"
  151. $t mkdir $(APP)/test
  152. $t printf "%s\n" \
  153. "-module($(APP)_ok_SUITE)." \
  154. "-export([all/0, ok/1])." \
  155. "all() -> [ok]." \
  156. "ok(_) -> ok." > $(APP)/test/$(APP)_ok_SUITE.erl
  157. $t printf "%s\n" \
  158. "-module($(APP)_fail_SUITE)." \
  159. "-export([all/0, bad/1])." \
  160. "all() -> [bad]." \
  161. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_fail_SUITE.erl
  162. $i "Check that we can run Common Test on a specific test suite"
  163. $t $(MAKE) -C $(APP) ct-$(APP)_ok $v
  164. ct-tests: build clean
  165. $i "Bootstrap a new OTP application named $(APP)"
  166. $t mkdir $(APP)/
  167. $t cp ../erlang.mk $(APP)/
  168. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  169. $i "Generate a Common Test suite"
  170. $t mkdir $(APP)/test
  171. $t printf "%s\n" \
  172. "-module($(APP)_SUITE)." \
  173. "-export([all/0, ok/1])." \
  174. "all() -> [ok]." \
  175. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  176. $i "Check that Common Test runs on 'make tests'"
  177. $t test ! -e $(APP)/logs/index.html
  178. $t $(MAKE) -C $(APP) tests $v
  179. $t test -f $(APP)/logs/index.html