Makefile 17 KB

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