plugin_ct.mk 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. # Common Test plugin.
  2. CT_TARGETS = $(call list_targets,ct)
  3. .PHONY: ct $(CT_TARGETS)
  4. ct: $(CT_TARGETS)
  5. ct-all: build clean
  6. $i "Bootstrap a new OTP application named $(APP)"
  7. $t mkdir $(APP)/
  8. $t cp ../erlang.mk $(APP)/
  9. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  10. $i "Check that Common Test detects no tests"
  11. $t $(MAKE) -C $(APP) ct | grep -c "Nothing to be done for 'ct'." | grep -q 1
  12. $i "Generate a Common Test suite"
  13. $t mkdir $(APP)/test
  14. $t printf "%s\n" \
  15. "-module($(APP)_SUITE)." \
  16. "-export([all/0, ok/1])." \
  17. "all() -> [ok]." \
  18. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  19. $i "Check that Common Test runs tests"
  20. # We can't pipe CT's output without it crashing, so let's check that
  21. # the command succeeds and log files are created instead.
  22. $t test ! -e $(APP)/logs/index.html
  23. $t $(MAKE) -C $(APP) ct $v
  24. $t test -f $(APP)/logs/index.html
  25. $i "Generate a Common Test suite with a failing test case"
  26. $t printf "%s\n" \
  27. "-module($(APP)_fail_SUITE)." \
  28. "-export([all/0, fail/1])." \
  29. "all() -> [fail]." \
  30. "fail(_) -> throw(fail)." > $(APP)/test/$(APP)_fail_SUITE.erl
  31. $i "Check that Common Test errors out"
  32. $t ! $(MAKE) -C $(APP) ct $v
  33. $i "Check that logs are kept on clean"
  34. $t $(MAKE) -C $(APP) clean $v
  35. $t test -f $(APP)/logs/index.html
  36. $i "Check that logs are deleted on distclean"
  37. $t $(MAKE) -C $(APP) distclean $v
  38. $t test ! -e $(APP)/logs/index.html
  39. ct-apps: build clean
  40. $i "Create a multi application repository with root application"
  41. $t mkdir $(APP)/
  42. $t cp ../erlang.mk $(APP)/.
  43. $t echo "include erlang.mk" > $(APP)/Makefile
  44. $i "Create a new library named my_lib"
  45. $t $(MAKE) -C $(APP) new-lib in=my_lib $v
  46. $i "Populate my_lib"
  47. $t printf "%s\n" \
  48. "-module(my_lib)." \
  49. "-export([random_int/0])." \
  50. "random_int() -> 4." > $(APP)/apps/my_lib/src/my_lib.erl
  51. $i "Generate a Common Test suite in root application"
  52. $t mkdir $(APP)/test
  53. $t printf "%s\n" \
  54. "-module(my_root_SUITE)." \
  55. "-export([all/0, ok/1, call_my_lib/1])." \
  56. "all() -> [ok, call_my_lib]." \
  57. "ok(_) -> ok." \
  58. "call_my_lib(_) -> 4 = my_lib:random_int()." > $(APP)/test/my_root_SUITE.erl
  59. $i "Check that Common Test runs tests"
  60. $t $(MAKE) -C $(APP) ct $v
  61. $i "Check that Common Test runs tests from a specific test suite"
  62. $t $(MAKE) -C $(APP) ct-my_root $v
  63. $i "Check that Common Test runs tests from a specific test suite using CT_SUITES"
  64. $t $(MAKE) -C $(APP) ct CT_SUITES=my_root $v
  65. ct-apps-only: build clean
  66. $i "Create a multi application repository with no root application"
  67. $t mkdir $(APP)/
  68. $t cp ../erlang.mk $(APP)/
  69. $t echo "include erlang.mk" > $(APP)/Makefile
  70. $i "Create a new application named my_app_only"
  71. $t $(MAKE) -C $(APP) new-app in=my_app_only $v
  72. $i "Create a new library named my_lib_only"
  73. $t $(MAKE) -C $(APP) new-lib in=my_lib_only $v
  74. $i "Populate my_lib_only"
  75. $t printf "%s\n" \
  76. "-module(my_lib_only)." \
  77. "-export([random_int/0])." \
  78. "random_int() -> 4." > $(APP)/apps/my_lib_only/src/my_lib_only.erl
  79. $i "Check that Common Test detects no tests"
  80. $t $(MAKE) -C $(APP) ct | grep -c "Nothing to be done for 'ct'." | grep -q 2
  81. $i "Generate a Common Test suite in my_app_only"
  82. $t mkdir $(APP)/apps/my_app_only/test
  83. $t printf "%s\n" \
  84. "-module(my_app_only_SUITE)." \
  85. "-export([all/0, ok/1, call_my_lib_only/1])." \
  86. "all() -> [ok, call_my_lib_only]." \
  87. "ok(_) -> ok." \
  88. "call_my_lib_only(_) -> 4 = my_lib_only:random_int()." > $(APP)/apps/my_app_only/test/my_app_only_SUITE.erl
  89. $i "Generate a Common Test suite in my_lib_only"
  90. $t mkdir $(APP)/apps/my_lib_only/test
  91. $t printf "%s\n" \
  92. "-module(my_lib_only_SUITE)." \
  93. "-export([all/0, ok/1])." \
  94. "all() -> [ok]." \
  95. "ok(_) -> ok." > $(APP)/apps/my_lib_only/test/my_lib_only_SUITE.erl
  96. $i "Check that Common Test runs tests"
  97. # We can't pipe CT's output without it crashing, so let's check that
  98. # the command succeeds and log files are created instead.
  99. $t test ! -e $(APP)/apps/my_app_only/logs/index.html
  100. $t test ! -e $(APP)/apps/my_lib_only/logs/index.html
  101. $t $(MAKE) -C $(APP) ct $v
  102. $t test -f $(APP)/apps/my_app_only/logs/index.html
  103. $t test -f $(APP)/apps/my_lib_only/logs/index.html
  104. ct-case: build clean
  105. $i "Bootstrap a new OTP application named $(APP)"
  106. $t mkdir $(APP)/
  107. $t cp ../erlang.mk $(APP)/
  108. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  109. $i "Generate a Common Test suite with two cases"
  110. $t mkdir $(APP)/test
  111. $t printf "%s\n" \
  112. "-module($(APP)_SUITE)." \
  113. "-export([all/0, groups/0, ok/1, bad/1])." \
  114. "all() -> [{group, mygroup}]." \
  115. "groups() -> [{mygroup, [ok, bad]}]." \
  116. "ok(_) -> ok." \
  117. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  118. $i "Check that we can run Common Test on a specific test case"
  119. $t $(MAKE) -C $(APP) ct-$(APP) t=mygroup:ok $v
  120. ct-case-without-group: build clean
  121. $i "Bootstrap a new OTP application named $(APP)"
  122. $t mkdir $(APP)/
  123. $t cp ../erlang.mk $(APP)/
  124. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  125. $i "Generate a Common Test suite with two cases that are not part of any group"
  126. $t mkdir $(APP)/test
  127. $t printf "%s\n" \
  128. "-module($(APP)_SUITE)." \
  129. "-export([all/0, ok/1, bad/1])." \
  130. "all() -> [ok, bad]." \
  131. "ok(_) -> ok." \
  132. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  133. $i "Check that we can run Common Test on a specific test case"
  134. $t $(MAKE) -C $(APP) ct-$(APP) c=ok $v
  135. ct-check: 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"
  141. $t mkdir $(APP)/test
  142. $t printf "%s\n" \
  143. "-module($(APP)_SUITE)." \
  144. "-export([all/0, ok/1])." \
  145. "all() -> [ok]." \
  146. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  147. $i "Check that Common Test runs on 'make check'"
  148. $t test ! -e $(APP)/logs/index.html
  149. $t $(MAKE) -C $(APP) check $v
  150. $t test -f $(APP)/logs/index.html
  151. ct-group: 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 "Generate a Common Test suite with two groups"
  157. $t mkdir $(APP)/test
  158. $t printf "%s\n" \
  159. "-module($(APP)_SUITE)." \
  160. "-export([all/0, groups/0, ok/1, bad/1])." \
  161. "all() -> [{group, okgroup}, {group, badgroup}]." \
  162. "groups() -> [{okgroup, [ok]}, {badgroup, [bad]}]." \
  163. "ok(_) -> ok." \
  164. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_SUITE.erl
  165. $i "Check that we can run Common Test on a specific group"
  166. $t $(MAKE) -C $(APP) ct-$(APP) t=okgroup $v
  167. ct-opts: build clean
  168. $i "Bootstrap a new OTP application named $(APP)"
  169. $t mkdir $(APP)/
  170. $t cp ../erlang.mk $(APP)/
  171. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  172. $i "Set CT_OPTS in the Makefile"
  173. $t perl -ni.bak -e 'print;if ($$.==1) {print "CT_OPTS = -label hello_ct_opts\n"}' $(APP)/Makefile
  174. $i "Generate a Common Test suite"
  175. $t mkdir $(APP)/test
  176. $t printf "%s\n" \
  177. "-module($(APP)_SUITE)." \
  178. "-export([all/0, ok/1])." \
  179. "all() -> [ok]." \
  180. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  181. $i "Run Common Test"
  182. $t $(MAKE) -C $(APP) ct $v
  183. $i "Check that Common Test uses options from CT_OPTS"
  184. $t grep -q hello_ct_opts $(APP)/logs/index.html
  185. ct-logs-dir: build clean
  186. $i "Bootstrap a new OTP application named $(APP)"
  187. $t mkdir $(APP)/
  188. $t cp ../erlang.mk $(APP)/
  189. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  190. $i "Set CT_OPTS in the Makefile"
  191. $t perl -ni.bak -e 'print;if ($$.==1) {print "CT_LOGS_DIR = custom_dir\n"}' $(APP)/Makefile
  192. $i "Generate a Common Test suite"
  193. $t mkdir $(APP)/test
  194. $t printf "%s\n" \
  195. "-module($(APP)_SUITE)." \
  196. "-export([all/0, ok/1])." \
  197. "all() -> [ok]." \
  198. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  199. $i "Check that Common Test log in right place"
  200. $t test ! -e $(APP)/custom_dir/index.html
  201. $t $(MAKE) -C $(APP) ct $v
  202. $t test -f $(APP)/custom_dir/index.html
  203. ct-suite: build clean
  204. $i "Bootstrap a new OTP application named $(APP)"
  205. $t mkdir $(APP)/
  206. $t cp ../erlang.mk $(APP)/
  207. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  208. $i "Generate two Common Test suites"
  209. $t mkdir $(APP)/test
  210. $t printf "%s\n" \
  211. "-module($(APP)_ok_SUITE)." \
  212. "-export([all/0, ok/1])." \
  213. "all() -> [ok]." \
  214. "ok(_) -> ok." > $(APP)/test/$(APP)_ok_SUITE.erl
  215. $t printf "%s\n" \
  216. "-module($(APP)_fail_SUITE)." \
  217. "-export([all/0, bad/1])." \
  218. "all() -> [bad]." \
  219. "bad(_) -> throw(fail)." > $(APP)/test/$(APP)_fail_SUITE.erl
  220. $i "Check that we can run Common Test on a specific test suite"
  221. $t $(MAKE) -C $(APP) ct-$(APP)_ok $v
  222. ct-tests: build clean
  223. $i "Bootstrap a new OTP application named $(APP)"
  224. $t mkdir $(APP)/
  225. $t cp ../erlang.mk $(APP)/
  226. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  227. $i "Generate a Common Test suite"
  228. $t mkdir $(APP)/test
  229. $t printf "%s\n" \
  230. "-module($(APP)_SUITE)." \
  231. "-export([all/0, ok/1])." \
  232. "all() -> [ok]." \
  233. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  234. $i "Check that Common Test runs on 'make tests'"
  235. $t test ! -e $(APP)/logs/index.html
  236. $t $(MAKE) -C $(APP) tests $v
  237. $t test -f $(APP)/logs/index.html