Makefile 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297
  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 xrl-include 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. core-app-hrl: build clean-core-app-hrl
  161. $i "Bootstrap a new OTP library named $(APP)"
  162. $t mkdir $(APP)/
  163. $t cp ../erlang.mk $(APP)/
  164. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  165. $i "Generate .hrl files"
  166. $t mkdir $(APP)/include/
  167. $t touch $(APP)/include/blue.hrl $(APP)/include/red.hrl
  168. $i "Generate .erl files dependent from headers"
  169. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  170. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  171. $i "Build the application"
  172. $t $(MAKE) -C $(APP) $v
  173. $i "Check that all compiled files exist"
  174. $t test -f $(APP)/$(APP).d
  175. $t test -f $(APP)/ebin/$(APP).app
  176. $t test -f $(APP)/ebin/use_blue.beam
  177. $t test -f $(APP)/ebin/use_red.beam
  178. $i "Check that the application was compiled correctly"
  179. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  180. ok = application:start($(APP)), \
  181. {ok, Mods = [use_blue, use_red]} \
  182. = application:get_key($(APP), modules), \
  183. [{module, M} = code:load_file(M) || M <- Mods], \
  184. halt()"
  185. $i "Touch one .hrl file; check that only required files are rebuilt"
  186. # The use_red.erl gets touched because of its dependency to red.hrl.
  187. $t printf "%s\n" \
  188. $(APP)/$(APP).d \
  189. $(APP)/ebin/$(APP).app \
  190. $(APP)/ebin/use_red.beam \
  191. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  192. $t touch $(APP)/include/red.hrl
  193. $t $(MAKE) -C $(APP) $v
  194. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  195. $t rm $(APP)/EXPECT
  196. $i "Check that the application was compiled correctly"
  197. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  198. ok = application:start($(APP)), \
  199. {ok, Mods = [use_blue, use_red]} \
  200. = application:get_key($(APP), modules), \
  201. [{module, M} = code:load_file(M) || M <- Mods], \
  202. halt()"
  203. $i "Clean the application"
  204. $t $(MAKE) -C $(APP) clean $v
  205. $i "Check that source files still exist"
  206. $t test -f $(APP)/Makefile
  207. $t test -f $(APP)/erlang.mk
  208. $t test -f $(APP)/include/blue.hrl
  209. $t test -f $(APP)/include/red.hrl
  210. $t test -f $(APP)/src/$(APP).app.src
  211. $t test -f $(APP)/src/use_blue.erl
  212. $t test -f $(APP)/src/use_red.erl
  213. $i "Check that all build artifacts are removed"
  214. $t test ! -e $(APP)/$(APP).d
  215. $t test ! -e $(APP)/ebin/
  216. $i "Build the application again"
  217. $t $(MAKE) -C $(APP) $v
  218. $i "Check that all compiled files exist"
  219. $t test -f $(APP)/$(APP).d
  220. $t test -f $(APP)/ebin/$(APP).app
  221. $t test -f $(APP)/ebin/use_blue.beam
  222. $t test -f $(APP)/ebin/use_red.beam
  223. $i "Check that the application was compiled correctly"
  224. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  225. ok = application:start($(APP)), \
  226. {ok, Mods = [use_blue, use_red]} \
  227. = application:get_key($(APP), modules), \
  228. [{module, M} = code:load_file(M) || M <- Mods], \
  229. halt()"
  230. core-app-hrl-recursive: build clean-core-app-hrl-recursive
  231. $i "Bootstrap a new OTP library named $(APP)"
  232. $t mkdir $(APP)/
  233. $t cp ../erlang.mk $(APP)/
  234. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  235. $i "Generate .hrl files"
  236. $t mkdir $(APP)/include/
  237. $t touch $(APP)/include/blue.hrl $(APP)/include/pill.hrl
  238. $t echo "-include(\"pill.hrl\")." > $(APP)/include/red.hrl
  239. $i "Generate .erl files dependent from headers"
  240. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  241. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  242. $i "Build the application"
  243. $t $(MAKE) -C $(APP) $v
  244. $i "Check that all compiled files exist"
  245. $t test -f $(APP)/$(APP).d
  246. $t test -f $(APP)/ebin/$(APP).app
  247. $t test -f $(APP)/ebin/use_blue.beam
  248. $t test -f $(APP)/ebin/use_red.beam
  249. $i "Check that the application was compiled correctly"
  250. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  251. ok = application:start($(APP)), \
  252. {ok, Mods = [use_blue, use_red]} \
  253. = application:get_key($(APP), modules), \
  254. [{module, M} = code:load_file(M) || M <- Mods], \
  255. halt()"
  256. $i "Touch the deepest .hrl file; check that only required files are rebuilt"
  257. # The use_red.erl gets touched because of its dependency to red.hrl and pill.hrl.
  258. $t printf "%s\n" \
  259. $(APP)/$(APP).d \
  260. $(APP)/ebin/$(APP).app \
  261. $(APP)/ebin/use_red.beam \
  262. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  263. $t touch $(APP)/include/pill.hrl
  264. $t $(MAKE) -C $(APP) $v
  265. $t find $(APP) -type f -newer $(APP)/include/pill.hrl | sort | diff $(APP)/EXPECT -
  266. $t rm $(APP)/EXPECT
  267. $i "Check that the application was compiled correctly"
  268. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  269. ok = application:start($(APP)), \
  270. {ok, Mods = [use_blue, use_red]} \
  271. = application:get_key($(APP), modules), \
  272. [{module, M} = code:load_file(M) || M <- Mods], \
  273. halt()"
  274. $i "Clean the application"
  275. $t $(MAKE) -C $(APP) clean $v
  276. $i "Check that source files still exist"
  277. $t test -f $(APP)/Makefile
  278. $t test -f $(APP)/erlang.mk
  279. $t test -f $(APP)/include/blue.hrl
  280. $t test -f $(APP)/include/pill.hrl
  281. $t test -f $(APP)/include/red.hrl
  282. $t test -f $(APP)/src/$(APP).app.src
  283. $t test -f $(APP)/src/use_blue.erl
  284. $t test -f $(APP)/src/use_red.erl
  285. $i "Check that all build artifacts are removed"
  286. $t test ! -e $(APP)/$(APP).d
  287. $t test ! -e $(APP)/ebin/
  288. $i "Build the application again"
  289. $t $(MAKE) -C $(APP) $v
  290. $i "Check that all compiled files exist"
  291. $t test -f $(APP)/$(APP).d
  292. $t test -f $(APP)/ebin/$(APP).app
  293. $t test -f $(APP)/ebin/use_blue.beam
  294. $t test -f $(APP)/ebin/use_red.beam
  295. $i "Check that the application was compiled correctly"
  296. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  297. ok = application:start($(APP)), \
  298. {ok, Mods = [use_blue, use_red]} \
  299. = application:get_key($(APP), modules), \
  300. [{module, M} = code:load_file(M) || M <- Mods], \
  301. halt()"
  302. core-app-mib: build clean-core-app-mib
  303. $i "Bootstrap a new OTP library named $(APP)"
  304. $t mkdir $(APP)/
  305. $t cp ../erlang.mk $(APP)/
  306. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  307. $i "Download .mib files from Erlang/OTP"
  308. $t mkdir $(APP)/mibs/
  309. $t curl -s -o $(APP)/mibs/EX1-MIB.mib $(OTP_MASTER)/lib/snmp/examples/ex1/EX1-MIB.mib
  310. $t curl -s -o $(APP)/mibs/OTP-REG.mib $(OTP_MASTER)/lib/otp_mibs/mibs/OTP-REG.mib
  311. $i "Generate .erl files dependent from headers generated by .mib files"
  312. $t printf "%s\n" "-module(use_v1)." "-include(\"EX1-MIB.hrl\")." > $(APP)/src/use_v1.erl
  313. $t printf "%s\n" "-module(use_v2)." "-include(\"OTP-REG.hrl\")." > $(APP)/src/use_v2.erl
  314. $i "Build the application"
  315. $t $(MAKE) -C $(APP) $v
  316. $i "Check that all compiled files exist"
  317. $t test -f $(APP)/$(APP).d
  318. $t test -f $(APP)/ebin/$(APP).app
  319. $t test -f $(APP)/ebin/use_v1.beam
  320. $t test -f $(APP)/ebin/use_v2.beam
  321. $t test -f $(APP)/include/EX1-MIB.hrl
  322. $t test -f $(APP)/include/OTP-REG.hrl
  323. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  324. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  325. $i "Check that the application was compiled correctly"
  326. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  327. ok = application:start($(APP)), \
  328. {ok, Mods = [use_v1, use_v2]} \
  329. = application:get_key($(APP), modules), \
  330. [{module, M} = code:load_file(M) || M <- Mods], \
  331. halt()"
  332. $i "Touch one .mib file; check that only required files are rebuilt"
  333. # The use_v1.erl gets touched because of its dependency to EX1-MIB.hrl.
  334. $t printf "%s\n" \
  335. $(APP)/$(APP).d \
  336. $(APP)/ebin/$(APP).app \
  337. $(APP)/ebin/use_v1.beam \
  338. $(APP)/include/EX1-MIB.hrl \
  339. $(APP)/priv/mibs/EX1-MIB.bin \
  340. $(APP)/src/use_v1.erl | sort > $(APP)/EXPECT
  341. $t touch $(APP)/mibs/EX1-MIB.mib
  342. $t $(MAKE) -C $(APP) $v
  343. $t find $(APP) -type f -newer $(APP)/mibs/EX1-MIB.mib | sort | diff $(APP)/EXPECT -
  344. $t rm $(APP)/EXPECT
  345. $i "Check that the application was compiled correctly"
  346. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  347. ok = application:start($(APP)), \
  348. {ok, Mods = [use_v1, use_v2]} \
  349. = application:get_key($(APP), modules), \
  350. [{module, M} = code:load_file(M) || M <- Mods], \
  351. halt()"
  352. $i "Clean the application"
  353. $t $(MAKE) -C $(APP) clean $v
  354. $i "Check that source files still exist"
  355. $t test -f $(APP)/Makefile
  356. $t test -f $(APP)/erlang.mk
  357. $t test -d $(APP)/include/
  358. $t test -f $(APP)/mibs/EX1-MIB.mib
  359. $t test -f $(APP)/mibs/OTP-REG.mib
  360. $t test -f $(APP)/src/$(APP).app.src
  361. $t test -f $(APP)/src/use_v1.erl
  362. $t test -f $(APP)/src/use_v2.erl
  363. $i "Check that all build artifacts are removed, including intermediates"
  364. $t test ! -e $(APP)/$(APP).d
  365. $t test ! -e $(APP)/ebin/
  366. $t test ! -e $(APP)/include/EX1-MIB.hrl
  367. $t test ! -e $(APP)/include/OTP-REG.hrl
  368. $t test ! -e $(APP)/priv/mibs/
  369. $i "Build the application again"
  370. $t $(MAKE) -C $(APP) $v
  371. $i "Check that all compiled files exist"
  372. $t test -f $(APP)/$(APP).d
  373. $t test -f $(APP)/ebin/$(APP).app
  374. $t test -f $(APP)/ebin/use_v1.beam
  375. $t test -f $(APP)/ebin/use_v2.beam
  376. $t test -f $(APP)/include/EX1-MIB.hrl
  377. $t test -f $(APP)/include/OTP-REG.hrl
  378. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  379. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  380. $i "Check that the application was compiled correctly"
  381. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  382. ok = application:start($(APP)), \
  383. {ok, Mods = [use_v1, use_v2]} \
  384. = application:get_key($(APP), modules), \
  385. [{module, M} = code:load_file(M) || M <- Mods], \
  386. halt()"
  387. core-app-xrl: build clean-core-app-xrl
  388. $i "Bootstrap a new OTP library named $(APP)"
  389. $t mkdir $(APP)/
  390. $t cp ../erlang.mk $(APP)/
  391. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  392. $i "Download .xrl files from Robert"
  393. $t curl -s -o $(APP)/src/erlang_scan.xrl https://raw.githubusercontent.com/rvirding/leex/master/examples/erlang_scan.xrl
  394. $t curl -s -o $(APP)/src/lfe_scan.xrl https://raw.githubusercontent.com/rvirding/leex/master/examples/lfe_scan.xrl
  395. $i "Generate unrelated .erl files"
  396. $t echo "-module(boy)." > $(APP)/src/boy.erl
  397. $t echo "-module(girl)." > $(APP)/src/girl.erl
  398. $i "Disable warnings; our test .xrl files aren't perfect"
  399. $t echo "ERLC_OPTS=+debug_info" >> $(APP)/Makefile
  400. $i "Build the application"
  401. $t $(MAKE) -C $(APP) $v
  402. $i "Check that all compiled files exist"
  403. $t test -f $(APP)/$(APP).d
  404. $t test -f $(APP)/ebin/$(APP).app
  405. $t test -f $(APP)/ebin/boy.beam
  406. $t test -f $(APP)/ebin/erlang_scan.beam
  407. $t test -f $(APP)/ebin/girl.beam
  408. $t test -f $(APP)/ebin/lfe_scan.beam
  409. $t test -f $(APP)/src/erlang_scan.erl
  410. $t test -f $(APP)/src/lfe_scan.erl
  411. $i "Check that the application was compiled correctly"
  412. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  413. ok = application:start($(APP)), \
  414. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  415. = application:get_key($(APP), modules), \
  416. [{module, M} = code:load_file(M) || M <- Mods], \
  417. halt()"
  418. $i "Touch one .xrl file; check that only required files are rebuilt"
  419. $t printf "%s\n" \
  420. $(APP)/$(APP).d \
  421. $(APP)/ebin/$(APP).app \
  422. $(APP)/ebin/erlang_scan.beam \
  423. $(APP)/src/erlang_scan.erl | sort > $(APP)/EXPECT
  424. $t touch $(APP)/src/erlang_scan.xrl
  425. $t $(MAKE) -C $(APP) $v
  426. $t find $(APP) -type f -newer $(APP)/src/erlang_scan.xrl | sort | diff $(APP)/EXPECT -
  427. $t rm $(APP)/EXPECT
  428. $i "Check that the application was compiled correctly"
  429. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  430. ok = application:start($(APP)), \
  431. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  432. = application:get_key($(APP), modules), \
  433. [{module, M} = code:load_file(M) || M <- Mods], \
  434. halt()"
  435. $i "Clean the application"
  436. $t $(MAKE) -C $(APP) clean $v
  437. $i "Check that source files still exist"
  438. $t test -f $(APP)/Makefile
  439. $t test -f $(APP)/erlang.mk
  440. $t test -f $(APP)/src/$(APP).app.src
  441. $t test -f $(APP)/src/boy.erl
  442. $t test -f $(APP)/src/erlang_scan.xrl
  443. $t test -f $(APP)/src/girl.erl
  444. $t test -f $(APP)/src/lfe_scan.xrl
  445. $i "Check that all build artifacts are removed, including intermediates"
  446. $t test ! -e $(APP)/$(APP).d
  447. $t test ! -e $(APP)/ebin/
  448. $t test ! -e $(APP)/src/erlang_scan.erl
  449. $t test ! -e $(APP)/src/lfe_scan.erl
  450. $i "Build the application again"
  451. $t $(MAKE) -C $(APP) $v
  452. $i "Check that all compiled files exist"
  453. $t test -f $(APP)/$(APP).d
  454. $t test -f $(APP)/ebin/$(APP).app
  455. $t test -f $(APP)/ebin/boy.beam
  456. $t test -f $(APP)/ebin/erlang_scan.beam
  457. $t test -f $(APP)/ebin/girl.beam
  458. $t test -f $(APP)/ebin/lfe_scan.beam
  459. $t test -f $(APP)/src/erlang_scan.erl
  460. $t test -f $(APP)/src/lfe_scan.erl
  461. $i "Check that the application was compiled correctly"
  462. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  463. ok = application:start($(APP)), \
  464. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  465. = application:get_key($(APP), modules), \
  466. [{module, M} = code:load_file(M) || M <- Mods], \
  467. halt()"
  468. core-app-xrl-include: build clean-core-app-xrl-include
  469. $i "Bootstrap a new OTP library named $(APP)"
  470. $t mkdir $(APP)/
  471. $t cp ../erlang.mk $(APP)/
  472. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  473. $i "Download a .xrl file with numerous includes from Gordon"
  474. $t curl -s -o $(APP)/src/xfl_lexer.xrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/formula_engine-1.0/priv/xfl_lexer.xrl
  475. $t curl -s -o $(APP)/src/errvals.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/errvals.hrl
  476. $t curl -s -o $(APP)/src/muin_proc_dict.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/muin_proc_dict.hrl
  477. $t curl -s -o $(APP)/src/muin_records.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/muin_records.hrl
  478. $t curl -s -o $(APP)/src/typechecks.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/typechecks.hrl
  479. $i "Generate unrelated .erl files"
  480. $t echo "-module(boy)." > $(APP)/src/boy.erl
  481. $t echo "-module(girl)." > $(APP)/src/girl.erl
  482. $i "Disable warnings; our test .xrl files aren't perfect"
  483. $t echo "ERLC_OPTS=+debug_info" >> $(APP)/Makefile
  484. $i "Build the application"
  485. $t $(MAKE) -C $(APP) $v
  486. $i "Check that all compiled files exist"
  487. $t test -f $(APP)/$(APP).d
  488. $t test -f $(APP)/ebin/$(APP).app
  489. $t test -f $(APP)/ebin/boy.beam
  490. $t test -f $(APP)/ebin/girl.beam
  491. $t test -f $(APP)/ebin/xfl_lexer.beam
  492. $t test -f $(APP)/src/xfl_lexer.erl
  493. $i "Check that the application was compiled correctly"
  494. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  495. ok = application:start($(APP)), \
  496. {ok, Mods = [boy, girl, xfl_lexer]} \
  497. = application:get_key($(APP), modules), \
  498. [{module, M} = code:load_file(M) || M <- Mods], \
  499. halt()"
  500. $i "Touch the .xrl file; check that only required files are rebuilt"
  501. $t printf "%s\n" \
  502. $(APP)/$(APP).d \
  503. $(APP)/ebin/$(APP).app \
  504. $(APP)/ebin/xfl_lexer.beam \
  505. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  506. $t touch $(APP)/src/xfl_lexer.xrl
  507. $t $(MAKE) -C $(APP) $v
  508. $t find $(APP) -type f -newer $(APP)/src/xfl_lexer.xrl | sort | diff $(APP)/EXPECT -
  509. $t rm $(APP)/EXPECT
  510. $i "Check that the application was compiled correctly"
  511. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  512. ok = application:start($(APP)), \
  513. {ok, Mods = [boy, girl, xfl_lexer]} \
  514. = application:get_key($(APP), modules), \
  515. [{module, M} = code:load_file(M) || M <- Mods], \
  516. halt()"
  517. $i "Touch a .hrl file included directly; check that only required files are rebuilt"
  518. $t printf "%s\n" \
  519. $(APP)/$(APP).d \
  520. $(APP)/ebin/$(APP).app \
  521. $(APP)/ebin/xfl_lexer.beam \
  522. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  523. $t touch $(APP)/src/typechecks.hrl
  524. $t $(MAKE) -C $(APP) $v
  525. $t find $(APP) -type f -newer $(APP)/src/typechecks.hrl | sort | diff $(APP)/EXPECT -
  526. $t rm $(APP)/EXPECT
  527. $i "Check that the application was compiled correctly"
  528. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  529. ok = application:start($(APP)), \
  530. {ok, Mods = [boy, girl, xfl_lexer]} \
  531. = application:get_key($(APP), modules), \
  532. [{module, M} = code:load_file(M) || M <- Mods], \
  533. halt()"
  534. $i "Touch a .hrl file included indirectly; check that only required files are rebuilt"
  535. $t printf "%s\n" \
  536. $(APP)/$(APP).d \
  537. $(APP)/ebin/$(APP).app \
  538. $(APP)/ebin/xfl_lexer.beam \
  539. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  540. $t touch $(APP)/src/errvals.hrl
  541. $t $(MAKE) -C $(APP) $v
  542. $t find $(APP) -type f -newer $(APP)/src/errvals.hrl | sort | diff $(APP)/EXPECT -
  543. $t rm $(APP)/EXPECT
  544. $i "Check that the application was compiled correctly"
  545. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  546. ok = application:start($(APP)), \
  547. {ok, Mods = [boy, girl, xfl_lexer]} \
  548. = application:get_key($(APP), modules), \
  549. [{module, M} = code:load_file(M) || M <- Mods], \
  550. halt()"
  551. $i "Clean the application"
  552. $t $(MAKE) -C $(APP) clean $v
  553. $i "Check that source files still exist"
  554. $t test -f $(APP)/Makefile
  555. $t test -f $(APP)/erlang.mk
  556. $t test -f $(APP)/src/$(APP).app.src
  557. $t test -f $(APP)/src/boy.erl
  558. $t test -f $(APP)/src/girl.erl
  559. $t test -f $(APP)/src/errvals.hrl
  560. $t test -f $(APP)/src/muin_proc_dict.hrl
  561. $t test -f $(APP)/src/muin_records.hrl
  562. $t test -f $(APP)/src/typechecks.hrl
  563. $t test -f $(APP)/src/xfl_lexer.xrl
  564. $i "Check that all build artifacts are removed, including intermediates"
  565. $t test ! -e $(APP)/$(APP).d
  566. $t test ! -e $(APP)/ebin/
  567. $t test ! -e $(APP)/src/xfl_lexer.erl
  568. $i "Build the application again"
  569. $t $(MAKE) -C $(APP) $v
  570. $i "Check that all compiled files exist"
  571. $t test -f $(APP)/$(APP).d
  572. $t test -f $(APP)/ebin/$(APP).app
  573. $t test -f $(APP)/ebin/boy.beam
  574. $t test -f $(APP)/ebin/girl.beam
  575. $t test -f $(APP)/ebin/xfl_lexer.beam
  576. $t test -f $(APP)/src/xfl_lexer.erl
  577. $i "Check that the application was compiled correctly"
  578. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  579. ok = application:start($(APP)), \
  580. {ok, Mods = [boy, girl, xfl_lexer]} \
  581. = application:get_key($(APP), modules), \
  582. [{module, M} = code:load_file(M) || M <- Mods], \
  583. halt()"
  584. core-app-yrl: build clean-core-app-yrl
  585. $i "Bootstrap a new OTP library named $(APP)"
  586. $t mkdir $(APP)/
  587. $t cp ../erlang.mk $(APP)/
  588. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  589. $i "Download .yrl files from Erlang/OTP"
  590. $t curl -s -o $(APP)/src/xmerl_xpath_parse.yrl $(OTP_MASTER)/lib/xmerl/src/xmerl_xpath_parse.yrl
  591. $t curl -s -o $(APP)/src/xref_parser.yrl $(OTP_MASTER)/lib/tools/src/xref_parser.yrl
  592. $i "Generate unrelated .erl files"
  593. $t echo "-module(boy)." > $(APP)/src/boy.erl
  594. $t echo "-module(girl)." > $(APP)/src/girl.erl
  595. $i "Build the application"
  596. $t $(MAKE) -C $(APP) $v
  597. $i "Check that all compiled files exist"
  598. $t test -f $(APP)/$(APP).d
  599. $t test -f $(APP)/ebin/$(APP).app
  600. $t test -f $(APP)/ebin/boy.beam
  601. $t test -f $(APP)/ebin/girl.beam
  602. $t test -f $(APP)/ebin/xmerl_xpath_parse.beam
  603. $t test -f $(APP)/ebin/xref_parser.beam
  604. $t test -f $(APP)/src/xmerl_xpath_parse.erl
  605. $t test -f $(APP)/src/xref_parser.erl
  606. $i "Check that the application was compiled correctly"
  607. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  608. ok = application:start($(APP)), \
  609. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  610. = application:get_key($(APP), modules), \
  611. [{module, M} = code:load_file(M) || M <- Mods], \
  612. halt()"
  613. $i "Touch one .yrl file; check that only required files are rebuilt"
  614. $t printf "%s\n" \
  615. $(APP)/$(APP).d \
  616. $(APP)/ebin/$(APP).app \
  617. $(APP)/ebin/xref_parser.beam \
  618. $(APP)/src/xref_parser.erl | sort > $(APP)/EXPECT
  619. $t touch $(APP)/src/xref_parser.yrl
  620. $t $(MAKE) -C $(APP) $v
  621. $t find $(APP) -type f -newer $(APP)/src/xref_parser.yrl | sort | diff $(APP)/EXPECT -
  622. $t rm $(APP)/EXPECT
  623. $i "Check that the application was compiled correctly"
  624. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  625. ok = application:start($(APP)), \
  626. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  627. = application:get_key($(APP), modules), \
  628. [{module, M} = code:load_file(M) || M <- Mods], \
  629. halt()"
  630. $i "Clean the application"
  631. $t $(MAKE) -C $(APP) clean $v
  632. $i "Check that source files still exist"
  633. $t test -f $(APP)/Makefile
  634. $t test -f $(APP)/erlang.mk
  635. $t test -f $(APP)/src/$(APP).app.src
  636. $t test -f $(APP)/src/boy.erl
  637. $t test -f $(APP)/src/girl.erl
  638. $t test -f $(APP)/src/xmerl_xpath_parse.yrl
  639. $t test -f $(APP)/src/xref_parser.yrl
  640. $i "Check that all build artifacts are removed, including intermediates"
  641. $t test ! -e $(APP)/$(APP).d
  642. $t test ! -e $(APP)/ebin/
  643. $t test ! -e $(APP)/src/xmerl_xpath_parse.erl
  644. $t test ! -e $(APP)/src/xref_parser.erl
  645. $i "Build the application again"
  646. $t $(MAKE) -C $(APP) $v
  647. $i "Check that all compiled files exist"
  648. $t test -f $(APP)/$(APP).d
  649. $t test -f $(APP)/ebin/$(APP).app
  650. $t test -f $(APP)/ebin/boy.beam
  651. $t test -f $(APP)/ebin/girl.beam
  652. $t test -f $(APP)/ebin/xmerl_xpath_parse.beam
  653. $t test -f $(APP)/ebin/xref_parser.beam
  654. $t test -f $(APP)/src/xmerl_xpath_parse.erl
  655. $t test -f $(APP)/src/xref_parser.erl
  656. $i "Check that the application was compiled correctly"
  657. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  658. ok = application:start($(APP)), \
  659. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  660. = application:get_key($(APP), modules), \
  661. [{module, M} = code:load_file(M) || M <- Mods], \
  662. halt()"
  663. clean-core-app: $(CORE_APP_CLEAN_TARGETS)
  664. $(CORE_APP_CLEAN_TARGETS):
  665. $t rm -rf $(APP_TO_CLEAN)/
  666. # Core: Erlang.mk upgrade.
  667. CORE_UPGRADE_CASES = no-config custom-config renamed-config custom-build-dir
  668. CORE_UPGRADE_TARGETS = $(addprefix core-upgrade-,$(CORE_UPGRADE_CASES))
  669. CORE_UPGRADE_CLEAN_TARGETS = $(addprefix clean-,$(CORE_UPGRADE_TARGETS))
  670. .PHONY: core-upgrade $(CORE_UPGRADE_TARGETS) $(CORE_UPGRADE_CLEAN_TARGETS)
  671. core-upgrade: $(CORE_UPGRADE_TARGETS)
  672. core-upgrade-no-config: build clean-core-upgrade-no-config
  673. $i "Bootstrap a new OTP library named $(APP)"
  674. $t mkdir $(APP)/
  675. $t cp ../erlang.mk $(APP)/
  676. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  677. $i "Append a rule to the Erlang.mk file for testing purposes"
  678. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  679. $i "Check that the test rule works as intended"
  680. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  681. $i "Upgrade Erlang.mk"
  682. $t $(MAKE) -C $(APP) erlang-mk $v
  683. $i "Check that the rule is gone"
  684. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  685. core-upgrade-custom-config: build clean-core-upgrade-custom-config
  686. $i "Bootstrap a new OTP library named $(APP)"
  687. $t mkdir $(APP)/
  688. $t cp ../erlang.mk $(APP)/
  689. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  690. $i "Create a custom build.config file without plugins"
  691. $t echo "core/*" > $(APP)/build.config
  692. $i "Upgrade Erlang.mk"
  693. $t $(MAKE) -C $(APP) erlang-mk $v
  694. $i "Check that the bootstrap plugin is gone"
  695. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  696. core-upgrade-renamed-config: build clean-core-upgrade-renamed-config
  697. $i "Bootstrap a new OTP library named $(APP)"
  698. $t mkdir $(APP)/
  699. $t cp ../erlang.mk $(APP)/
  700. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  701. $i "Create a custom build.config file without plugins; name it my.build.config"
  702. $t echo "core/*" > $(APP)/my.build.config
  703. $i "Set ERLANG_MK_BUILD_CONFIG=my.build.config in the Makefile"
  704. $t echo "ERLANG_MK_BUILD_CONFIG = my.build.config" >> $(APP)/Makefile
  705. $i "Upgrade Erlang.mk"
  706. $t $(MAKE) -C $(APP) erlang-mk $v
  707. $i "Check that the bootstrap plugin is gone"
  708. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  709. core-upgrade-custom-build-dir: build clean-core-upgrade-custom-build-dir
  710. $i "Bootstrap a new OTP library named $(APP)"
  711. $t mkdir $(APP)/
  712. $t cp ../erlang.mk $(APP)/
  713. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  714. $i "Append a rule to the Erlang.mk file for testing purposes"
  715. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  716. $i "Check that the test rule works as intended"
  717. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  718. $i "Create the custom build directory"
  719. $t mkdir $(APP)/custom/
  720. $t test -d $(APP)/custom/
  721. $i "Upgrade Erlang.mk with a custom build directory"
  722. $t ERLANG_MK_BUILD_DIR=custom $(MAKE) -C $(APP) erlang-mk $v
  723. $i "Check that the rule is gone"
  724. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  725. $i "Check that the custom build directory is gone"
  726. $t test ! -d $(APP)/custom/
  727. clean-core-upgrade: $(CORE_UPGRADE_CLEAN_TARGETS)
  728. $(CORE_UPGRADE_CLEAN_TARGETS):
  729. $t rm -rf $(APP_TO_CLEAN)/
  730. # Bootstrap plugin.
  731. BOOTSTRAP_CASES = app lib rel templates
  732. BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
  733. BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
  734. .PHONY: bootstrap $(BOOTSTRAP_TARGETS) $(BOOTSTRAP_CLEAN_TARGETS)
  735. bootstrap: $(BOOTSTRAP_TARGETS)
  736. bootstrap-app: build clean-bootstrap-app
  737. $i "Bootstrap a new OTP application named $(APP)"
  738. $t mkdir $(APP)/
  739. $t cp ../erlang.mk $(APP)/
  740. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  741. $i "Check that all bootstrapped files exist"
  742. $t test -f $(APP)/Makefile
  743. $t test -f $(APP)/src/$(APP).app.src
  744. $t test -f $(APP)/src/$(APP)_app.erl
  745. $t test -f $(APP)/src/$(APP)_sup.erl
  746. $i "Build the application"
  747. $t $(MAKE) -C $(APP) $v
  748. $i "Check that all compiled files exist"
  749. $t test -f $(APP)/ebin/$(APP).app
  750. $t test -f $(APP)/ebin/$(APP)_app.beam
  751. $t test -f $(APP)/ebin/$(APP)_sup.beam
  752. $i "Check that the application was compiled correctly"
  753. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  754. ok = application:start($(APP)), \
  755. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  756. {module, $(APP)_app} = code:load_file($(APP)_app), \
  757. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  758. halt()"
  759. bootstrap-lib: build clean-bootstrap-lib
  760. $i "Bootstrap a new OTP library named $(APP)"
  761. $t mkdir $(APP)/
  762. $t cp ../erlang.mk $(APP)/
  763. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  764. $i "Check that all bootstrapped files exist"
  765. $t test -f $(APP)/Makefile
  766. $t test -f $(APP)/src/$(APP).app.src
  767. $i "Build the application"
  768. $t $(MAKE) -C $(APP) $v
  769. $i "Check that all compiled files exist"
  770. $t test -f $(APP)/ebin/$(APP).app
  771. $i "Check that the application was compiled correctly"
  772. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  773. ok = application:start($(APP)), \
  774. {ok, []} = application:get_key($(APP), modules), \
  775. halt()"
  776. bootstrap-rel: build clean-bootstrap-rel
  777. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  778. $t mkdir $(APP)/
  779. $t cp ../erlang.mk $(APP)/
  780. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  781. $i "Check that all bootstrapped files exist"
  782. $t test -f $(APP)/Makefile
  783. $t test -f $(APP)/relx.config
  784. $t test -f $(APP)/rel/sys.config
  785. $t test -f $(APP)/rel/vm.args
  786. $t test -f $(APP)/src/$(APP).app.src
  787. $t test -f $(APP)/src/$(APP)_app.erl
  788. $t test -f $(APP)/src/$(APP)_sup.erl
  789. $i "Build the application and the release"
  790. $t $(MAKE) -C $(APP) $v
  791. $i "Check that all compiled files exist"
  792. $t test -f $(APP)/ebin/$(APP).app
  793. $t test -f $(APP)/ebin/$(APP)_app.beam
  794. $t test -f $(APP)/ebin/$(APP)_sup.beam
  795. $i "Check that the release was generated"
  796. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  797. $i "Check that the release can be started and stopped"
  798. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  799. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  800. $i "Check that there's no erl_crash.dump file"
  801. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  802. bootstrap-templates: build clean-bootstrap-templates
  803. $i "Bootstrap a new OTP library named $(APP)"
  804. $t mkdir $(APP)/
  805. $t cp ../erlang.mk $(APP)/
  806. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  807. $i "Check that we can get the list of templates"
  808. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  809. $i "Generate one of each template"
  810. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  811. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  812. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  813. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  814. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  815. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  816. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  817. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  818. # Here we disable warnings because templates contain missing behaviors.
  819. $i "Build the application"
  820. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  821. $i "Check that all compiled files exist"
  822. $t test -f $(APP)/ebin/$(APP).app
  823. $t test -f $(APP)/ebin/my_fsm.beam
  824. $t test -f $(APP)/ebin/my_server.beam
  825. $t test -f $(APP)/ebin/my_sup.beam
  826. $i "Check that all the modules can be loaded"
  827. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  828. ok = application:start($(APP)), \
  829. {ok, Mods = [my_fsm, my_http, my_loop, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  830. = application:get_key($(APP), modules), \
  831. [{module, M} = code:load_file(M) || M <- Mods], \
  832. halt()"
  833. clean-bootstrap: $(BOOTSTRAP_CLEAN_TARGETS)
  834. $(BOOTSTRAP_CLEAN_TARGETS):
  835. $t rm -rf $(APP_TO_CLEAN)/
  836. ########################################
  837. # Legacy tests.
  838. app: app1
  839. $i "app: Testing the 'app' target."
  840. $t $(MAKE) -C app1 app $v
  841. $i "Checking the modules line in the generated .app file."
  842. $t [ `grep -E "{modules, *\['m'\]}" app1/ebin/app1.app | wc -l` -eq 1 ]
  843. $t [ -e app1/ebin/m.beam ]
  844. $i "Checking that '$(MAKE) clean-app' deletes ebin."
  845. $t $(MAKE) -C app1 clean-app $v
  846. $t [ ! -e app1/ebin ]
  847. $i "Checking that '$(MAKE) app' returns non-zero on compile errors."
  848. $t printf "%s\n" \
  849. "-module(syntax_error)." \
  850. "foo lorem_ipsum dolor sit amet." \
  851. > app1/src/syntax_error.erl
  852. $t if $(MAKE) -C app1 app $v ; then false ; fi
  853. $t rm app1/src/syntax_error.erl
  854. $i "Test 'app' passed."
  855. ct: app1
  856. $i "ct: Testing ct and related targets."
  857. $i "Setting up test suite."
  858. $t mkdir -p app1/test
  859. $t printf "%s\n" \
  860. "-module(m_SUITE)." \
  861. "-export([all/0, testcase1/1])." \
  862. "all() -> [testcase1]." \
  863. "testcase1(_) -> 2 = m:succ(1)." \
  864. > app1/test/m_SUITE.erl
  865. $t $(MAKE) -C app1 ct $v
  866. $i "Checking files created by '$(MAKE) ct'."
  867. $t [ -e app1/test/m_SUITE.beam ]
  868. $t [ -e app1/ebin/m.beam ]
  869. $t [ -e app1/logs ]
  870. $i "Checking that '$(MAKE) clean' does not delete logs."
  871. $t $(MAKE) -C app1 clean $v
  872. $t [ -e app1/logs ]
  873. $i "Testing target 'ct-mysuite' where mysuite_SUITE is a test suite."
  874. $t $(MAKE) -C app1 ct-m $v
  875. $i "Checking that '$(MAKE) ct' returns non-zero for a failing suite."
  876. $t printf "%s\n" \
  877. "-module(failing_SUITE)." \
  878. "-export([all/0, testcase1/1])." \
  879. "all() -> [testcase1]." \
  880. "testcase1(_) -> 42 = m:succ(1)." \
  881. > app1/test/failing_SUITE.erl
  882. $t if $(MAKE) -C app1 ct-failing $v ; then false ; fi
  883. $i "Checking that '$(MAKE) distclean-ct' deletes logs."
  884. $t $(MAKE) -C app1 distclean-ct $v
  885. $t [ ! -e app1/logs ]
  886. $t [ -e app1/ebin/m.beam ]
  887. $i "Cleaning up test data."
  888. $t rm -rf app1/test
  889. $i "Test 'ct' passed."
  890. eunit: app1
  891. $i "eunit: Testing the 'eunit' target."
  892. $i "Running eunit test case inside module src/t.erl"
  893. $t $(call create-module-t)
  894. $t $(MAKE) -C app1 distclean $v
  895. $t $(MAKE) -C app1 eunit $v
  896. $i "Checking that the eunit test in module t."
  897. $t echo t | cmp app1/test-eunit.log -
  898. $t rm app1/test-eunit.log
  899. $i "Running eunit tests in a separate directory."
  900. $t mkdir -p app1/eunit
  901. $t printf '%s\n' \
  902. '-module(t_tests).' \
  903. '-include_lib("eunit/include/eunit.hrl").' \
  904. 'succ_test() ->' \
  905. ' ?assertEqual(2, t:succ(1)),' \
  906. ' os:cmd("echo t_tests >> test-eunit.log").' \
  907. > app1/eunit/t_tests.erl
  908. $t printf '%s\n' \
  909. '-module(x_tests).' \
  910. '-include_lib("eunit/include/eunit.hrl").' \
  911. 'succ_test() ->' \
  912. ' ?assertEqual(2, t:succ(1)),' \
  913. ' os:cmd("echo x_tests >> test-eunit.log").' \
  914. > app1/eunit/x_tests.erl
  915. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  916. $t $(MAKE) -C app1 eunit TEST_DIR=eunit $v
  917. $i "Checking that '$(MAKE) eunit' didn't run the tests in t_tests twice, etc."
  918. $t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
  919. $t rm app1/test-eunit.log
  920. $i "Checking that '$(MAKE) eunit' returns non-zero for a failing test."
  921. $t rm -f app1/eunit/*
  922. $t printf "%s\n" \
  923. "-module(t_tests)." \
  924. '-include_lib("eunit/include/eunit.hrl").' \
  925. "succ_test() ->" \
  926. " ?assertEqual(42, t:succ(1))." \
  927. > app1/eunit/t_tests.erl
  928. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  929. $t if $(MAKE) -C app1 eunit TEST_DIR=eunit $v ; then false ; fi
  930. $t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
  931. $i "Test 'eunit' passed."
  932. # TODO: do coverage for 'tests' instead of 'eunit ct' when triq is fixed
  933. tests-cover: app1
  934. $i "tests-cover: Testing 'eunit' and 'ct' with COVER=1"
  935. $i "Setting up eunit and ct suites."
  936. $t $(call create-module-t)
  937. $t mkdir -p app1/test
  938. $t printf "%s\n" \
  939. "-module(m_SUITE)." \
  940. "-export([all/0, testcase1/1])." \
  941. "all() -> [testcase1]." \
  942. "testcase1(_) -> 2 = m:succ(1)." \
  943. > app1/test/m_SUITE.erl
  944. $i "Running tests with coverage analysis."
  945. $t $(MAKE) -C app1 eunit ct COVER=1 $v
  946. $t [ -e app1/test-eunit.log ]
  947. $t [ -e app1/eunit.coverdata ]
  948. $t [ -e app1/ct.coverdata ]
  949. $i "Generating coverage report."
  950. $t $(MAKE) -C app1 cover-report COVER=1 $v
  951. $t [ -e app1/cover/m.COVER.html ]
  952. $t [ -e app1/cover/t.COVER.html ]
  953. $t [ -e app1/cover/index.html ]
  954. $i "Checking combined coverage from eunit and ct."
  955. $t [ `grep 'Total: 100%' app1/cover/index.html | wc -l` -eq 1 ]
  956. $i "Checking that cover-report-clean removes cover report."
  957. $t $(MAKE) -C app1 cover-report-clean $v
  958. $t [ ! -e app1/cover ]
  959. $i "Checking that coverdata-clean removes cover data."
  960. $t $(MAKE) -C app1 coverdata-clean $v
  961. $t [ ! -e app1/eunit.coverdata ]
  962. @# clean up
  963. $t rm -rf app1/src/t.erl app1/test app1/test-eunit.log
  964. $t $(MAKE) -C app1 clean $v
  965. $i "Test 'tests-cover' passed."
  966. docs: app1
  967. $i "docs: Testing EDoc including DOC_DEPS."
  968. $t printf "%s\n" \
  969. "PROJECT = app1" \
  970. "DOC_DEPS = edown" \
  971. "dep_edown = git https://github.com/uwiger/edown.git 0.7" \
  972. "EDOC_OPTS = {doclet, edown_doclet}" \
  973. "include erlang.mk" \
  974. "distclean:: distclean-doc-md" \
  975. "distclean-doc-md:" \
  976. " rm -rf doc/*.md" \
  977. > app1/Makefile-doc
  978. $i "Downloading doc deps (edown) and building docs."
  979. $t $(MAKE) -C app1 -f Makefile-doc docs $v
  980. $i "Checking that '$(MAKE) docs' using edown generated a markdown file."
  981. $t [ -e app1/doc/m.md ]
  982. $i "Checking that '$(MAKE) distclean' deletes all generated doc files."
  983. $t $(MAKE) -C app1 -f Makefile-doc distclean $v
  984. $t [ "`ls app1/doc/`" = "" ]
  985. $i "Cleaning up test data."
  986. $t rm app1/Makefile-doc
  987. $i "Test 'docs' passed."
  988. define app1_setup
  989. $i "Setting up app."
  990. $t mkdir -p app1
  991. $t cd .. && $(MAKE)
  992. $t cp ../erlang.mk app1/
  993. $t $(MAKE) -C app1 -f erlang.mk bootstrap-lib
  994. $t printf "%s\n" \
  995. "-module(m)." \
  996. "-export([succ/1])." \
  997. "succ(N) -> N + 1." \
  998. > app1/src/m.erl
  999. endef
  1000. define pkg_test_target
  1001. pkg-$(1)-clean:
  1002. $t rm -rf app1 erl_crash.dump
  1003. pkg-$(1)-app1:
  1004. $(call app1_setup)
  1005. # Running 'make' twice to make sure it recompiles fine.
  1006. pkg-$(1): pkg-$(1)-clean pkg-$(1)-app1
  1007. $i
  1008. $i " pkgs: Checking that '$(1)' builds correctly"
  1009. $i
  1010. $t printf "%s\n" \
  1011. "PROJECT = app1" \
  1012. "DEPS = $(1)" \
  1013. "include erlang.mk" \
  1014. > app1/Makefile
  1015. $t \
  1016. if [ "$(1)" = "amqp_client" ]; then \
  1017. $(MAKE) -C app1 RABBITMQ_CLIENT_PATCH=1; \
  1018. elif [ "$(1)" = "rabbit" ]; then \
  1019. $(MAKE) -C app1 RABBITMQ_SERVER_PATCH=1; \
  1020. else \
  1021. $(MAKE) -C app1; \
  1022. fi; \
  1023. if [ $$$$? -ne 0 ]; then \
  1024. echo "$(1): make error" >> pkgs.log; \
  1025. else \
  1026. $(MAKE) -C app1; if [ $$$$? -ne 0 ]; then \
  1027. echo "$(1): re-make error" >> pkgs.log; \
  1028. else \
  1029. find . -type f -name erl_crash.dump; if [ $$$$? -ne 0 ]; then \
  1030. echo "$(1): erl_crash.dump found" >> pkgs.log; \
  1031. else \
  1032. erl +A0 -noinput -boot start_clean -pa app1/deps/*/ebin -eval " \
  1033. Apps = [list_to_atom(App) || \"app1/deps/\" ++ App \
  1034. <- filelib:wildcard(\"app1/deps/*\")], \
  1035. [begin \
  1036. io:format(\"Loading application ~p~n\", [App]), \
  1037. case application:load(App) of \
  1038. {error, _} -> ok; \
  1039. ok -> \
  1040. {ok, Mods} = application:get_key(App, modules), \
  1041. [try io:format(\" Loading module ~p~n\", [Mod]), \
  1042. {module, Mod} = code:load_file(Mod) \
  1043. catch C:R -> timer:sleep(500), erlang:C(R) \
  1044. end || Mod <- Mods] \
  1045. end \
  1046. end || App <- Apps], \
  1047. halt()."; if [ $$$$? -ne 0 ]; then \
  1048. echo "$(1): load error" >> pkgs.log; \
  1049. fi \
  1050. fi \
  1051. fi \
  1052. fi
  1053. endef
  1054. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  1055. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_test_target,$(pkg))))
  1056. pkgs: $(addprefix pkg-,$(PACKAGES))
  1057. @if [ -f pkgs.log ]; then \
  1058. echo "+-------------------------------+"; \
  1059. echo "| ERRORS WHILE TESTING PACKAGES |"; \
  1060. echo "+-------------------------------+"; \
  1061. cat pkgs.log; \
  1062. exit 33; \
  1063. fi
  1064. # Test application used for testing.
  1065. app1:
  1066. $(call app1_setup)
  1067. # Extra module in app1 used for testing eunit
  1068. define create-module-t
  1069. printf '%s\n' \
  1070. '-module(t).' \
  1071. '-export([succ/1]).' \
  1072. 'succ(N) -> N + 1.' \
  1073. '-ifdef(TEST).' \
  1074. '-include_lib("eunit/include/eunit.hrl").' \
  1075. 'succ_test() ->' \
  1076. ' ?assertEqual(2, succ(1)),' \
  1077. ' os:cmd("echo t >> test-eunit.log").' \
  1078. '-endif.' \
  1079. > app1/src/t.erl
  1080. endef