Makefile 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. # Copyright (c) 2014, Viktor Söderqvist <viktor@zuiderkwast.se>
  2. # This file is part of erlang.mk and subject to the terms of the ISC License.
  3. # Tests for erlang.mk targets. If any test fails or if you run a target other
  4. # than 'all', you must probably do 'make clean' before you can test again.
  5. # Verbosity.
  6. V ?= 0
  7. # Temporary files directory.
  8. ERLANG_MK_TMP=$(CURDIR)/tmp
  9. export ERLANG_MK_TMP
  10. # Temporary application name, taken from rule name.
  11. APP = $(subst -,_,$@)
  12. APP_TO_CLEAN = $(subst -,_,$(patsubst clean-%,%,$@))
  13. # Erlang, quickly!
  14. ERL = erl +A0 -noinput -boot start_clean
  15. # OTP master, for downloading files for testing.
  16. OTP_MASTER = https://raw.githubusercontent.com/erlang/otp/master
  17. # t = Verbosity control for tests
  18. # v = Verbosity control for erlang.mk
  19. # i = Command to display (or suppress) info messages
  20. ifeq ($V,0)
  21. # Show info messages only
  22. t = @
  23. v = V=0 >/dev/null 2>&1
  24. i = @echo $@:
  25. else ifeq ($V,1)
  26. # Show test commands
  27. t =
  28. v = V=0 >/dev/null 2>&1
  29. i = @echo == $@:
  30. else ifeq ($V,2)
  31. # Show briefly what erlang.mk is doing
  32. t = @echo " TEST " $@;
  33. v = V=0
  34. i = @echo == $@:
  35. else
  36. # Show all commands with maximum verbosity
  37. t =
  38. v = V=1
  39. i = @echo == $@:
  40. endif
  41. .PHONY: all clean app ct eunit tests-cover docs
  42. .NOTPARALLEL:
  43. all: clean core bootstrap app ct eunit tests-cover docs pkgs
  44. $i '+---------------------+'
  45. $i '| All tests passed. |'
  46. $i '+---------------------+'
  47. clean: clean-core clean-bootstrap
  48. $t rm -rf app1 pkgs.log $(ERLANG_MK_TMP)
  49. build:
  50. $i "Generate a bleeding edge Erlang.mk"
  51. $t cd .. && $(MAKE) $v
  52. # Core.
  53. .PHONY: core clean-core
  54. core: core-app core-upgrade
  55. clean-core: clean-core-app clean-core-upgrade
  56. # Core: Building applications.
  57. CORE_APP_CASES = asn1 hrl hrl-recursive mib xrl yrl
  58. CORE_APP_TARGETS = $(addprefix core-app-,$(CORE_APP_CASES))
  59. CORE_APP_CLEAN_TARGETS = $(addprefix clean-,$(CORE_APP_TARGETS))
  60. .PHONY: core-app $(CORE_APP_TARGETS) $(CORE_APP_CLEAN_TARGETS)
  61. core-app: $(CORE_APP_TARGETS)
  62. core-app-asn1: build clean-core-app-asn1
  63. $i "Bootstrap a new OTP library named $(APP)"
  64. $t mkdir $(APP)/
  65. $t cp ../erlang.mk $(APP)/
  66. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  67. $i "Download .asn1 files from Erlang/OTP"
  68. $t mkdir $(APP)/asn1/
  69. $t curl -s -o $(APP)/asn1/CAP.asn1 $(OTP_MASTER)/lib/asn1/test/asn1_SUITE_data/CAP.asn1
  70. $t curl -s -o $(APP)/asn1/Def.asn1 $(OTP_MASTER)/lib/asn1/test/asn1_SUITE_data/Def.asn1
  71. $i "Generate .erl files dependent from headers generated by .asn1 files"
  72. $t printf "%s\n" "-module(use_cap)." "-include(\"CAP.hrl\")." > $(APP)/src/use_cap.erl
  73. $t printf "%s\n" "-module(use_def)." "-include(\"Def.hrl\")." > $(APP)/src/use_def.erl
  74. $i "Build the application"
  75. $t $(MAKE) -C $(APP) $v
  76. $i "Check that all compiled files exist"
  77. $t test -f $(APP)/$(APP).d
  78. $t test -f $(APP)/ebin/$(APP).app
  79. $t test -f $(APP)/ebin/CAP.beam
  80. $t test -f $(APP)/ebin/Def.beam
  81. $t test -f $(APP)/ebin/use_cap.beam
  82. $t test -f $(APP)/ebin/use_def.beam
  83. $t test -f $(APP)/include/CAP.asn1db
  84. $t test -f $(APP)/include/CAP.hrl
  85. $t test -f $(APP)/include/Def.asn1db
  86. $t test -f $(APP)/include/Def.hrl
  87. $t test -f $(APP)/src/CAP.erl
  88. $t test -f $(APP)/src/Def.erl
  89. $i "Check that the application was compiled correctly"
  90. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  91. ok = application:start($(APP)), \
  92. {ok, Mods = ['CAP', 'Def', use_cap, use_def]} \
  93. = application:get_key($(APP), modules), \
  94. [{module, M} = code:load_file(M) || M <- Mods], \
  95. halt()"
  96. $i "Touch one .asn1 file; check that only required files are rebuilt"
  97. # The use_cap.erl gets touched because of its dependency to CAP.hrl.
  98. $t printf "%s\n" \
  99. $(APP)/$(APP).d \
  100. $(APP)/ebin/$(APP).app \
  101. $(APP)/ebin/CAP.beam \
  102. $(APP)/ebin/use_cap.beam \
  103. $(APP)/include/CAP.asn1db \
  104. $(APP)/include/CAP.hrl \
  105. $(APP)/src/CAP.erl \
  106. $(APP)/src/use_cap.erl | sort > $(APP)/EXPECT
  107. $t touch $(APP)/asn1/CAP.asn1
  108. $t $(MAKE) -C $(APP) $v
  109. $t find $(APP) -type f -newer $(APP)/asn1/CAP.asn1 | sort | diff $(APP)/EXPECT -
  110. $t rm $(APP)/EXPECT
  111. $i "Check that the application was compiled correctly"
  112. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  113. ok = application:start($(APP)), \
  114. {ok, Mods = ['CAP', 'Def', use_cap, use_def]} \
  115. = application:get_key($(APP), modules), \
  116. [{module, M} = code:load_file(M) || M <- Mods], \
  117. halt()"
  118. $i "Clean the application"
  119. $t $(MAKE) -C $(APP) clean $v
  120. $i "Check that source files still exist"
  121. $t test -f $(APP)/Makefile
  122. $t test -f $(APP)/erlang.mk
  123. $t test -f $(APP)/asn1/CAP.asn1
  124. $t test -f $(APP)/asn1/Def.asn1
  125. $t test -d $(APP)/include/
  126. $t test -f $(APP)/src/$(APP).app.src
  127. $t test -f $(APP)/src/use_cap.erl
  128. $t test -f $(APP)/src/use_def.erl
  129. $i "Check that all build artifacts are removed, including intermediates"
  130. $t test ! -e $(APP)/$(APP).d
  131. $t test ! -e $(APP)/ebin/
  132. $t test ! -e $(APP)/include/CAP.asn1db
  133. $t test ! -e $(APP)/include/CAP.hrl
  134. $t test ! -e $(APP)/include/Def.asn1db
  135. $t test ! -e $(APP)/include/Def.hrl
  136. $t test ! -e $(APP)/src/CAP.erl
  137. $t test ! -e $(APP)/src/Def.erl
  138. $i "Build the application again"
  139. $t $(MAKE) -C $(APP) $v
  140. $i "Check that all compiled files exist"
  141. $t test -f $(APP)/$(APP).d
  142. $t test -f $(APP)/ebin/$(APP).app
  143. $t test -f $(APP)/ebin/CAP.beam
  144. $t test -f $(APP)/ebin/Def.beam
  145. $t test -f $(APP)/ebin/use_cap.beam
  146. $t test -f $(APP)/ebin/use_def.beam
  147. $t test -f $(APP)/include/CAP.asn1db
  148. $t test -f $(APP)/include/CAP.hrl
  149. $t test -f $(APP)/include/Def.asn1db
  150. $t test -f $(APP)/include/Def.hrl
  151. $t test -f $(APP)/src/CAP.erl
  152. $t test -f $(APP)/src/Def.erl
  153. $i "Check that the application was compiled correctly"
  154. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  155. ok = application:start($(APP)), \
  156. {ok, Mods = ['CAP', 'Def', use_cap, use_def]} \
  157. = application:get_key($(APP), modules), \
  158. [{module, M} = code:load_file(M) || M <- Mods], \
  159. halt()"
  160. clean-core-app: $(CORE_APP_CLEAN_TARGETS)
  161. $(CORE_APP_CLEAN_TARGETS):
  162. $t rm -rf $(APP_TO_CLEAN)/
  163. # Core: Erlang.mk upgrade.
  164. CORE_UPGRADE_CASES = no-config custom-config renamed-config custom-build-dir
  165. CORE_UPGRADE_TARGETS = $(addprefix core-upgrade-,$(CORE_UPGRADE_CASES))
  166. CORE_UPGRADE_CLEAN_TARGETS = $(addprefix clean-,$(CORE_UPGRADE_TARGETS))
  167. .PHONY: core-upgrade $(CORE_UPGRADE_TARGETS) $(CORE_UPGRADE_CLEAN_TARGETS)
  168. core-upgrade: $(CORE_UPGRADE_TARGETS)
  169. core-upgrade-no-config: build clean-core-upgrade-no-config
  170. $i "Bootstrap a new OTP library named $(APP)"
  171. $t mkdir $(APP)/
  172. $t cp ../erlang.mk $(APP)/
  173. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  174. $i "Append a rule to the Erlang.mk file for testing purposes"
  175. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  176. $i "Check that the test rule works as intended"
  177. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  178. $i "Upgrade Erlang.mk"
  179. $t $(MAKE) -C $(APP) erlang-mk $v
  180. $i "Check that the rule is gone"
  181. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  182. core-upgrade-custom-config: build clean-core-upgrade-custom-config
  183. $i "Bootstrap a new OTP library named $(APP)"
  184. $t mkdir $(APP)/
  185. $t cp ../erlang.mk $(APP)/
  186. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  187. $i "Create a custom build.config file without plugins"
  188. $t echo "core/*" > $(APP)/build.config
  189. $i "Upgrade Erlang.mk"
  190. $t $(MAKE) -C $(APP) erlang-mk $v
  191. $i "Check that the bootstrap plugin is gone"
  192. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  193. core-upgrade-renamed-config: build clean-core-upgrade-renamed-config
  194. $i "Bootstrap a new OTP library named $(APP)"
  195. $t mkdir $(APP)/
  196. $t cp ../erlang.mk $(APP)/
  197. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  198. $i "Create a custom build.config file without plugins; name it my.build.config"
  199. $t echo "core/*" > $(APP)/my.build.config
  200. $i "Set ERLANG_MK_BUILD_CONFIG=my.build.config in the Makefile"
  201. $t echo "ERLANG_MK_BUILD_CONFIG = my.build.config" >> $(APP)/Makefile
  202. $i "Upgrade Erlang.mk"
  203. $t $(MAKE) -C $(APP) erlang-mk $v
  204. $i "Check that the bootstrap plugin is gone"
  205. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  206. core-upgrade-custom-build-dir: build clean-core-upgrade-custom-build-dir
  207. $i "Bootstrap a new OTP library named $(APP)"
  208. $t mkdir $(APP)/
  209. $t cp ../erlang.mk $(APP)/
  210. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  211. $i "Append a rule to the Erlang.mk file for testing purposes"
  212. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  213. $i "Check that the test rule works as intended"
  214. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  215. $i "Create the custom build directory"
  216. $t mkdir $(APP)/custom/
  217. $t test -d $(APP)/custom/
  218. $i "Upgrade Erlang.mk with a custom build directory"
  219. $t ERLANG_MK_BUILD_DIR=custom $(MAKE) -C $(APP) erlang-mk $v
  220. $i "Check that the rule is gone"
  221. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  222. $i "Check that the custom build directory is gone"
  223. $t test ! -d $(APP)/custom/
  224. clean-core-upgrade: $(CORE_UPGRADE_CLEAN_TARGETS)
  225. $(CORE_UPGRADE_CLEAN_TARGETS):
  226. $t rm -rf $(APP_TO_CLEAN)/
  227. # Bootstrap plugin.
  228. BOOTSTRAP_CASES = app lib rel templates
  229. BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
  230. BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
  231. .PHONY: bootstrap $(BOOTSTRAP_TARGETS) $(BOOTSTRAP_CLEAN_TARGETS)
  232. bootstrap: $(BOOTSTRAP_TARGETS)
  233. bootstrap-app: build clean-bootstrap-app
  234. $i "Bootstrap a new OTP application named $(APP)"
  235. $t mkdir $(APP)/
  236. $t cp ../erlang.mk $(APP)/
  237. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  238. $i "Check that all bootstrapped files exist"
  239. $t test -f $(APP)/Makefile
  240. $t test -f $(APP)/src/$(APP).app.src
  241. $t test -f $(APP)/src/$(APP)_app.erl
  242. $t test -f $(APP)/src/$(APP)_sup.erl
  243. $i "Build the application"
  244. $t $(MAKE) -C $(APP) $v
  245. $i "Check that all compiled files exist"
  246. $t test -f $(APP)/ebin/$(APP).app
  247. $t test -f $(APP)/ebin/$(APP)_app.beam
  248. $t test -f $(APP)/ebin/$(APP)_sup.beam
  249. $i "Check that the application was compiled correctly"
  250. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  251. ok = application:start($(APP)), \
  252. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  253. {module, $(APP)_app} = code:load_file($(APP)_app), \
  254. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  255. halt()"
  256. bootstrap-lib: build clean-bootstrap-lib
  257. $i "Bootstrap a new OTP library named $(APP)"
  258. $t mkdir $(APP)/
  259. $t cp ../erlang.mk $(APP)/
  260. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  261. $i "Check that all bootstrapped files exist"
  262. $t test -f $(APP)/Makefile
  263. $t test -f $(APP)/src/$(APP).app.src
  264. $i "Build the application"
  265. $t $(MAKE) -C $(APP) $v
  266. $i "Check that all compiled files exist"
  267. $t test -f $(APP)/ebin/$(APP).app
  268. $i "Check that the application was compiled correctly"
  269. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  270. ok = application:start($(APP)), \
  271. {ok, []} = application:get_key($(APP), modules), \
  272. halt()"
  273. bootstrap-rel: build clean-bootstrap-rel
  274. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  275. $t mkdir $(APP)/
  276. $t cp ../erlang.mk $(APP)/
  277. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  278. $i "Check that all bootstrapped files exist"
  279. $t test -f $(APP)/Makefile
  280. $t test -f $(APP)/relx.config
  281. $t test -f $(APP)/rel/sys.config
  282. $t test -f $(APP)/rel/vm.args
  283. $t test -f $(APP)/src/$(APP).app.src
  284. $t test -f $(APP)/src/$(APP)_app.erl
  285. $t test -f $(APP)/src/$(APP)_sup.erl
  286. $i "Build the application and the release"
  287. $t $(MAKE) -C $(APP) $v
  288. $i "Check that all compiled files exist"
  289. $t test -f $(APP)/ebin/$(APP).app
  290. $t test -f $(APP)/ebin/$(APP)_app.beam
  291. $t test -f $(APP)/ebin/$(APP)_sup.beam
  292. $i "Check that the release was generated"
  293. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  294. $i "Check that the release can be started and stopped"
  295. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  296. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  297. $i "Check that there's no erl_crash.dump file"
  298. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  299. bootstrap-templates: build clean-bootstrap-templates
  300. $i "Bootstrap a new OTP library named $(APP)"
  301. $t mkdir $(APP)/
  302. $t cp ../erlang.mk $(APP)/
  303. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  304. $i "Check that we can get the list of templates"
  305. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  306. $i "Generate one of each template"
  307. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  308. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  309. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  310. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  311. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  312. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  313. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  314. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  315. # Here we disable warnings because templates contain missing behaviors.
  316. $i "Build the application"
  317. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  318. $i "Check that all compiled files exist"
  319. $t test -f $(APP)/ebin/$(APP).app
  320. $t test -f $(APP)/ebin/my_fsm.beam
  321. $t test -f $(APP)/ebin/my_server.beam
  322. $t test -f $(APP)/ebin/my_sup.beam
  323. $i "Check that all the modules can be loaded"
  324. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  325. ok = application:start($(APP)), \
  326. {ok, Mods = [my_fsm, my_http, my_loop, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  327. = application:get_key($(APP), modules), \
  328. [{module, M} = code:load_file(M) || M <- Mods], \
  329. halt()"
  330. clean-bootstrap: $(BOOTSTRAP_CLEAN_TARGETS)
  331. $(BOOTSTRAP_CLEAN_TARGETS):
  332. $t rm -rf $(APP_TO_CLEAN)/
  333. ########################################
  334. # Legacy tests.
  335. app: app1
  336. $i "app: Testing the 'app' target."
  337. $t $(MAKE) -C app1 app $v
  338. $i "Checking the modules line in the generated .app file."
  339. $t [ `grep -E "{modules, *\['m'\]}" app1/ebin/app1.app | wc -l` -eq 1 ]
  340. $t [ -e app1/ebin/m.beam ]
  341. $i "Checking that '$(MAKE) clean-app' deletes ebin."
  342. $t $(MAKE) -C app1 clean-app $v
  343. $t [ ! -e app1/ebin ]
  344. $i "Checking that '$(MAKE) app' returns non-zero on compile errors."
  345. $t printf "%s\n" \
  346. "-module(syntax_error)." \
  347. "foo lorem_ipsum dolor sit amet." \
  348. > app1/src/syntax_error.erl
  349. $t if $(MAKE) -C app1 app $v ; then false ; fi
  350. $t rm app1/src/syntax_error.erl
  351. $i "Test 'app' passed."
  352. ct: app1
  353. $i "ct: Testing ct and related targets."
  354. $i "Setting up test suite."
  355. $t mkdir -p app1/test
  356. $t printf "%s\n" \
  357. "-module(m_SUITE)." \
  358. "-export([all/0, testcase1/1])." \
  359. "all() -> [testcase1]." \
  360. "testcase1(_) -> 2 = m:succ(1)." \
  361. > app1/test/m_SUITE.erl
  362. $t $(MAKE) -C app1 ct $v
  363. $i "Checking files created by '$(MAKE) ct'."
  364. $t [ -e app1/test/m_SUITE.beam ]
  365. $t [ -e app1/ebin/m.beam ]
  366. $t [ -e app1/logs ]
  367. $i "Checking that '$(MAKE) clean' does not delete logs."
  368. $t $(MAKE) -C app1 clean $v
  369. $t [ -e app1/logs ]
  370. $i "Testing target 'ct-mysuite' where mysuite_SUITE is a test suite."
  371. $t $(MAKE) -C app1 ct-m $v
  372. $i "Checking that '$(MAKE) ct' returns non-zero for a failing suite."
  373. $t printf "%s\n" \
  374. "-module(failing_SUITE)." \
  375. "-export([all/0, testcase1/1])." \
  376. "all() -> [testcase1]." \
  377. "testcase1(_) -> 42 = m:succ(1)." \
  378. > app1/test/failing_SUITE.erl
  379. $t if $(MAKE) -C app1 ct-failing $v ; then false ; fi
  380. $i "Checking that '$(MAKE) distclean-ct' deletes logs."
  381. $t $(MAKE) -C app1 distclean-ct $v
  382. $t [ ! -e app1/logs ]
  383. $t [ -e app1/ebin/m.beam ]
  384. $i "Cleaning up test data."
  385. $t rm -rf app1/test
  386. $i "Test 'ct' passed."
  387. eunit: app1
  388. $i "eunit: Testing the 'eunit' target."
  389. $i "Running eunit test case inside module src/t.erl"
  390. $t $(call create-module-t)
  391. $t $(MAKE) -C app1 distclean $v
  392. $t $(MAKE) -C app1 eunit $v
  393. $i "Checking that the eunit test in module t."
  394. $t echo t | cmp app1/test-eunit.log -
  395. $t rm app1/test-eunit.log
  396. $i "Running eunit tests in a separate directory."
  397. $t mkdir -p app1/eunit
  398. $t printf '%s\n' \
  399. '-module(t_tests).' \
  400. '-include_lib("eunit/include/eunit.hrl").' \
  401. 'succ_test() ->' \
  402. ' ?assertEqual(2, t:succ(1)),' \
  403. ' os:cmd("echo t_tests >> test-eunit.log").' \
  404. > app1/eunit/t_tests.erl
  405. $t printf '%s\n' \
  406. '-module(x_tests).' \
  407. '-include_lib("eunit/include/eunit.hrl").' \
  408. 'succ_test() ->' \
  409. ' ?assertEqual(2, t:succ(1)),' \
  410. ' os:cmd("echo x_tests >> test-eunit.log").' \
  411. > app1/eunit/x_tests.erl
  412. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  413. $t $(MAKE) -C app1 eunit TEST_DIR=eunit $v
  414. $i "Checking that '$(MAKE) eunit' didn't run the tests in t_tests twice, etc."
  415. $t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
  416. $t rm app1/test-eunit.log
  417. $i "Checking that '$(MAKE) eunit' returns non-zero for a failing test."
  418. $t rm -f app1/eunit/*
  419. $t printf "%s\n" \
  420. "-module(t_tests)." \
  421. '-include_lib("eunit/include/eunit.hrl").' \
  422. "succ_test() ->" \
  423. " ?assertEqual(42, t:succ(1))." \
  424. > app1/eunit/t_tests.erl
  425. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  426. $t if $(MAKE) -C app1 eunit TEST_DIR=eunit $v ; then false ; fi
  427. $t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
  428. $i "Test 'eunit' passed."
  429. # TODO: do coverage for 'tests' instead of 'eunit ct' when triq is fixed
  430. tests-cover: app1
  431. $i "tests-cover: Testing 'eunit' and 'ct' with COVER=1"
  432. $i "Setting up eunit and ct suites."
  433. $t $(call create-module-t)
  434. $t mkdir -p app1/test
  435. $t printf "%s\n" \
  436. "-module(m_SUITE)." \
  437. "-export([all/0, testcase1/1])." \
  438. "all() -> [testcase1]." \
  439. "testcase1(_) -> 2 = m:succ(1)." \
  440. > app1/test/m_SUITE.erl
  441. $i "Running tests with coverage analysis."
  442. $t $(MAKE) -C app1 eunit ct COVER=1 $v
  443. $t [ -e app1/test-eunit.log ]
  444. $t [ -e app1/eunit.coverdata ]
  445. $t [ -e app1/ct.coverdata ]
  446. $i "Generating coverage report."
  447. $t $(MAKE) -C app1 cover-report COVER=1 $v
  448. $t [ -e app1/cover/m.COVER.html ]
  449. $t [ -e app1/cover/t.COVER.html ]
  450. $t [ -e app1/cover/index.html ]
  451. $i "Checking combined coverage from eunit and ct."
  452. $t [ `grep 'Total: 100%' app1/cover/index.html | wc -l` -eq 1 ]
  453. $i "Checking that cover-report-clean removes cover report."
  454. $t $(MAKE) -C app1 cover-report-clean $v
  455. $t [ ! -e app1/cover ]
  456. $i "Checking that coverdata-clean removes cover data."
  457. $t $(MAKE) -C app1 coverdata-clean $v
  458. $t [ ! -e app1/eunit.coverdata ]
  459. @# clean up
  460. $t rm -rf app1/src/t.erl app1/test app1/test-eunit.log
  461. $t $(MAKE) -C app1 clean $v
  462. $i "Test 'tests-cover' passed."
  463. docs: app1
  464. $i "docs: Testing EDoc including DOC_DEPS."
  465. $t printf "%s\n" \
  466. "PROJECT = app1" \
  467. "DOC_DEPS = edown" \
  468. "dep_edown = git https://github.com/uwiger/edown.git 0.7" \
  469. "EDOC_OPTS = {doclet, edown_doclet}" \
  470. "include erlang.mk" \
  471. "distclean:: distclean-doc-md" \
  472. "distclean-doc-md:" \
  473. " rm -rf doc/*.md" \
  474. > app1/Makefile-doc
  475. $i "Downloading doc deps (edown) and building docs."
  476. $t $(MAKE) -C app1 -f Makefile-doc docs $v
  477. $i "Checking that '$(MAKE) docs' using edown generated a markdown file."
  478. $t [ -e app1/doc/m.md ]
  479. $i "Checking that '$(MAKE) distclean' deletes all generated doc files."
  480. $t $(MAKE) -C app1 -f Makefile-doc distclean $v
  481. $t [ "`ls app1/doc/`" = "" ]
  482. $i "Cleaning up test data."
  483. $t rm app1/Makefile-doc
  484. $i "Test 'docs' passed."
  485. define app1_setup
  486. $i "Setting up app."
  487. $t mkdir -p app1
  488. $t cd .. && $(MAKE)
  489. $t cp ../erlang.mk app1/
  490. $t $(MAKE) -C app1 -f erlang.mk bootstrap-lib
  491. $t printf "%s\n" \
  492. "-module(m)." \
  493. "-export([succ/1])." \
  494. "succ(N) -> N + 1." \
  495. > app1/src/m.erl
  496. endef
  497. define pkg_test_target
  498. pkg-$(1)-clean:
  499. $t rm -rf app1 erl_crash.dump
  500. pkg-$(1)-app1:
  501. $(call app1_setup)
  502. # Running 'make' twice to make sure it recompiles fine.
  503. pkg-$(1): pkg-$(1)-clean pkg-$(1)-app1
  504. $i
  505. $i " pkgs: Checking that '$(1)' builds correctly"
  506. $i
  507. $t printf "%s\n" \
  508. "PROJECT = app1" \
  509. "DEPS = $(1)" \
  510. "include erlang.mk" \
  511. > app1/Makefile
  512. $t \
  513. if [ "$(1)" = "amqp_client" ]; then \
  514. $(MAKE) -C app1 RABBITMQ_CLIENT_PATCH=1; \
  515. elif [ "$(1)" = "rabbit" ]; then \
  516. $(MAKE) -C app1 RABBITMQ_SERVER_PATCH=1; \
  517. else \
  518. $(MAKE) -C app1; \
  519. fi; \
  520. if [ $$$$? -ne 0 ]; then \
  521. echo "$(1): make error" >> pkgs.log; \
  522. else \
  523. $(MAKE) -C app1; if [ $$$$? -ne 0 ]; then \
  524. echo "$(1): re-make error" >> pkgs.log; \
  525. else \
  526. find . -type f -name erl_crash.dump; if [ $$$$? -ne 0 ]; then \
  527. echo "$(1): erl_crash.dump found" >> pkgs.log; \
  528. else \
  529. erl +A0 -noinput -boot start_clean -pa app1/deps/*/ebin -eval " \
  530. Apps = [list_to_atom(App) || \"app1/deps/\" ++ App \
  531. <- filelib:wildcard(\"app1/deps/*\")], \
  532. [begin \
  533. io:format(\"Loading application ~p~n\", [App]), \
  534. case application:load(App) of \
  535. {error, _} -> ok; \
  536. ok -> \
  537. {ok, Mods} = application:get_key(App, modules), \
  538. [try io:format(\" Loading module ~p~n\", [Mod]), \
  539. {module, Mod} = code:load_file(Mod) \
  540. catch C:R -> timer:sleep(500), erlang:C(R) \
  541. end || Mod <- Mods] \
  542. end \
  543. end || App <- Apps], \
  544. halt()."; if [ $$$$? -ne 0 ]; then \
  545. echo "$(1): load error" >> pkgs.log; \
  546. fi \
  547. fi \
  548. fi \
  549. fi
  550. endef
  551. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  552. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_test_target,$(pkg))))
  553. pkgs: $(addprefix pkg-,$(PACKAGES))
  554. @if [ -f pkgs.log ]; then \
  555. echo "+-------------------------------+"; \
  556. echo "| ERRORS WHILE TESTING PACKAGES |"; \
  557. echo "+-------------------------------+"; \
  558. cat pkgs.log; \
  559. exit 33; \
  560. fi
  561. # Test application used for testing.
  562. app1:
  563. $(call app1_setup)
  564. # Extra module in app1 used for testing eunit
  565. define create-module-t
  566. printf '%s\n' \
  567. '-module(t).' \
  568. '-export([succ/1]).' \
  569. 'succ(N) -> N + 1.' \
  570. '-ifdef(TEST).' \
  571. '-include_lib("eunit/include/eunit.hrl").' \
  572. 'succ_test() ->' \
  573. ' ?assertEqual(2, succ(1)),' \
  574. ' os:cmd("echo t >> test-eunit.log").' \
  575. '-endif.' \
  576. > app1/src/t.erl
  577. endef