plugin_ct.mk 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. # Common Test plugin.
  2. CT_CASES = all apps apps-only case check group logs-dir 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: build clean
  41. $i "Create a multi application repository with 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 library named my_lib"
  46. $t $(MAKE) -C $(APP) new-lib in=my_lib $v
  47. $i "Populate my_lib"
  48. $t printf "%s\n" \
  49. "-module(my_lib)." \
  50. "-export([random_int/0])." \
  51. "random_int() -> 4." > $(APP)/apps/my_lib/src/my_lib.erl
  52. $i "Generate a Common Test suite in root application"
  53. $t mkdir $(APP)/test
  54. $t printf "%s\n" \
  55. "-module(my_root_SUITE)." \
  56. "-export([all/0, ok/1, call_my_lib/1])." \
  57. "all() -> [ok, call_my_lib]." \
  58. "ok(_) -> ok." \
  59. "call_my_lib(_) -> 4 = my_lib:random_int()." > $(APP)/test/my_root_SUITE.erl
  60. $i "Check that Common Test runs tests"
  61. $t $(MAKE) -C $(APP) ct $v
  62. $i "Check that Common Test runs tests from a specific test suite"
  63. $t $(MAKE) -C $(APP) ct CT_SUITES=my_root $v
  64. ct-apps-only: build clean
  65. $i "Create a multi application repository with no root application"
  66. $t mkdir $(APP)/
  67. $t cp ../erlang.mk $(APP)/
  68. $t echo "include erlang.mk" > $(APP)/Makefile
  69. $i "Create a new application named my_app"
  70. $t $(MAKE) -C $(APP) new-app in=my_app $v
  71. $i "Create a new library named my_lib"
  72. $t $(MAKE) -C $(APP) new-lib in=my_lib $v
  73. $i "Populate my_lib"
  74. $t printf "%s\n" \
  75. "-module(my_lib)." \
  76. "-export([random_int/0])." \
  77. "random_int() -> 4." > $(APP)/apps/my_lib/src/my_lib.erl
  78. $i "Check that Common Test detects no tests"
  79. $t $(MAKE) -C $(APP) ct | grep -q "Nothing to be done for 'ct'."
  80. $i "Generate a Common Test suite in my_app"
  81. $t mkdir $(APP)/apps/my_app/test
  82. $t printf "%s\n" \
  83. "-module(my_app_SUITE)." \
  84. "-export([all/0, ok/1, call_my_lib/1])." \
  85. "all() -> [ok, call_my_lib]." \
  86. "ok(_) -> ok." \
  87. "call_my_lib(_) -> 4 = my_lib:random_int()." > $(APP)/apps/my_app/test/my_app_SUITE.erl
  88. $i "Generate a Common Test suite in my_lib"
  89. $t mkdir $(APP)/apps/my_lib/test
  90. $t printf "%s\n" \
  91. "-module(my_lib_SUITE)." \
  92. "-export([all/0, ok/1])." \
  93. "all() -> [ok]." \
  94. "ok(_) -> ok." > $(APP)/apps/my_lib/test/my_lib_SUITE.erl
  95. $i "Check that Common Test runs tests"
  96. # We can't pipe CT's output without it crashing, so let's check that
  97. # the command succeeds and log files are created instead.
  98. $t test ! -e $(APP)/apps/my_app/logs/index.html
  99. $t test ! -e $(APP)/apps/my_lib/logs/index.html
  100. $t $(MAKE) -C $(APP) ct $v
  101. $t test -f $(APP)/apps/my_app/logs/index.html
  102. $t test -f $(APP)/apps/my_lib/logs/index.html
  103. ct-case: build clean
  104. $i "Bootstrap a new OTP application named $(APP)"
  105. $t mkdir $(APP)/
  106. $t cp ../erlang.mk $(APP)/
  107. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  108. $i "Generate a Common Test suite with two cases"
  109. $t mkdir $(APP)/test
  110. $t printf "%s\n" \
  111. "-module($(APP)_SUITE)." \
  112. "-export([all/0, groups/0, ok/1, bad/1])." \
  113. "all() -> [{group, mygroup}]." \
  114. "groups() -> [{mygroup, [ok, bad]}]." \
  115. "ok(_) -> ok." \
  116. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  117. $i "Check that we can run Common Test on a specific test case"
  118. $t $(MAKE) -C $(APP) ct-$(APP) t=mygroup:ok $v
  119. ct-check: build clean
  120. $i "Bootstrap a new OTP application named $(APP)"
  121. $t mkdir $(APP)/
  122. $t cp ../erlang.mk $(APP)/
  123. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  124. $i "Generate a Common Test suite"
  125. $t mkdir $(APP)/test
  126. $t printf "%s\n" \
  127. "-module($(APP)_SUITE)." \
  128. "-export([all/0, ok/1])." \
  129. "all() -> [ok]." \
  130. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  131. $i "Check that Common Test runs on 'make check'"
  132. $t test ! -e $(APP)/logs/index.html
  133. $t $(MAKE) -C $(APP) check $v
  134. $t test -f $(APP)/logs/index.html
  135. ct-group: build clean
  136. $i "Bootstrap a new OTP application named $(APP)"
  137. $t mkdir $(APP)/
  138. $t cp ../erlang.mk $(APP)/
  139. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  140. $i "Generate a Common Test suite with two groups"
  141. $t mkdir $(APP)/test
  142. $t printf "%s\n" \
  143. "-module($(APP)_SUITE)." \
  144. "-export([all/0, groups/0, ok/1, bad/1])." \
  145. "all() -> [{group, okgroup}, {group, badgroup}]." \
  146. "groups() -> [{okgroup, [ok]}, {badgroup, [bad]}]." \
  147. "ok(_) -> ok." \
  148. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  149. $i "Check that we can run Common Test on a specific group"
  150. $t $(MAKE) -C $(APP) ct-$(APP) t=okgroup $v
  151. ct-opts: build clean
  152. $i "Bootstrap a new OTP application named $(APP)"
  153. $t mkdir $(APP)/
  154. $t cp ../erlang.mk $(APP)/
  155. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  156. $i "Set CT_OPTS in the Makefile"
  157. $t perl -ni.bak -e 'print;if ($$.==1) {print "CT_OPTS = -label hello_ct_opts\n"}' $(APP)/Makefile
  158. $i "Generate a Common Test suite"
  159. $t mkdir $(APP)/test
  160. $t printf "%s\n" \
  161. "-module($(APP)_SUITE)." \
  162. "-export([all/0, ok/1])." \
  163. "all() -> [ok]." \
  164. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  165. $i "Run Common Test"
  166. $t $(MAKE) -C $(APP) ct $v
  167. $i "Check that Common Test uses options from CT_OPTS"
  168. $t grep -q hello_ct_opts $(APP)/logs/index.html
  169. ct-logs-dir: build clean
  170. $i "Bootstrap a new OTP application named $(APP)"
  171. $t mkdir $(APP)/
  172. $t cp ../erlang.mk $(APP)/
  173. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  174. $i "Set CT_OPTS in the Makefile"
  175. $t perl -ni.bak -e 'print;if ($$.==1) {print "CT_LOGS_DIR = custom_dir\n"}' $(APP)/Makefile
  176. $i "Generate a Common Test suite"
  177. $t mkdir $(APP)/test
  178. $t printf "%s\n" \
  179. "-module($(APP)_SUITE)." \
  180. "-export([all/0, ok/1])." \
  181. "all() -> [ok]." \
  182. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  183. $i "Check that Common Test log in right place"
  184. $t test ! -e $(APP)/custom_dir/index.html
  185. $t $(MAKE) -C $(APP) ct $v
  186. $t test -f $(APP)/custom_dir/index.html
  187. ct-suite: build clean
  188. $i "Bootstrap a new OTP application named $(APP)"
  189. $t mkdir $(APP)/
  190. $t cp ../erlang.mk $(APP)/
  191. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  192. $i "Generate two Common Test suites"
  193. $t mkdir $(APP)/test
  194. $t printf "%s\n" \
  195. "-module($(APP)_ok_SUITE)." \
  196. "-export([all/0, ok/1])." \
  197. "all() -> [ok]." \
  198. "ok(_) -> ok." > $(APP)/test/$(APP)_ok_SUITE.erl
  199. $t printf "%s\n" \
  200. "-module($(APP)_fail_SUITE)." \
  201. "-export([all/0, bad/1])." \
  202. "all() -> [bad]." \
  203. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_fail_SUITE.erl
  204. $i "Check that we can run Common Test on a specific test suite"
  205. $t $(MAKE) -C $(APP) ct-$(APP)_ok $v
  206. ct-tests: build clean
  207. $i "Bootstrap a new OTP application named $(APP)"
  208. $t mkdir $(APP)/
  209. $t cp ../erlang.mk $(APP)/
  210. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  211. $i "Generate a Common Test suite"
  212. $t mkdir $(APP)/test
  213. $t printf "%s\n" \
  214. "-module($(APP)_SUITE)." \
  215. "-export([all/0, ok/1])." \
  216. "all() -> [ok]." \
  217. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  218. $i "Check that Common Test runs on 'make tests'"
  219. $t test ! -e $(APP)/logs/index.html
  220. $t $(MAKE) -C $(APP) tests $v
  221. $t test -f $(APP)/logs/index.html