plugin_ct.mk 8.0 KB

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