Makefile 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786
  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 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 error generate-erl generate-erl-include generate-erl-prepend hrl hrl-recursive mib no-makedep xrl xrl-include yrl yrl-include
  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 "Generate an unrelated .hrl file"
  75. $t mkdir $(APP)/include/
  76. $t touch $(APP)/include/unrelated.hrl
  77. $i "Build the application"
  78. $t $(MAKE) -C $(APP) $v
  79. $i "Check that all compiled files exist"
  80. $t test -f $(APP)/$(APP).d
  81. $t test -f $(APP)/ebin/$(APP).app
  82. $t test -f $(APP)/ebin/CAP.beam
  83. $t test -f $(APP)/ebin/Def.beam
  84. $t test -f $(APP)/ebin/use_cap.beam
  85. $t test -f $(APP)/ebin/use_def.beam
  86. $t test -f $(APP)/include/CAP.asn1db
  87. $t test -f $(APP)/include/CAP.hrl
  88. $t test -f $(APP)/include/Def.asn1db
  89. $t test -f $(APP)/include/Def.hrl
  90. $t test -f $(APP)/src/CAP.erl
  91. $t test -f $(APP)/src/Def.erl
  92. $i "Check that the application was compiled correctly"
  93. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  94. ok = application:start($(APP)), \
  95. {ok, Mods = ['CAP', 'Def', use_cap, use_def]} \
  96. = application:get_key($(APP), modules), \
  97. [{module, M} = code:load_file(M) || M <- Mods], \
  98. halt()"
  99. $i "Touch one .asn1 file; check that only required files are rebuilt"
  100. # The use_cap.erl gets touched because of its dependency to CAP.hrl.
  101. $t printf "%s\n" \
  102. $(APP)/$(APP).d \
  103. $(APP)/ebin/$(APP).app \
  104. $(APP)/ebin/CAP.beam \
  105. $(APP)/ebin/use_cap.beam \
  106. $(APP)/include/CAP.asn1db \
  107. $(APP)/include/CAP.hrl \
  108. $(APP)/src/CAP.erl \
  109. $(APP)/src/use_cap.erl | sort > $(APP)/EXPECT
  110. $t touch $(APP)/asn1/CAP.asn1
  111. $t $(MAKE) -C $(APP) $v
  112. $t find $(APP) -type f -newer $(APP)/asn1/CAP.asn1 | sort | diff $(APP)/EXPECT -
  113. $t rm $(APP)/EXPECT
  114. $i "Check that the application was compiled correctly"
  115. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  116. ok = application:start($(APP)), \
  117. {ok, Mods = ['CAP', 'Def', use_cap, use_def]} \
  118. = application:get_key($(APP), modules), \
  119. [{module, M} = code:load_file(M) || M <- Mods], \
  120. halt()"
  121. $i "Clean the application"
  122. $t $(MAKE) -C $(APP) clean $v
  123. $i "Check that source files still exist"
  124. $t test -f $(APP)/Makefile
  125. $t test -f $(APP)/erlang.mk
  126. $t test -f $(APP)/asn1/CAP.asn1
  127. $t test -f $(APP)/asn1/Def.asn1
  128. $t test -f $(APP)/include/unrelated.hrl
  129. $t test -f $(APP)/src/$(APP).app.src
  130. $t test -f $(APP)/src/use_cap.erl
  131. $t test -f $(APP)/src/use_def.erl
  132. $i "Check that all build artifacts are removed, including intermediates"
  133. $t test ! -e $(APP)/$(APP).d
  134. $t test ! -e $(APP)/ebin/
  135. $t test ! -e $(APP)/include/CAP.asn1db
  136. $t test ! -e $(APP)/include/CAP.hrl
  137. $t test ! -e $(APP)/include/Def.asn1db
  138. $t test ! -e $(APP)/include/Def.hrl
  139. $t test ! -e $(APP)/src/CAP.erl
  140. $t test ! -e $(APP)/src/Def.erl
  141. $i "Build the application again"
  142. $t $(MAKE) -C $(APP) $v
  143. $i "Check that all compiled files exist"
  144. $t test -f $(APP)/$(APP).d
  145. $t test -f $(APP)/ebin/$(APP).app
  146. $t test -f $(APP)/ebin/CAP.beam
  147. $t test -f $(APP)/ebin/Def.beam
  148. $t test -f $(APP)/ebin/use_cap.beam
  149. $t test -f $(APP)/ebin/use_def.beam
  150. $t test -f $(APP)/include/CAP.asn1db
  151. $t test -f $(APP)/include/CAP.hrl
  152. $t test -f $(APP)/include/Def.asn1db
  153. $t test -f $(APP)/include/Def.hrl
  154. $t test -f $(APP)/src/CAP.erl
  155. $t test -f $(APP)/src/Def.erl
  156. $i "Check that the application was compiled correctly"
  157. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  158. ok = application:start($(APP)), \
  159. {ok, Mods = ['CAP', 'Def', use_cap, use_def]} \
  160. = application:get_key($(APP), modules), \
  161. [{module, M} = code:load_file(M) || M <- Mods], \
  162. halt()"
  163. core-app-error: build clean-core-app-error
  164. $i "Bootstrap a new OTP library named $(APP)"
  165. $t mkdir $(APP)/
  166. $t cp ../erlang.mk $(APP)/
  167. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  168. $i "Generate a bad .erl files"
  169. $t touch $(APP)/src/breaking.erl
  170. $i "Generate unrelated .erl files"
  171. $t echo "-module(boy)." > $(APP)/src/boy.erl
  172. $t echo "-module(girl)." > $(APP)/src/girl.erl
  173. $i "Check that trying to build returns non-zero"
  174. $t if $(MAKE) -C $(APP) $v; then false; fi
  175. core-app-generate-erl: build clean-core-app-generate-erl
  176. $i "Bootstrap a new OTP library named $(APP)"
  177. $t mkdir $(APP)/
  178. $t cp ../erlang.mk $(APP)/
  179. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  180. $i "Create a fake script file to be used as dependency"
  181. $t touch $(APP)/script.sh
  182. $i "Append rules to the Makefile to generate a .erl module"
  183. $t echo "\$$(PROJECT).d:: src/generated.erl" >> $(APP)/Makefile
  184. $t echo "src/generated.erl:: script.sh; echo \"-module(generated).\" > \$$@" >> $(APP)/Makefile
  185. $i "Generate unrelated .erl files"
  186. $t echo "-module(boy)." > $(APP)/src/boy.erl
  187. $t echo "-module(girl)." > $(APP)/src/girl.erl
  188. $i "Build the application"
  189. $t $(MAKE) -C $(APP) $v
  190. $i "Check that all compiled files exist"
  191. $t test -f $(APP)/$(APP).d
  192. $t test -f $(APP)/ebin/$(APP).app
  193. $t test -f $(APP)/ebin/boy.beam
  194. $t test -f $(APP)/ebin/generated.beam
  195. $t test -f $(APP)/ebin/girl.beam
  196. $t test -f $(APP)/src/generated.erl
  197. $i "Check that the application was compiled correctly"
  198. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  199. ok = application:start($(APP)), \
  200. {ok, Mods = [boy, generated, girl]} \
  201. = application:get_key($(APP), modules), \
  202. [{module, M} = code:load_file(M) || M <- Mods], \
  203. halt()"
  204. $i "Touch the script file; check that only required files are rebuilt"
  205. $t printf "%s\n" \
  206. $(APP)/$(APP).d \
  207. $(APP)/ebin/$(APP).app \
  208. $(APP)/ebin/generated.beam \
  209. $(APP)/src/generated.erl | sort > $(APP)/EXPECT
  210. $t touch $(APP)/script.sh
  211. $t $(MAKE) -C $(APP) $v
  212. $t find $(APP) -type f -newer $(APP)/script.sh | sort | diff $(APP)/EXPECT -
  213. $t rm $(APP)/EXPECT
  214. $i "Check that the application was compiled correctly"
  215. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  216. ok = application:start($(APP)), \
  217. {ok, Mods = [boy, generated, girl]} \
  218. = application:get_key($(APP), modules), \
  219. [{module, M} = code:load_file(M) || M <- Mods], \
  220. halt()"
  221. $i "Clean the application"
  222. $t $(MAKE) -C $(APP) clean $v
  223. $i "Check that source files still exist"
  224. $t test -f $(APP)/Makefile
  225. $t test -f $(APP)/erlang.mk
  226. $t test -f $(APP)/script.sh
  227. $t test -f $(APP)/src/$(APP).app.src
  228. $t test -f $(APP)/src/boy.erl
  229. $t test -f $(APP)/src/girl.erl
  230. $i "Check that the generated .erl file still exists"
  231. $t test -f $(APP)/src/generated.erl
  232. $i "Check that all build artifacts are removed"
  233. $t test ! -e $(APP)/$(APP).d
  234. $t test ! -e $(APP)/ebin/
  235. $i "Add a rule to remove the generated .erl file on clean"
  236. $t echo "clean:: ; rm src/generated.erl" >> $(APP)/Makefile
  237. $i "Clean the application again"
  238. $t $(MAKE) -C $(APP) clean $v
  239. $i "Check that the generated .erl file was removed"
  240. $t test ! -e $(APP)/src/generated.erl
  241. $i "Build the application again"
  242. $t $(MAKE) -C $(APP) $v
  243. $i "Check that all compiled files exist"
  244. $t test -f $(APP)/$(APP).d
  245. $t test -f $(APP)/ebin/$(APP).app
  246. $t test -f $(APP)/ebin/boy.beam
  247. $t test -f $(APP)/ebin/generated.beam
  248. $t test -f $(APP)/ebin/girl.beam
  249. $t test -f $(APP)/src/generated.erl
  250. $i "Check that the application was compiled correctly"
  251. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  252. ok = application:start($(APP)), \
  253. {ok, Mods = [boy, generated, girl]} \
  254. = application:get_key($(APP), modules), \
  255. [{module, M} = code:load_file(M) || M <- Mods], \
  256. halt()"
  257. core-app-generate-erl-include: build clean-core-app-generate-erl-include
  258. $i "Bootstrap a new OTP library named $(APP)"
  259. $t mkdir $(APP)/
  260. $t cp ../erlang.mk $(APP)/
  261. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  262. $i "Create a fake script file to be used as dependency"
  263. $t touch $(APP)/script.sh
  264. $i "Append rules to the Makefile to generate a .erl module"
  265. $t echo "\$$(PROJECT).d:: src/generated.erl" >> $(APP)/Makefile
  266. $t echo "src/generated.erl:: script.sh; echo \"-module(generated).\" > \$$@; echo \"-include(\\\"included.hrl\\\").\" >> \$$@" >> $(APP)/Makefile
  267. $i "Generate the .hrl file"
  268. $t mkdir $(APP)/include/
  269. $t touch $(APP)/include/included.hrl
  270. $i "Generate unrelated .erl files"
  271. $t echo "-module(boy)." > $(APP)/src/boy.erl
  272. $t echo "-module(girl)." > $(APP)/src/girl.erl
  273. $i "Build the application"
  274. $t $(MAKE) -C $(APP) $v
  275. $i "Check that all compiled files exist"
  276. $t test -f $(APP)/$(APP).d
  277. $t test -f $(APP)/ebin/$(APP).app
  278. $t test -f $(APP)/ebin/boy.beam
  279. $t test -f $(APP)/ebin/generated.beam
  280. $t test -f $(APP)/ebin/girl.beam
  281. $t test -f $(APP)/src/generated.erl
  282. $i "Check that the application was compiled correctly"
  283. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  284. ok = application:start($(APP)), \
  285. {ok, Mods = [boy, generated, girl]} \
  286. = application:get_key($(APP), modules), \
  287. [{module, M} = code:load_file(M) || M <- Mods], \
  288. halt()"
  289. $i "Touch the .hrl file; check that only required files are rebuilt"
  290. $t printf "%s\n" \
  291. $(APP)/$(APP).d \
  292. $(APP)/ebin/$(APP).app \
  293. $(APP)/ebin/generated.beam \
  294. $(APP)/src/generated.erl | sort > $(APP)/EXPECT
  295. $t touch $(APP)/include/included.hrl
  296. $t $(MAKE) -C $(APP) $v
  297. $t find $(APP) -type f -newer $(APP)/include/included.hrl | sort | diff $(APP)/EXPECT -
  298. $t rm $(APP)/EXPECT
  299. $i "Check that the application was compiled correctly"
  300. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  301. ok = application:start($(APP)), \
  302. {ok, Mods = [boy, generated, girl]} \
  303. = application:get_key($(APP), modules), \
  304. [{module, M} = code:load_file(M) || M <- Mods], \
  305. halt()"
  306. core-app-generate-erl-prepend: build clean-core-app-generate-erl-prepend
  307. $i "Bootstrap a new OTP library named $(APP)"
  308. $t mkdir $(APP)/
  309. $t cp ../erlang.mk $(APP)/
  310. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  311. $i "Create a fake script file to be used as dependency"
  312. $t touch $(APP)/script.sh
  313. $i "Generate a Makefile and prepend rules that generate a .erl module"
  314. $t echo "PROJECT = $(APP)" > $(APP)/Makefile
  315. $t echo ".DEFAULT_GOAL = all" >> $(APP)/Makefile
  316. $t echo "\$$(PROJECT).d:: src/generated.erl" >> $(APP)/Makefile
  317. $t echo "src/generated.erl:: script.sh; echo \"-module(generated).\" > \$$@" >> $(APP)/Makefile
  318. $t echo "include erlang.mk" >> $(APP)/Makefile
  319. $i "Generate unrelated .erl files"
  320. $t echo "-module(boy)." > $(APP)/src/boy.erl
  321. $t echo "-module(girl)." > $(APP)/src/girl.erl
  322. $i "Build the application"
  323. $t $(MAKE) -C $(APP) $v
  324. $i "Check that all compiled files exist"
  325. $t test -f $(APP)/$(APP).d
  326. $t test -f $(APP)/ebin/$(APP).app
  327. $t test -f $(APP)/ebin/boy.beam
  328. $t test -f $(APP)/ebin/generated.beam
  329. $t test -f $(APP)/ebin/girl.beam
  330. $t test -f $(APP)/src/generated.erl
  331. $i "Check that the application was compiled correctly"
  332. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  333. ok = application:start($(APP)), \
  334. {ok, Mods = [boy, generated, girl]} \
  335. = application:get_key($(APP), modules), \
  336. [{module, M} = code:load_file(M) || M <- Mods], \
  337. halt()"
  338. $i "Touch the script file; check that only required files are rebuilt"
  339. $t printf "%s\n" \
  340. $(APP)/$(APP).d \
  341. $(APP)/ebin/$(APP).app \
  342. $(APP)/ebin/generated.beam \
  343. $(APP)/src/generated.erl | sort > $(APP)/EXPECT
  344. $t touch $(APP)/script.sh
  345. $t $(MAKE) -C $(APP) $v
  346. $t find $(APP) -type f -newer $(APP)/script.sh | sort | diff $(APP)/EXPECT -
  347. $t rm $(APP)/EXPECT
  348. $i "Check that the application was compiled correctly"
  349. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  350. ok = application:start($(APP)), \
  351. {ok, Mods = [boy, generated, girl]} \
  352. = application:get_key($(APP), modules), \
  353. [{module, M} = code:load_file(M) || M <- Mods], \
  354. halt()"
  355. $i "Clean the application"
  356. $t $(MAKE) -C $(APP) clean $v
  357. $i "Check that source files still exist"
  358. $t test -f $(APP)/Makefile
  359. $t test -f $(APP)/erlang.mk
  360. $t test -f $(APP)/script.sh
  361. $t test -f $(APP)/src/$(APP).app.src
  362. $t test -f $(APP)/src/boy.erl
  363. $t test -f $(APP)/src/girl.erl
  364. $i "Check that the generated .erl file still exists"
  365. $t test -f $(APP)/src/generated.erl
  366. $i "Check that all build artifacts are removed"
  367. $t test ! -e $(APP)/$(APP).d
  368. $t test ! -e $(APP)/ebin/
  369. $i "Add a rule to remove the generated .erl file on clean"
  370. $t echo "clean:: ; rm src/generated.erl" >> $(APP)/Makefile
  371. $i "Clean the application again"
  372. $t $(MAKE) -C $(APP) clean $v
  373. $i "Check that the generated .erl file was removed"
  374. $t test ! -e $(APP)/src/generated.erl
  375. $i "Build the application again"
  376. $t $(MAKE) -C $(APP) $v
  377. $i "Check that all compiled files exist"
  378. $t test -f $(APP)/$(APP).d
  379. $t test -f $(APP)/ebin/$(APP).app
  380. $t test -f $(APP)/ebin/boy.beam
  381. $t test -f $(APP)/ebin/generated.beam
  382. $t test -f $(APP)/ebin/girl.beam
  383. $t test -f $(APP)/src/generated.erl
  384. $i "Check that the application was compiled correctly"
  385. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  386. ok = application:start($(APP)), \
  387. {ok, Mods = [boy, generated, girl]} \
  388. = application:get_key($(APP), modules), \
  389. [{module, M} = code:load_file(M) || M <- Mods], \
  390. halt()"
  391. core-app-hrl: build clean-core-app-hrl
  392. $i "Bootstrap a new OTP library named $(APP)"
  393. $t mkdir $(APP)/
  394. $t cp ../erlang.mk $(APP)/
  395. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  396. $i "Generate .hrl files"
  397. $t mkdir $(APP)/include/
  398. $t touch $(APP)/include/blue.hrl $(APP)/include/red.hrl
  399. $i "Generate .erl files dependent from headers"
  400. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  401. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  402. $i "Build the application"
  403. $t $(MAKE) -C $(APP) $v
  404. $i "Check that all compiled files exist"
  405. $t test -f $(APP)/$(APP).d
  406. $t test -f $(APP)/ebin/$(APP).app
  407. $t test -f $(APP)/ebin/use_blue.beam
  408. $t test -f $(APP)/ebin/use_red.beam
  409. $i "Check that the application was compiled correctly"
  410. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  411. ok = application:start($(APP)), \
  412. {ok, Mods = [use_blue, use_red]} \
  413. = application:get_key($(APP), modules), \
  414. [{module, M} = code:load_file(M) || M <- Mods], \
  415. halt()"
  416. $i "Touch one .hrl file; check that only required files are rebuilt"
  417. # The use_red.erl gets touched because of its dependency to red.hrl.
  418. $t printf "%s\n" \
  419. $(APP)/$(APP).d \
  420. $(APP)/ebin/$(APP).app \
  421. $(APP)/ebin/use_red.beam \
  422. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  423. $t touch $(APP)/include/red.hrl
  424. $t $(MAKE) -C $(APP) $v
  425. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  426. $t rm $(APP)/EXPECT
  427. $i "Check that the application was compiled correctly"
  428. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  429. ok = application:start($(APP)), \
  430. {ok, Mods = [use_blue, use_red]} \
  431. = application:get_key($(APP), modules), \
  432. [{module, M} = code:load_file(M) || M <- Mods], \
  433. halt()"
  434. $i "Clean the application"
  435. $t $(MAKE) -C $(APP) clean $v
  436. $i "Check that source files still exist"
  437. $t test -f $(APP)/Makefile
  438. $t test -f $(APP)/erlang.mk
  439. $t test -f $(APP)/include/blue.hrl
  440. $t test -f $(APP)/include/red.hrl
  441. $t test -f $(APP)/src/$(APP).app.src
  442. $t test -f $(APP)/src/use_blue.erl
  443. $t test -f $(APP)/src/use_red.erl
  444. $i "Check that all build artifacts are removed"
  445. $t test ! -e $(APP)/$(APP).d
  446. $t test ! -e $(APP)/ebin/
  447. $i "Build the application again"
  448. $t $(MAKE) -C $(APP) $v
  449. $i "Check that all compiled files exist"
  450. $t test -f $(APP)/$(APP).d
  451. $t test -f $(APP)/ebin/$(APP).app
  452. $t test -f $(APP)/ebin/use_blue.beam
  453. $t test -f $(APP)/ebin/use_red.beam
  454. $i "Check that the application was compiled correctly"
  455. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  456. ok = application:start($(APP)), \
  457. {ok, Mods = [use_blue, use_red]} \
  458. = application:get_key($(APP), modules), \
  459. [{module, M} = code:load_file(M) || M <- Mods], \
  460. halt()"
  461. core-app-hrl-recursive: build clean-core-app-hrl-recursive
  462. $i "Bootstrap a new OTP library named $(APP)"
  463. $t mkdir $(APP)/
  464. $t cp ../erlang.mk $(APP)/
  465. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  466. $i "Generate .hrl files"
  467. $t mkdir $(APP)/include/
  468. $t touch $(APP)/include/blue.hrl $(APP)/include/pill.hrl
  469. $t echo "-include(\"pill.hrl\")." > $(APP)/include/red.hrl
  470. $i "Generate .erl files dependent from headers"
  471. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  472. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  473. $i "Build the application"
  474. $t $(MAKE) -C $(APP) $v
  475. $i "Check that all compiled files exist"
  476. $t test -f $(APP)/$(APP).d
  477. $t test -f $(APP)/ebin/$(APP).app
  478. $t test -f $(APP)/ebin/use_blue.beam
  479. $t test -f $(APP)/ebin/use_red.beam
  480. $i "Check that the application was compiled correctly"
  481. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  482. ok = application:start($(APP)), \
  483. {ok, Mods = [use_blue, use_red]} \
  484. = application:get_key($(APP), modules), \
  485. [{module, M} = code:load_file(M) || M <- Mods], \
  486. halt()"
  487. $i "Touch the deepest .hrl file; check that only required files are rebuilt"
  488. # The use_red.erl gets touched because of its dependency to red.hrl and pill.hrl.
  489. $t printf "%s\n" \
  490. $(APP)/$(APP).d \
  491. $(APP)/ebin/$(APP).app \
  492. $(APP)/ebin/use_red.beam \
  493. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  494. $t touch $(APP)/include/pill.hrl
  495. $t $(MAKE) -C $(APP) $v
  496. $t find $(APP) -type f -newer $(APP)/include/pill.hrl | sort | diff $(APP)/EXPECT -
  497. $t rm $(APP)/EXPECT
  498. $i "Check that the application was compiled correctly"
  499. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  500. ok = application:start($(APP)), \
  501. {ok, Mods = [use_blue, use_red]} \
  502. = application:get_key($(APP), modules), \
  503. [{module, M} = code:load_file(M) || M <- Mods], \
  504. halt()"
  505. $i "Clean the application"
  506. $t $(MAKE) -C $(APP) clean $v
  507. $i "Check that source files still exist"
  508. $t test -f $(APP)/Makefile
  509. $t test -f $(APP)/erlang.mk
  510. $t test -f $(APP)/include/blue.hrl
  511. $t test -f $(APP)/include/pill.hrl
  512. $t test -f $(APP)/include/red.hrl
  513. $t test -f $(APP)/src/$(APP).app.src
  514. $t test -f $(APP)/src/use_blue.erl
  515. $t test -f $(APP)/src/use_red.erl
  516. $i "Check that all build artifacts are removed"
  517. $t test ! -e $(APP)/$(APP).d
  518. $t test ! -e $(APP)/ebin/
  519. $i "Build the application again"
  520. $t $(MAKE) -C $(APP) $v
  521. $i "Check that all compiled files exist"
  522. $t test -f $(APP)/$(APP).d
  523. $t test -f $(APP)/ebin/$(APP).app
  524. $t test -f $(APP)/ebin/use_blue.beam
  525. $t test -f $(APP)/ebin/use_red.beam
  526. $i "Check that the application was compiled correctly"
  527. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  528. ok = application:start($(APP)), \
  529. {ok, Mods = [use_blue, use_red]} \
  530. = application:get_key($(APP), modules), \
  531. [{module, M} = code:load_file(M) || M <- Mods], \
  532. halt()"
  533. core-app-mib: build clean-core-app-mib
  534. $i "Bootstrap a new OTP library named $(APP)"
  535. $t mkdir $(APP)/
  536. $t cp ../erlang.mk $(APP)/
  537. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  538. $i "Download .mib files from Erlang/OTP"
  539. $t mkdir $(APP)/mibs/
  540. $t curl -s -o $(APP)/mibs/EX1-MIB.mib $(OTP_MASTER)/lib/snmp/examples/ex1/EX1-MIB.mib
  541. $t curl -s -o $(APP)/mibs/OTP-REG.mib $(OTP_MASTER)/lib/otp_mibs/mibs/OTP-REG.mib
  542. $i "Generate .erl files dependent from headers generated by .mib files"
  543. $t printf "%s\n" "-module(use_v1)." "-include(\"EX1-MIB.hrl\")." > $(APP)/src/use_v1.erl
  544. $t printf "%s\n" "-module(use_v2)." "-include(\"OTP-REG.hrl\")." > $(APP)/src/use_v2.erl
  545. $i "Generate an unrelated .hrl file"
  546. $t mkdir $(APP)/include/
  547. $t touch $(APP)/include/unrelated.hrl
  548. $i "Build the application"
  549. $t $(MAKE) -C $(APP) $v
  550. $i "Check that all compiled files exist"
  551. $t test -f $(APP)/$(APP).d
  552. $t test -f $(APP)/ebin/$(APP).app
  553. $t test -f $(APP)/ebin/use_v1.beam
  554. $t test -f $(APP)/ebin/use_v2.beam
  555. $t test -f $(APP)/include/EX1-MIB.hrl
  556. $t test -f $(APP)/include/OTP-REG.hrl
  557. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  558. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  559. $i "Check that the application was compiled correctly"
  560. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  561. ok = application:start($(APP)), \
  562. {ok, Mods = [use_v1, use_v2]} \
  563. = application:get_key($(APP), modules), \
  564. [{module, M} = code:load_file(M) || M <- Mods], \
  565. halt()"
  566. $i "Touch one .mib file; check that only required files are rebuilt"
  567. # The use_v1.erl gets touched because of its dependency to EX1-MIB.hrl.
  568. $t printf "%s\n" \
  569. $(APP)/$(APP).d \
  570. $(APP)/ebin/$(APP).app \
  571. $(APP)/ebin/use_v1.beam \
  572. $(APP)/include/EX1-MIB.hrl \
  573. $(APP)/priv/mibs/EX1-MIB.bin \
  574. $(APP)/src/use_v1.erl | sort > $(APP)/EXPECT
  575. $t touch $(APP)/mibs/EX1-MIB.mib
  576. $t $(MAKE) -C $(APP) $v
  577. $t find $(APP) -type f -newer $(APP)/mibs/EX1-MIB.mib | sort | diff $(APP)/EXPECT -
  578. $t rm $(APP)/EXPECT
  579. $i "Check that the application was compiled correctly"
  580. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  581. ok = application:start($(APP)), \
  582. {ok, Mods = [use_v1, use_v2]} \
  583. = application:get_key($(APP), modules), \
  584. [{module, M} = code:load_file(M) || M <- Mods], \
  585. halt()"
  586. $i "Clean the application"
  587. $t $(MAKE) -C $(APP) clean $v
  588. $i "Check that source files still exist"
  589. $t test -f $(APP)/Makefile
  590. $t test -f $(APP)/erlang.mk
  591. $t test -f $(APP)/include/unrelated.hrl
  592. $t test -f $(APP)/mibs/EX1-MIB.mib
  593. $t test -f $(APP)/mibs/OTP-REG.mib
  594. $t test -f $(APP)/src/$(APP).app.src
  595. $t test -f $(APP)/src/use_v1.erl
  596. $t test -f $(APP)/src/use_v2.erl
  597. $i "Check that all build artifacts are removed, including intermediates"
  598. $t test ! -e $(APP)/$(APP).d
  599. $t test ! -e $(APP)/ebin/
  600. $t test ! -e $(APP)/include/EX1-MIB.hrl
  601. $t test ! -e $(APP)/include/OTP-REG.hrl
  602. $t test ! -e $(APP)/priv/mibs/
  603. $i "Build the application again"
  604. $t $(MAKE) -C $(APP) $v
  605. $i "Check that all compiled files exist"
  606. $t test -f $(APP)/$(APP).d
  607. $t test -f $(APP)/ebin/$(APP).app
  608. $t test -f $(APP)/ebin/use_v1.beam
  609. $t test -f $(APP)/ebin/use_v2.beam
  610. $t test -f $(APP)/include/EX1-MIB.hrl
  611. $t test -f $(APP)/include/OTP-REG.hrl
  612. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  613. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  614. $i "Check that the application was compiled correctly"
  615. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  616. ok = application:start($(APP)), \
  617. {ok, Mods = [use_v1, use_v2]} \
  618. = application:get_key($(APP), modules), \
  619. [{module, M} = code:load_file(M) || M <- Mods], \
  620. halt()"
  621. core-app-no-makedep: build clean-core-app-no-makedep
  622. $i "Bootstrap a new OTP library named $(APP)"
  623. $t mkdir $(APP)/
  624. $t cp ../erlang.mk $(APP)/
  625. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  626. $i "Set NO_MAKEDEP ?= 1 in the Makefile"
  627. $t sed -i '2iNO_MAKEDEP ?= 1' $(APP)/Makefile
  628. $i "Generate .hrl files"
  629. $t mkdir $(APP)/include/
  630. $t touch $(APP)/include/blue.hrl $(APP)/include/red.hrl
  631. $i "Generate .erl files dependent from headers"
  632. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  633. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  634. $i "Build the application"
  635. $t $(MAKE) -C $(APP) $v
  636. $i "Check that all compiled files exist"
  637. $t test -f $(APP)/$(APP).d
  638. $t test -f $(APP)/ebin/$(APP).app
  639. $t test -f $(APP)/ebin/use_blue.beam
  640. $t test -f $(APP)/ebin/use_red.beam
  641. $i "Check that the application was compiled correctly"
  642. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  643. ok = application:start($(APP)), \
  644. {ok, Mods = [use_blue, use_red]} \
  645. = application:get_key($(APP), modules), \
  646. [{module, M} = code:load_file(M) || M <- Mods], \
  647. halt()"
  648. $i "Touch one .hrl file; check that only required files are rebuilt"
  649. # The use_red.erl gets touched because of its dependency to red.hrl.
  650. $t printf "%s\n" \
  651. $(APP)/ebin/$(APP).app \
  652. $(APP)/ebin/use_red.beam \
  653. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  654. $t touch $(APP)/include/red.hrl
  655. $t $(MAKE) -C $(APP) $v
  656. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  657. $t rm $(APP)/EXPECT
  658. $i "Check that the application was compiled correctly"
  659. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  660. ok = application:start($(APP)), \
  661. {ok, Mods = [use_blue, use_red]} \
  662. = application:get_key($(APP), modules), \
  663. [{module, M} = code:load_file(M) || M <- Mods], \
  664. halt()"
  665. $i "Touch one .hrl file; disable NO_MAKEDEP and check that only required files are rebuilt"
  666. # The use_red.erl gets touched because of its dependency to red.hrl.
  667. $t printf "%s\n" \
  668. $(APP)/$(APP).d \
  669. $(APP)/ebin/$(APP).app \
  670. $(APP)/ebin/use_red.beam \
  671. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  672. $t touch $(APP)/include/red.hrl
  673. $t NO_MAKEDEP= $(MAKE) -C $(APP) $v
  674. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  675. $t rm $(APP)/EXPECT
  676. $i "Check that the application was compiled correctly"
  677. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  678. ok = application:start($(APP)), \
  679. {ok, Mods = [use_blue, use_red]} \
  680. = application:get_key($(APP), modules), \
  681. [{module, M} = code:load_file(M) || M <- Mods], \
  682. halt()"
  683. $i "Clean the application"
  684. $t $(MAKE) -C $(APP) clean $v
  685. $i "Check that source files still exist"
  686. $t test -f $(APP)/Makefile
  687. $t test -f $(APP)/erlang.mk
  688. $t test -f $(APP)/include/blue.hrl
  689. $t test -f $(APP)/include/red.hrl
  690. $t test -f $(APP)/src/$(APP).app.src
  691. $t test -f $(APP)/src/use_blue.erl
  692. $t test -f $(APP)/src/use_red.erl
  693. $i "Check that all build artifacts are removed"
  694. $t test ! -e $(APP)/$(APP).d
  695. $t test ! -e $(APP)/ebin/
  696. $i "Build the application again"
  697. $t $(MAKE) -C $(APP) $v
  698. $i "Check that all compiled files exist"
  699. $t test -f $(APP)/$(APP).d
  700. $t test -f $(APP)/ebin/$(APP).app
  701. $t test -f $(APP)/ebin/use_blue.beam
  702. $t test -f $(APP)/ebin/use_red.beam
  703. $i "Check that the application was compiled correctly"
  704. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  705. ok = application:start($(APP)), \
  706. {ok, Mods = [use_blue, use_red]} \
  707. = application:get_key($(APP), modules), \
  708. [{module, M} = code:load_file(M) || M <- Mods], \
  709. halt()"
  710. core-app-xrl: build clean-core-app-xrl
  711. $i "Bootstrap a new OTP library named $(APP)"
  712. $t mkdir $(APP)/
  713. $t cp ../erlang.mk $(APP)/
  714. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  715. $i "Download .xrl files from Robert"
  716. $t curl -s -o $(APP)/src/erlang_scan.xrl https://raw.githubusercontent.com/rvirding/leex/master/examples/erlang_scan.xrl
  717. $t curl -s -o $(APP)/src/lfe_scan.xrl https://raw.githubusercontent.com/rvirding/leex/master/examples/lfe_scan.xrl
  718. $i "Generate unrelated .erl files"
  719. $t echo "-module(boy)." > $(APP)/src/boy.erl
  720. $t echo "-module(girl)." > $(APP)/src/girl.erl
  721. $i "Disable warnings; our test .xrl files aren't perfect"
  722. $t echo "ERLC_OPTS=+debug_info" >> $(APP)/Makefile
  723. $i "Build the application"
  724. $t $(MAKE) -C $(APP) $v
  725. $i "Check that all compiled files exist"
  726. $t test -f $(APP)/$(APP).d
  727. $t test -f $(APP)/ebin/$(APP).app
  728. $t test -f $(APP)/ebin/boy.beam
  729. $t test -f $(APP)/ebin/erlang_scan.beam
  730. $t test -f $(APP)/ebin/girl.beam
  731. $t test -f $(APP)/ebin/lfe_scan.beam
  732. $t test -f $(APP)/src/erlang_scan.erl
  733. $t test -f $(APP)/src/lfe_scan.erl
  734. $i "Check that the application was compiled correctly"
  735. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  736. ok = application:start($(APP)), \
  737. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  738. = application:get_key($(APP), modules), \
  739. [{module, M} = code:load_file(M) || M <- Mods], \
  740. halt()"
  741. $i "Touch one .xrl file; check that only required files are rebuilt"
  742. $t printf "%s\n" \
  743. $(APP)/$(APP).d \
  744. $(APP)/ebin/$(APP).app \
  745. $(APP)/ebin/erlang_scan.beam \
  746. $(APP)/src/erlang_scan.erl | sort > $(APP)/EXPECT
  747. $t touch $(APP)/src/erlang_scan.xrl
  748. $t $(MAKE) -C $(APP) $v
  749. $t find $(APP) -type f -newer $(APP)/src/erlang_scan.xrl | sort | diff $(APP)/EXPECT -
  750. $t rm $(APP)/EXPECT
  751. $i "Check that the application was compiled correctly"
  752. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  753. ok = application:start($(APP)), \
  754. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  755. = application:get_key($(APP), modules), \
  756. [{module, M} = code:load_file(M) || M <- Mods], \
  757. halt()"
  758. $i "Clean the application"
  759. $t $(MAKE) -C $(APP) clean $v
  760. $i "Check that source files still exist"
  761. $t test -f $(APP)/Makefile
  762. $t test -f $(APP)/erlang.mk
  763. $t test -f $(APP)/src/$(APP).app.src
  764. $t test -f $(APP)/src/boy.erl
  765. $t test -f $(APP)/src/erlang_scan.xrl
  766. $t test -f $(APP)/src/girl.erl
  767. $t test -f $(APP)/src/lfe_scan.xrl
  768. $i "Check that all build artifacts are removed, including intermediates"
  769. $t test ! -e $(APP)/$(APP).d
  770. $t test ! -e $(APP)/ebin/
  771. $t test ! -e $(APP)/src/erlang_scan.erl
  772. $t test ! -e $(APP)/src/lfe_scan.erl
  773. $i "Build the application again"
  774. $t $(MAKE) -C $(APP) $v
  775. $i "Check that all compiled files exist"
  776. $t test -f $(APP)/$(APP).d
  777. $t test -f $(APP)/ebin/$(APP).app
  778. $t test -f $(APP)/ebin/boy.beam
  779. $t test -f $(APP)/ebin/erlang_scan.beam
  780. $t test -f $(APP)/ebin/girl.beam
  781. $t test -f $(APP)/ebin/lfe_scan.beam
  782. $t test -f $(APP)/src/erlang_scan.erl
  783. $t test -f $(APP)/src/lfe_scan.erl
  784. $i "Check that the application was compiled correctly"
  785. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  786. ok = application:start($(APP)), \
  787. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  788. = application:get_key($(APP), modules), \
  789. [{module, M} = code:load_file(M) || M <- Mods], \
  790. halt()"
  791. core-app-xrl-include: build clean-core-app-xrl-include
  792. $i "Bootstrap a new OTP library named $(APP)"
  793. $t mkdir $(APP)/
  794. $t cp ../erlang.mk $(APP)/
  795. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  796. $i "Download a .xrl file with numerous includes from Gordon"
  797. $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
  798. $t curl -s -o $(APP)/src/errvals.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/errvals.hrl
  799. $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
  800. $t curl -s -o $(APP)/src/muin_records.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/muin_records.hrl
  801. $t curl -s -o $(APP)/src/typechecks.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/typechecks.hrl
  802. $i "Generate unrelated .erl files"
  803. $t echo "-module(boy)." > $(APP)/src/boy.erl
  804. $t echo "-module(girl)." > $(APP)/src/girl.erl
  805. $i "Disable warnings; our test .xrl files aren't perfect"
  806. $t echo "ERLC_OPTS=+debug_info" >> $(APP)/Makefile
  807. $i "Build the application"
  808. $t $(MAKE) -C $(APP) $v
  809. $i "Check that all compiled files exist"
  810. $t test -f $(APP)/$(APP).d
  811. $t test -f $(APP)/ebin/$(APP).app
  812. $t test -f $(APP)/ebin/boy.beam
  813. $t test -f $(APP)/ebin/girl.beam
  814. $t test -f $(APP)/ebin/xfl_lexer.beam
  815. $t test -f $(APP)/src/xfl_lexer.erl
  816. $i "Check that the application was compiled correctly"
  817. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  818. ok = application:start($(APP)), \
  819. {ok, Mods = [boy, girl, xfl_lexer]} \
  820. = application:get_key($(APP), modules), \
  821. [{module, M} = code:load_file(M) || M <- Mods], \
  822. halt()"
  823. $i "Touch the .xrl file; check that only required files are rebuilt"
  824. $t printf "%s\n" \
  825. $(APP)/$(APP).d \
  826. $(APP)/ebin/$(APP).app \
  827. $(APP)/ebin/xfl_lexer.beam \
  828. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  829. $t touch $(APP)/src/xfl_lexer.xrl
  830. $t $(MAKE) -C $(APP) $v
  831. $t find $(APP) -type f -newer $(APP)/src/xfl_lexer.xrl | sort | diff $(APP)/EXPECT -
  832. $t rm $(APP)/EXPECT
  833. $i "Check that the application was compiled correctly"
  834. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  835. ok = application:start($(APP)), \
  836. {ok, Mods = [boy, girl, xfl_lexer]} \
  837. = application:get_key($(APP), modules), \
  838. [{module, M} = code:load_file(M) || M <- Mods], \
  839. halt()"
  840. $i "Touch a .hrl file included directly; check that only required files are rebuilt"
  841. $t printf "%s\n" \
  842. $(APP)/$(APP).d \
  843. $(APP)/ebin/$(APP).app \
  844. $(APP)/ebin/xfl_lexer.beam \
  845. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  846. $t touch $(APP)/src/typechecks.hrl
  847. $t $(MAKE) -C $(APP) $v
  848. $t find $(APP) -type f -newer $(APP)/src/typechecks.hrl | sort | diff $(APP)/EXPECT -
  849. $t rm $(APP)/EXPECT
  850. $i "Check that the application was compiled correctly"
  851. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  852. ok = application:start($(APP)), \
  853. {ok, Mods = [boy, girl, xfl_lexer]} \
  854. = application:get_key($(APP), modules), \
  855. [{module, M} = code:load_file(M) || M <- Mods], \
  856. halt()"
  857. $i "Touch a .hrl file included indirectly; check that only required files are rebuilt"
  858. $t printf "%s\n" \
  859. $(APP)/$(APP).d \
  860. $(APP)/ebin/$(APP).app \
  861. $(APP)/ebin/xfl_lexer.beam \
  862. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  863. $t touch $(APP)/src/errvals.hrl
  864. $t $(MAKE) -C $(APP) $v
  865. $t find $(APP) -type f -newer $(APP)/src/errvals.hrl | sort | diff $(APP)/EXPECT -
  866. $t rm $(APP)/EXPECT
  867. $i "Check that the application was compiled correctly"
  868. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  869. ok = application:start($(APP)), \
  870. {ok, Mods = [boy, girl, xfl_lexer]} \
  871. = application:get_key($(APP), modules), \
  872. [{module, M} = code:load_file(M) || M <- Mods], \
  873. halt()"
  874. $i "Clean the application"
  875. $t $(MAKE) -C $(APP) clean $v
  876. $i "Check that source files still exist"
  877. $t test -f $(APP)/Makefile
  878. $t test -f $(APP)/erlang.mk
  879. $t test -f $(APP)/src/$(APP).app.src
  880. $t test -f $(APP)/src/boy.erl
  881. $t test -f $(APP)/src/girl.erl
  882. $t test -f $(APP)/src/errvals.hrl
  883. $t test -f $(APP)/src/muin_proc_dict.hrl
  884. $t test -f $(APP)/src/muin_records.hrl
  885. $t test -f $(APP)/src/typechecks.hrl
  886. $t test -f $(APP)/src/xfl_lexer.xrl
  887. $i "Check that all build artifacts are removed, including intermediates"
  888. $t test ! -e $(APP)/$(APP).d
  889. $t test ! -e $(APP)/ebin/
  890. $t test ! -e $(APP)/src/xfl_lexer.erl
  891. $i "Build the application again"
  892. $t $(MAKE) -C $(APP) $v
  893. $i "Check that all compiled files exist"
  894. $t test -f $(APP)/$(APP).d
  895. $t test -f $(APP)/ebin/$(APP).app
  896. $t test -f $(APP)/ebin/boy.beam
  897. $t test -f $(APP)/ebin/girl.beam
  898. $t test -f $(APP)/ebin/xfl_lexer.beam
  899. $t test -f $(APP)/src/xfl_lexer.erl
  900. $i "Check that the application was compiled correctly"
  901. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  902. ok = application:start($(APP)), \
  903. {ok, Mods = [boy, girl, xfl_lexer]} \
  904. = application:get_key($(APP), modules), \
  905. [{module, M} = code:load_file(M) || M <- Mods], \
  906. halt()"
  907. core-app-yrl: build clean-core-app-yrl
  908. $i "Bootstrap a new OTP library named $(APP)"
  909. $t mkdir $(APP)/
  910. $t cp ../erlang.mk $(APP)/
  911. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  912. $i "Download .yrl files from Erlang/OTP"
  913. $t curl -s -o $(APP)/src/xmerl_xpath_parse.yrl $(OTP_MASTER)/lib/xmerl/src/xmerl_xpath_parse.yrl
  914. $t curl -s -o $(APP)/src/xref_parser.yrl $(OTP_MASTER)/lib/tools/src/xref_parser.yrl
  915. $i "Generate unrelated .erl files"
  916. $t echo "-module(boy)." > $(APP)/src/boy.erl
  917. $t echo "-module(girl)." > $(APP)/src/girl.erl
  918. $i "Build the application"
  919. $t $(MAKE) -C $(APP) $v
  920. $i "Check that all compiled files exist"
  921. $t test -f $(APP)/$(APP).d
  922. $t test -f $(APP)/ebin/$(APP).app
  923. $t test -f $(APP)/ebin/boy.beam
  924. $t test -f $(APP)/ebin/girl.beam
  925. $t test -f $(APP)/ebin/xmerl_xpath_parse.beam
  926. $t test -f $(APP)/ebin/xref_parser.beam
  927. $t test -f $(APP)/src/xmerl_xpath_parse.erl
  928. $t test -f $(APP)/src/xref_parser.erl
  929. $i "Check that the application was compiled correctly"
  930. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  931. ok = application:start($(APP)), \
  932. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  933. = application:get_key($(APP), modules), \
  934. [{module, M} = code:load_file(M) || M <- Mods], \
  935. halt()"
  936. $i "Touch one .yrl file; check that only required files are rebuilt"
  937. $t printf "%s\n" \
  938. $(APP)/$(APP).d \
  939. $(APP)/ebin/$(APP).app \
  940. $(APP)/ebin/xref_parser.beam \
  941. $(APP)/src/xref_parser.erl | sort > $(APP)/EXPECT
  942. $t touch $(APP)/src/xref_parser.yrl
  943. $t $(MAKE) -C $(APP) $v
  944. $t find $(APP) -type f -newer $(APP)/src/xref_parser.yrl | sort | diff $(APP)/EXPECT -
  945. $t rm $(APP)/EXPECT
  946. $i "Check that the application was compiled correctly"
  947. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  948. ok = application:start($(APP)), \
  949. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  950. = application:get_key($(APP), modules), \
  951. [{module, M} = code:load_file(M) || M <- Mods], \
  952. halt()"
  953. $i "Clean the application"
  954. $t $(MAKE) -C $(APP) clean $v
  955. $i "Check that source files still exist"
  956. $t test -f $(APP)/Makefile
  957. $t test -f $(APP)/erlang.mk
  958. $t test -f $(APP)/src/$(APP).app.src
  959. $t test -f $(APP)/src/boy.erl
  960. $t test -f $(APP)/src/girl.erl
  961. $t test -f $(APP)/src/xmerl_xpath_parse.yrl
  962. $t test -f $(APP)/src/xref_parser.yrl
  963. $i "Check that all build artifacts are removed, including intermediates"
  964. $t test ! -e $(APP)/$(APP).d
  965. $t test ! -e $(APP)/ebin/
  966. $t test ! -e $(APP)/src/xmerl_xpath_parse.erl
  967. $t test ! -e $(APP)/src/xref_parser.erl
  968. $i "Build the application again"
  969. $t $(MAKE) -C $(APP) $v
  970. $i "Check that all compiled files exist"
  971. $t test -f $(APP)/$(APP).d
  972. $t test -f $(APP)/ebin/$(APP).app
  973. $t test -f $(APP)/ebin/boy.beam
  974. $t test -f $(APP)/ebin/girl.beam
  975. $t test -f $(APP)/ebin/xmerl_xpath_parse.beam
  976. $t test -f $(APP)/ebin/xref_parser.beam
  977. $t test -f $(APP)/src/xmerl_xpath_parse.erl
  978. $t test -f $(APP)/src/xref_parser.erl
  979. $i "Check that the application was compiled correctly"
  980. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  981. ok = application:start($(APP)), \
  982. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  983. = application:get_key($(APP), modules), \
  984. [{module, M} = code:load_file(M) || M <- Mods], \
  985. halt()"
  986. core-app-yrl-include: build clean-core-app-yrl-include
  987. $i "Bootstrap a new OTP library named $(APP)"
  988. $t mkdir $(APP)/
  989. $t cp ../erlang.mk $(APP)/
  990. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  991. $i "Download a .yrl file with includes from Erlang/OTP"
  992. $t curl -s -o $(APP)/src/core_parse.yrl $(OTP_MASTER)/lib/compiler/src/core_parse.yrl
  993. $t curl -s -o $(APP)/src/core_parse.hrl $(OTP_MASTER)/lib/compiler/src/core_parse.hrl
  994. $i "Generate unrelated .erl files"
  995. $t echo "-module(boy)." > $(APP)/src/boy.erl
  996. $t echo "-module(girl)." > $(APP)/src/girl.erl
  997. $i "Build the application"
  998. $t $(MAKE) -C $(APP) $v
  999. $i "Check that all compiled files exist"
  1000. $t test -f $(APP)/$(APP).d
  1001. $t test -f $(APP)/ebin/$(APP).app
  1002. $t test -f $(APP)/ebin/boy.beam
  1003. $t test -f $(APP)/ebin/core_parse.beam
  1004. $t test -f $(APP)/ebin/girl.beam
  1005. $t test -f $(APP)/src/core_parse.erl
  1006. $i "Check that the application was compiled correctly"
  1007. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1008. ok = application:start($(APP)), \
  1009. {ok, Mods = [boy, core_parse, girl]} \
  1010. = application:get_key($(APP), modules), \
  1011. [{module, M} = code:load_file(M) || M <- Mods], \
  1012. halt()"
  1013. $i "Touch the .yrl file; check that only required files are rebuilt"
  1014. $t printf "%s\n" \
  1015. $(APP)/$(APP).d \
  1016. $(APP)/ebin/$(APP).app \
  1017. $(APP)/ebin/core_parse.beam \
  1018. $(APP)/src/core_parse.erl | sort > $(APP)/EXPECT
  1019. $t touch $(APP)/src/core_parse.yrl
  1020. $t $(MAKE) -C $(APP) $v
  1021. $t find $(APP) -type f -newer $(APP)/src/core_parse.yrl | sort | diff $(APP)/EXPECT -
  1022. $t rm $(APP)/EXPECT
  1023. $i "Check that the application was compiled correctly"
  1024. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1025. ok = application:start($(APP)), \
  1026. {ok, Mods = [boy, core_parse, girl]} \
  1027. = application:get_key($(APP), modules), \
  1028. [{module, M} = code:load_file(M) || M <- Mods], \
  1029. halt()"
  1030. $i "Touch the .hrl file included; check that only required files are rebuilt"
  1031. $t printf "%s\n" \
  1032. $(APP)/$(APP).d \
  1033. $(APP)/ebin/$(APP).app \
  1034. $(APP)/ebin/core_parse.beam \
  1035. $(APP)/src/core_parse.erl | sort > $(APP)/EXPECT
  1036. $t touch $(APP)/src/core_parse.hrl
  1037. $t $(MAKE) -C $(APP) $v
  1038. $t find $(APP) -type f -newer $(APP)/src/core_parse.hrl | sort | diff $(APP)/EXPECT -
  1039. $t rm $(APP)/EXPECT
  1040. $i "Check that the application was compiled correctly"
  1041. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1042. ok = application:start($(APP)), \
  1043. {ok, Mods = [boy, core_parse, girl]} \
  1044. = application:get_key($(APP), modules), \
  1045. [{module, M} = code:load_file(M) || M <- Mods], \
  1046. halt()"
  1047. $i "Clean the application"
  1048. $t $(MAKE) -C $(APP) clean $v
  1049. $i "Check that source files still exist"
  1050. $t test -f $(APP)/Makefile
  1051. $t test -f $(APP)/erlang.mk
  1052. $t test -f $(APP)/src/$(APP).app.src
  1053. $t test -f $(APP)/src/boy.erl
  1054. $t test -f $(APP)/src/core_parse.hrl
  1055. $t test -f $(APP)/src/core_parse.yrl
  1056. $t test -f $(APP)/src/girl.erl
  1057. $i "Check that all build artifacts are removed, including intermediates"
  1058. $t test ! -e $(APP)/$(APP).d
  1059. $t test ! -e $(APP)/ebin/
  1060. $t test ! -e $(APP)/src/core_parse.erl
  1061. $i "Build the application again"
  1062. $t $(MAKE) -C $(APP) $v
  1063. $i "Check that all compiled files exist"
  1064. $t test -f $(APP)/$(APP).d
  1065. $t test -f $(APP)/ebin/$(APP).app
  1066. $t test -f $(APP)/ebin/boy.beam
  1067. $t test -f $(APP)/ebin/core_parse.beam
  1068. $t test -f $(APP)/ebin/girl.beam
  1069. $t test -f $(APP)/src/core_parse.erl
  1070. $i "Check that the application was compiled correctly"
  1071. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1072. ok = application:start($(APP)), \
  1073. {ok, Mods = [boy, core_parse, girl]} \
  1074. = application:get_key($(APP), modules), \
  1075. [{module, M} = code:load_file(M) || M <- Mods], \
  1076. halt()"
  1077. clean-core-app: $(CORE_APP_CLEAN_TARGETS)
  1078. $(CORE_APP_CLEAN_TARGETS):
  1079. $t rm -rf $(APP_TO_CLEAN)/
  1080. # Core: Erlang.mk upgrade.
  1081. CORE_UPGRADE_CASES = no-config custom-config renamed-config custom-build-dir
  1082. CORE_UPGRADE_TARGETS = $(addprefix core-upgrade-,$(CORE_UPGRADE_CASES))
  1083. CORE_UPGRADE_CLEAN_TARGETS = $(addprefix clean-,$(CORE_UPGRADE_TARGETS))
  1084. .PHONY: core-upgrade $(CORE_UPGRADE_TARGETS) $(CORE_UPGRADE_CLEAN_TARGETS)
  1085. core-upgrade: $(CORE_UPGRADE_TARGETS)
  1086. core-upgrade-no-config: build clean-core-upgrade-no-config
  1087. $i "Bootstrap a new OTP library named $(APP)"
  1088. $t mkdir $(APP)/
  1089. $t cp ../erlang.mk $(APP)/
  1090. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1091. $i "Append a rule to the Erlang.mk file for testing purposes"
  1092. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  1093. $i "Check that the test rule works as intended"
  1094. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  1095. $i "Upgrade Erlang.mk"
  1096. $t $(MAKE) -C $(APP) erlang-mk $v
  1097. $i "Check that the rule is gone"
  1098. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  1099. core-upgrade-custom-config: build clean-core-upgrade-custom-config
  1100. $i "Bootstrap a new OTP library named $(APP)"
  1101. $t mkdir $(APP)/
  1102. $t cp ../erlang.mk $(APP)/
  1103. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1104. $i "Create a custom build.config file without plugins"
  1105. $t echo "core/*" > $(APP)/build.config
  1106. $i "Upgrade Erlang.mk"
  1107. $t $(MAKE) -C $(APP) erlang-mk $v
  1108. $i "Check that the bootstrap plugin is gone"
  1109. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  1110. core-upgrade-renamed-config: build clean-core-upgrade-renamed-config
  1111. $i "Bootstrap a new OTP library named $(APP)"
  1112. $t mkdir $(APP)/
  1113. $t cp ../erlang.mk $(APP)/
  1114. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1115. $i "Create a custom build.config file without plugins; name it my.build.config"
  1116. $t echo "core/*" > $(APP)/my.build.config
  1117. $i "Set ERLANG_MK_BUILD_CONFIG=my.build.config in the Makefile"
  1118. $t echo "ERLANG_MK_BUILD_CONFIG = my.build.config" >> $(APP)/Makefile
  1119. $i "Upgrade Erlang.mk"
  1120. $t $(MAKE) -C $(APP) erlang-mk $v
  1121. $i "Check that the bootstrap plugin is gone"
  1122. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  1123. core-upgrade-custom-build-dir: build clean-core-upgrade-custom-build-dir
  1124. $i "Bootstrap a new OTP library named $(APP)"
  1125. $t mkdir $(APP)/
  1126. $t cp ../erlang.mk $(APP)/
  1127. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1128. $i "Append a rule to the Erlang.mk file for testing purposes"
  1129. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  1130. $i "Check that the test rule works as intended"
  1131. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  1132. $i "Create the custom build directory"
  1133. $t mkdir $(APP)/custom/
  1134. $t test -d $(APP)/custom/
  1135. $i "Upgrade Erlang.mk with a custom build directory"
  1136. $t ERLANG_MK_BUILD_DIR=custom $(MAKE) -C $(APP) erlang-mk $v
  1137. $i "Check that the rule is gone"
  1138. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  1139. $i "Check that the custom build directory is gone"
  1140. $t test ! -d $(APP)/custom/
  1141. clean-core-upgrade: $(CORE_UPGRADE_CLEAN_TARGETS)
  1142. $(CORE_UPGRADE_CLEAN_TARGETS):
  1143. $t rm -rf $(APP_TO_CLEAN)/
  1144. # Bootstrap plugin.
  1145. BOOTSTRAP_CASES = app lib rel templates
  1146. BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
  1147. BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
  1148. .PHONY: bootstrap $(BOOTSTRAP_TARGETS) $(BOOTSTRAP_CLEAN_TARGETS)
  1149. bootstrap: $(BOOTSTRAP_TARGETS)
  1150. bootstrap-app: build clean-bootstrap-app
  1151. $i "Bootstrap a new OTP application named $(APP)"
  1152. $t mkdir $(APP)/
  1153. $t cp ../erlang.mk $(APP)/
  1154. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  1155. $i "Check that all bootstrapped files exist"
  1156. $t test -f $(APP)/Makefile
  1157. $t test -f $(APP)/src/$(APP).app.src
  1158. $t test -f $(APP)/src/$(APP)_app.erl
  1159. $t test -f $(APP)/src/$(APP)_sup.erl
  1160. $i "Build the application"
  1161. $t $(MAKE) -C $(APP) $v
  1162. $i "Check that all compiled files exist"
  1163. $t test -f $(APP)/ebin/$(APP).app
  1164. $t test -f $(APP)/ebin/$(APP)_app.beam
  1165. $t test -f $(APP)/ebin/$(APP)_sup.beam
  1166. $i "Check that the application was compiled correctly"
  1167. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1168. ok = application:start($(APP)), \
  1169. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  1170. {module, $(APP)_app} = code:load_file($(APP)_app), \
  1171. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  1172. halt()"
  1173. bootstrap-lib: build clean-bootstrap-lib
  1174. $i "Bootstrap a new OTP library named $(APP)"
  1175. $t mkdir $(APP)/
  1176. $t cp ../erlang.mk $(APP)/
  1177. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1178. $i "Check that all bootstrapped files exist"
  1179. $t test -f $(APP)/Makefile
  1180. $t test -f $(APP)/src/$(APP).app.src
  1181. $i "Build the application"
  1182. $t $(MAKE) -C $(APP) $v
  1183. $i "Check that all compiled files exist"
  1184. $t test -f $(APP)/ebin/$(APP).app
  1185. $i "Check that the application was compiled correctly"
  1186. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1187. ok = application:start($(APP)), \
  1188. {ok, []} = application:get_key($(APP), modules), \
  1189. halt()"
  1190. bootstrap-rel: build clean-bootstrap-rel
  1191. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  1192. $t mkdir $(APP)/
  1193. $t cp ../erlang.mk $(APP)/
  1194. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  1195. $i "Check that all bootstrapped files exist"
  1196. $t test -f $(APP)/Makefile
  1197. $t test -f $(APP)/relx.config
  1198. $t test -f $(APP)/rel/sys.config
  1199. $t test -f $(APP)/rel/vm.args
  1200. $t test -f $(APP)/src/$(APP).app.src
  1201. $t test -f $(APP)/src/$(APP)_app.erl
  1202. $t test -f $(APP)/src/$(APP)_sup.erl
  1203. $i "Build the application and the release"
  1204. $t $(MAKE) -C $(APP) $v
  1205. $i "Check that all compiled files exist"
  1206. $t test -f $(APP)/ebin/$(APP).app
  1207. $t test -f $(APP)/ebin/$(APP)_app.beam
  1208. $t test -f $(APP)/ebin/$(APP)_sup.beam
  1209. $i "Check that the release was generated"
  1210. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  1211. $i "Check that the release can be started and stopped"
  1212. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  1213. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  1214. $i "Check that there's no erl_crash.dump file"
  1215. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  1216. bootstrap-templates: build clean-bootstrap-templates
  1217. $i "Bootstrap a new OTP library named $(APP)"
  1218. $t mkdir $(APP)/
  1219. $t cp ../erlang.mk $(APP)/
  1220. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1221. $i "Check that we can get the list of templates"
  1222. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  1223. $i "Generate one of each template"
  1224. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  1225. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  1226. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  1227. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  1228. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  1229. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  1230. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  1231. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  1232. # Here we disable warnings because templates contain missing behaviors.
  1233. $i "Build the application"
  1234. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  1235. $i "Check that all compiled files exist"
  1236. $t test -f $(APP)/ebin/$(APP).app
  1237. $t test -f $(APP)/ebin/my_fsm.beam
  1238. $t test -f $(APP)/ebin/my_server.beam
  1239. $t test -f $(APP)/ebin/my_sup.beam
  1240. $i "Check that all the modules can be loaded"
  1241. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1242. ok = application:start($(APP)), \
  1243. {ok, Mods = [my_fsm, my_http, my_loop, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  1244. = application:get_key($(APP), modules), \
  1245. [{module, M} = code:load_file(M) || M <- Mods], \
  1246. halt()"
  1247. clean-bootstrap: $(BOOTSTRAP_CLEAN_TARGETS)
  1248. $(BOOTSTRAP_CLEAN_TARGETS):
  1249. $t rm -rf $(APP_TO_CLEAN)/
  1250. ########################################
  1251. # Legacy tests.
  1252. ct: app1
  1253. $i "ct: Testing ct and related targets."
  1254. $i "Setting up test suite."
  1255. $t mkdir -p app1/test
  1256. $t printf "%s\n" \
  1257. "-module(m_SUITE)." \
  1258. "-export([all/0, testcase1/1])." \
  1259. "all() -> [testcase1]." \
  1260. "testcase1(_) -> 2 = m:succ(1)." \
  1261. > app1/test/m_SUITE.erl
  1262. $t $(MAKE) -C app1 ct $v
  1263. $i "Checking files created by '$(MAKE) ct'."
  1264. $t [ -e app1/test/m_SUITE.beam ]
  1265. $t [ -e app1/ebin/m.beam ]
  1266. $t [ -e app1/logs ]
  1267. $i "Checking that '$(MAKE) clean' does not delete logs."
  1268. $t $(MAKE) -C app1 clean $v
  1269. $t [ -e app1/logs ]
  1270. $i "Testing target 'ct-mysuite' where mysuite_SUITE is a test suite."
  1271. $t $(MAKE) -C app1 ct-m $v
  1272. $i "Checking that '$(MAKE) ct' returns non-zero for a failing suite."
  1273. $t printf "%s\n" \
  1274. "-module(failing_SUITE)." \
  1275. "-export([all/0, testcase1/1])." \
  1276. "all() -> [testcase1]." \
  1277. "testcase1(_) -> 42 = m:succ(1)." \
  1278. > app1/test/failing_SUITE.erl
  1279. $t if $(MAKE) -C app1 ct-failing $v ; then false ; fi
  1280. $i "Checking that '$(MAKE) distclean-ct' deletes logs."
  1281. $t $(MAKE) -C app1 distclean-ct $v
  1282. $t [ ! -e app1/logs ]
  1283. $t [ -e app1/ebin/m.beam ]
  1284. $i "Cleaning up test data."
  1285. $t rm -rf app1/test
  1286. $i "Test 'ct' passed."
  1287. eunit: app1
  1288. $i "eunit: Testing the 'eunit' target."
  1289. $i "Running eunit test case inside module src/t.erl"
  1290. $t $(call create-module-t)
  1291. $t $(MAKE) -C app1 distclean $v
  1292. $t $(MAKE) -C app1 eunit $v
  1293. $i "Checking that the eunit test in module t."
  1294. $t echo t | cmp app1/test-eunit.log -
  1295. $t rm app1/test-eunit.log
  1296. $i "Running eunit tests in a separate directory."
  1297. $t mkdir -p app1/eunit
  1298. $t printf '%s\n' \
  1299. '-module(t_tests).' \
  1300. '-include_lib("eunit/include/eunit.hrl").' \
  1301. 'succ_test() ->' \
  1302. ' ?assertEqual(2, t:succ(1)),' \
  1303. ' os:cmd("echo t_tests >> test-eunit.log").' \
  1304. > app1/eunit/t_tests.erl
  1305. $t printf '%s\n' \
  1306. '-module(x_tests).' \
  1307. '-include_lib("eunit/include/eunit.hrl").' \
  1308. 'succ_test() ->' \
  1309. ' ?assertEqual(2, t:succ(1)),' \
  1310. ' os:cmd("echo x_tests >> test-eunit.log").' \
  1311. > app1/eunit/x_tests.erl
  1312. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  1313. $t $(MAKE) -C app1 eunit TEST_DIR=eunit $v
  1314. $i "Checking that '$(MAKE) eunit' didn't run the tests in t_tests twice, etc."
  1315. $t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
  1316. $t rm app1/test-eunit.log
  1317. $i "Checking that '$(MAKE) eunit' returns non-zero for a failing test."
  1318. $t rm -f app1/eunit/*
  1319. $t printf "%s\n" \
  1320. "-module(t_tests)." \
  1321. '-include_lib("eunit/include/eunit.hrl").' \
  1322. "succ_test() ->" \
  1323. " ?assertEqual(42, t:succ(1))." \
  1324. > app1/eunit/t_tests.erl
  1325. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  1326. $t if $(MAKE) -C app1 eunit TEST_DIR=eunit $v ; then false ; fi
  1327. $t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
  1328. $i "Test 'eunit' passed."
  1329. # TODO: do coverage for 'tests' instead of 'eunit ct' when triq is fixed
  1330. tests-cover: app1
  1331. $i "tests-cover: Testing 'eunit' and 'ct' with COVER=1"
  1332. $i "Setting up eunit and ct suites."
  1333. $t $(call create-module-t)
  1334. $t mkdir -p app1/test
  1335. $t printf "%s\n" \
  1336. "-module(m_SUITE)." \
  1337. "-export([all/0, testcase1/1])." \
  1338. "all() -> [testcase1]." \
  1339. "testcase1(_) -> 2 = m:succ(1)." \
  1340. > app1/test/m_SUITE.erl
  1341. $i "Running tests with coverage analysis."
  1342. $t $(MAKE) -C app1 eunit ct COVER=1 $v
  1343. $t [ -e app1/test-eunit.log ]
  1344. $t [ -e app1/eunit.coverdata ]
  1345. $t [ -e app1/ct.coverdata ]
  1346. $i "Generating coverage report."
  1347. $t $(MAKE) -C app1 cover-report COVER=1 $v
  1348. $t [ -e app1/cover/m.COVER.html ]
  1349. $t [ -e app1/cover/t.COVER.html ]
  1350. $t [ -e app1/cover/index.html ]
  1351. $i "Checking combined coverage from eunit and ct."
  1352. $t [ `grep 'Total: 100%' app1/cover/index.html | wc -l` -eq 1 ]
  1353. $i "Checking that cover-report-clean removes cover report."
  1354. $t $(MAKE) -C app1 cover-report-clean $v
  1355. $t [ ! -e app1/cover ]
  1356. $i "Checking that coverdata-clean removes cover data."
  1357. $t $(MAKE) -C app1 coverdata-clean $v
  1358. $t [ ! -e app1/eunit.coverdata ]
  1359. @# clean up
  1360. $t rm -rf app1/src/t.erl app1/test app1/test-eunit.log
  1361. $t $(MAKE) -C app1 clean $v
  1362. $i "Test 'tests-cover' passed."
  1363. docs: app1
  1364. $i "docs: Testing EDoc including DOC_DEPS."
  1365. $t printf "%s\n" \
  1366. "PROJECT = app1" \
  1367. "DOC_DEPS = edown" \
  1368. "dep_edown = git https://github.com/uwiger/edown.git 0.7" \
  1369. "EDOC_OPTS = {doclet, edown_doclet}" \
  1370. "include erlang.mk" \
  1371. "distclean:: distclean-doc-md" \
  1372. "distclean-doc-md:" \
  1373. " rm -rf doc/*.md" \
  1374. > app1/Makefile-doc
  1375. $i "Downloading doc deps (edown) and building docs."
  1376. $t $(MAKE) -C app1 -f Makefile-doc docs $v
  1377. $i "Checking that '$(MAKE) docs' using edown generated a markdown file."
  1378. $t [ -e app1/doc/m.md ]
  1379. $i "Checking that '$(MAKE) distclean' deletes all generated doc files."
  1380. $t $(MAKE) -C app1 -f Makefile-doc distclean $v
  1381. $t [ "`ls app1/doc/`" = "" ]
  1382. $i "Cleaning up test data."
  1383. $t rm app1/Makefile-doc
  1384. $i "Test 'docs' passed."
  1385. define app1_setup
  1386. $i "Setting up app."
  1387. $t mkdir -p app1
  1388. $t cd .. && $(MAKE)
  1389. $t cp ../erlang.mk app1/
  1390. $t $(MAKE) -C app1 -f erlang.mk bootstrap-lib
  1391. $t printf "%s\n" \
  1392. "-module(m)." \
  1393. "-export([succ/1])." \
  1394. "succ(N) -> N + 1." \
  1395. > app1/src/m.erl
  1396. endef
  1397. define pkg_test_target
  1398. pkg-$(1)-clean:
  1399. $t rm -rf app1 erl_crash.dump
  1400. pkg-$(1)-app1:
  1401. $(call app1_setup)
  1402. # Running 'make' twice to make sure it recompiles fine.
  1403. pkg-$(1): pkg-$(1)-clean pkg-$(1)-app1
  1404. $i
  1405. $i " pkgs: Checking that '$(1)' builds correctly"
  1406. $i
  1407. $t printf "%s\n" \
  1408. "PROJECT = app1" \
  1409. "DEPS = $(1)" \
  1410. "include erlang.mk" \
  1411. > app1/Makefile
  1412. $t \
  1413. if [ "$(1)" = "amqp_client" ]; then \
  1414. $(MAKE) -C app1 RABBITMQ_CLIENT_PATCH=1; \
  1415. elif [ "$(1)" = "rabbit" ]; then \
  1416. $(MAKE) -C app1 RABBITMQ_SERVER_PATCH=1; \
  1417. else \
  1418. $(MAKE) -C app1; \
  1419. fi; \
  1420. if [ $$$$? -ne 0 ]; then \
  1421. echo "$(1): make error" >> pkgs.log; \
  1422. else \
  1423. $(MAKE) -C app1; if [ $$$$? -ne 0 ]; then \
  1424. echo "$(1): re-make error" >> pkgs.log; \
  1425. else \
  1426. find . -type f -name erl_crash.dump; if [ $$$$? -ne 0 ]; then \
  1427. echo "$(1): erl_crash.dump found" >> pkgs.log; \
  1428. else \
  1429. erl +A0 -noinput -boot start_clean -pa app1/deps/*/ebin -eval " \
  1430. Apps = [list_to_atom(App) || \"app1/deps/\" ++ App \
  1431. <- filelib:wildcard(\"app1/deps/*\")], \
  1432. [begin \
  1433. io:format(\"Loading application ~p~n\", [App]), \
  1434. case application:load(App) of \
  1435. {error, _} -> ok; \
  1436. ok -> \
  1437. {ok, Mods} = application:get_key(App, modules), \
  1438. [try io:format(\" Loading module ~p~n\", [Mod]), \
  1439. {module, Mod} = code:load_file(Mod) \
  1440. catch C:R -> timer:sleep(500), erlang:C(R) \
  1441. end || Mod <- Mods] \
  1442. end \
  1443. end || App <- Apps], \
  1444. halt()."; if [ $$$$? -ne 0 ]; then \
  1445. echo "$(1): load error" >> pkgs.log; \
  1446. fi \
  1447. fi \
  1448. fi \
  1449. fi
  1450. endef
  1451. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  1452. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_test_target,$(pkg))))
  1453. pkgs: $(addprefix pkg-,$(PACKAGES))
  1454. @if [ -f pkgs.log ]; then \
  1455. echo "+-------------------------------+"; \
  1456. echo "| ERRORS WHILE TESTING PACKAGES |"; \
  1457. echo "+-------------------------------+"; \
  1458. cat pkgs.log; \
  1459. exit 33; \
  1460. fi
  1461. # Test application used for testing.
  1462. app1:
  1463. $(call app1_setup)
  1464. # Extra module in app1 used for testing eunit
  1465. define create-module-t
  1466. printf '%s\n' \
  1467. '-module(t).' \
  1468. '-export([succ/1]).' \
  1469. 'succ(N) -> N + 1.' \
  1470. '-ifdef(TEST).' \
  1471. '-include_lib("eunit/include/eunit.hrl").' \
  1472. 'succ_test() ->' \
  1473. ' ?assertEqual(2, succ(1)),' \
  1474. ' os:cmd("echo t >> test-eunit.log").' \
  1475. '-endif.' \
  1476. > app1/src/t.erl
  1477. endef