Makefile 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826
  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 help 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-help: build clean-core-app-help
  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 "Run 'make help' and check that it prints help"
  397. $t test -n "`make -C $(APP) help` | grep Usage"
  398. core-app-hrl: build clean-core-app-hrl
  399. $i "Bootstrap a new OTP library named $(APP)"
  400. $t mkdir $(APP)/
  401. $t cp ../erlang.mk $(APP)/
  402. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  403. $i "Generate .hrl files"
  404. $t mkdir $(APP)/include/
  405. $t touch $(APP)/include/blue.hrl $(APP)/include/red.hrl
  406. $i "Generate .erl files dependent from headers"
  407. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  408. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  409. $i "Build the application"
  410. $t $(MAKE) -C $(APP) $v
  411. $i "Check that all compiled files exist"
  412. $t test -f $(APP)/$(APP).d
  413. $t test -f $(APP)/ebin/$(APP).app
  414. $t test -f $(APP)/ebin/use_blue.beam
  415. $t test -f $(APP)/ebin/use_red.beam
  416. $i "Check that the application was compiled correctly"
  417. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  418. ok = application:start($(APP)), \
  419. {ok, Mods = [use_blue, use_red]} \
  420. = application:get_key($(APP), modules), \
  421. [{module, M} = code:load_file(M) || M <- Mods], \
  422. halt()"
  423. $i "Touch one .hrl file; check that only required files are rebuilt"
  424. # The use_red.erl gets touched because of its dependency to red.hrl.
  425. $t printf "%s\n" \
  426. $(APP)/$(APP).d \
  427. $(APP)/ebin/$(APP).app \
  428. $(APP)/ebin/use_red.beam \
  429. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  430. $t touch $(APP)/include/red.hrl
  431. $t $(MAKE) -C $(APP) $v
  432. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  433. $t rm $(APP)/EXPECT
  434. $i "Check that the application was compiled correctly"
  435. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  436. ok = application:start($(APP)), \
  437. {ok, Mods = [use_blue, use_red]} \
  438. = application:get_key($(APP), modules), \
  439. [{module, M} = code:load_file(M) || M <- Mods], \
  440. halt()"
  441. $i "Clean the application"
  442. $t $(MAKE) -C $(APP) clean $v
  443. $i "Check that source files still exist"
  444. $t test -f $(APP)/Makefile
  445. $t test -f $(APP)/erlang.mk
  446. $t test -f $(APP)/include/blue.hrl
  447. $t test -f $(APP)/include/red.hrl
  448. $t test -f $(APP)/src/$(APP).app.src
  449. $t test -f $(APP)/src/use_blue.erl
  450. $t test -f $(APP)/src/use_red.erl
  451. $i "Check that all build artifacts are removed"
  452. $t test ! -e $(APP)/$(APP).d
  453. $t test ! -e $(APP)/ebin/
  454. $i "Build the application again"
  455. $t $(MAKE) -C $(APP) $v
  456. $i "Check that all compiled files exist"
  457. $t test -f $(APP)/$(APP).d
  458. $t test -f $(APP)/ebin/$(APP).app
  459. $t test -f $(APP)/ebin/use_blue.beam
  460. $t test -f $(APP)/ebin/use_red.beam
  461. $i "Check that the application was compiled correctly"
  462. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  463. ok = application:start($(APP)), \
  464. {ok, Mods = [use_blue, use_red]} \
  465. = application:get_key($(APP), modules), \
  466. [{module, M} = code:load_file(M) || M <- Mods], \
  467. halt()"
  468. core-app-hrl-recursive: build clean-core-app-hrl-recursive
  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 "Generate .hrl files"
  474. $t mkdir $(APP)/include/
  475. $t touch $(APP)/include/blue.hrl $(APP)/include/pill.hrl
  476. $t echo "-include(\"pill.hrl\")." > $(APP)/include/red.hrl
  477. $i "Generate .erl files dependent from headers"
  478. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  479. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  480. $i "Build the application"
  481. $t $(MAKE) -C $(APP) $v
  482. $i "Check that all compiled files exist"
  483. $t test -f $(APP)/$(APP).d
  484. $t test -f $(APP)/ebin/$(APP).app
  485. $t test -f $(APP)/ebin/use_blue.beam
  486. $t test -f $(APP)/ebin/use_red.beam
  487. $i "Check that the application was compiled correctly"
  488. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  489. ok = application:start($(APP)), \
  490. {ok, Mods = [use_blue, use_red]} \
  491. = application:get_key($(APP), modules), \
  492. [{module, M} = code:load_file(M) || M <- Mods], \
  493. halt()"
  494. $i "Touch the deepest .hrl file; check that only required files are rebuilt"
  495. # The use_red.erl gets touched because of its dependency to red.hrl and pill.hrl.
  496. $t printf "%s\n" \
  497. $(APP)/$(APP).d \
  498. $(APP)/ebin/$(APP).app \
  499. $(APP)/ebin/use_red.beam \
  500. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  501. $t touch $(APP)/include/pill.hrl
  502. $t $(MAKE) -C $(APP) $v
  503. $t find $(APP) -type f -newer $(APP)/include/pill.hrl | sort | diff $(APP)/EXPECT -
  504. $t rm $(APP)/EXPECT
  505. $i "Check that the application was compiled correctly"
  506. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  507. ok = application:start($(APP)), \
  508. {ok, Mods = [use_blue, use_red]} \
  509. = application:get_key($(APP), modules), \
  510. [{module, M} = code:load_file(M) || M <- Mods], \
  511. halt()"
  512. $i "Clean the application"
  513. $t $(MAKE) -C $(APP) clean $v
  514. $i "Check that source files still exist"
  515. $t test -f $(APP)/Makefile
  516. $t test -f $(APP)/erlang.mk
  517. $t test -f $(APP)/include/blue.hrl
  518. $t test -f $(APP)/include/pill.hrl
  519. $t test -f $(APP)/include/red.hrl
  520. $t test -f $(APP)/src/$(APP).app.src
  521. $t test -f $(APP)/src/use_blue.erl
  522. $t test -f $(APP)/src/use_red.erl
  523. $i "Check that all build artifacts are removed"
  524. $t test ! -e $(APP)/$(APP).d
  525. $t test ! -e $(APP)/ebin/
  526. $i "Build the application again"
  527. $t $(MAKE) -C $(APP) $v
  528. $i "Check that all compiled files exist"
  529. $t test -f $(APP)/$(APP).d
  530. $t test -f $(APP)/ebin/$(APP).app
  531. $t test -f $(APP)/ebin/use_blue.beam
  532. $t test -f $(APP)/ebin/use_red.beam
  533. $i "Check that the application was compiled correctly"
  534. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  535. ok = application:start($(APP)), \
  536. {ok, Mods = [use_blue, use_red]} \
  537. = application:get_key($(APP), modules), \
  538. [{module, M} = code:load_file(M) || M <- Mods], \
  539. halt()"
  540. core-app-mib: build clean-core-app-mib
  541. $i "Bootstrap a new OTP library named $(APP)"
  542. $t mkdir $(APP)/
  543. $t cp ../erlang.mk $(APP)/
  544. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  545. $i "Download .mib files from Erlang/OTP"
  546. $t mkdir $(APP)/mibs/
  547. $t curl -s -o $(APP)/mibs/EX1-MIB.mib $(OTP_MASTER)/lib/snmp/examples/ex1/EX1-MIB.mib
  548. $t curl -s -o $(APP)/mibs/OTP-REG.mib $(OTP_MASTER)/lib/otp_mibs/mibs/OTP-REG.mib
  549. $i "Generate .erl files dependent from headers generated by .mib files"
  550. $t printf "%s\n" "-module(use_v1)." "-include(\"EX1-MIB.hrl\")." > $(APP)/src/use_v1.erl
  551. $t printf "%s\n" "-module(use_v2)." "-include(\"OTP-REG.hrl\")." > $(APP)/src/use_v2.erl
  552. $i "Generate an unrelated .hrl file"
  553. $t mkdir $(APP)/include/
  554. $t touch $(APP)/include/unrelated.hrl
  555. $i "Build the application"
  556. $t $(MAKE) -C $(APP) $v
  557. $i "Check that all compiled files exist"
  558. $t test -f $(APP)/$(APP).d
  559. $t test -f $(APP)/ebin/$(APP).app
  560. $t test -f $(APP)/ebin/use_v1.beam
  561. $t test -f $(APP)/ebin/use_v2.beam
  562. $t test -f $(APP)/include/EX1-MIB.hrl
  563. $t test -f $(APP)/include/OTP-REG.hrl
  564. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  565. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  566. $i "Check that the application was compiled correctly"
  567. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  568. ok = application:start($(APP)), \
  569. {ok, Mods = [use_v1, use_v2]} \
  570. = application:get_key($(APP), modules), \
  571. [{module, M} = code:load_file(M) || M <- Mods], \
  572. halt()"
  573. $i "Touch one .mib file; check that only required files are rebuilt"
  574. # The use_v1.erl gets touched because of its dependency to EX1-MIB.hrl.
  575. $t printf "%s\n" \
  576. $(APP)/$(APP).d \
  577. $(APP)/ebin/$(APP).app \
  578. $(APP)/ebin/use_v1.beam \
  579. $(APP)/include/EX1-MIB.hrl \
  580. $(APP)/priv/mibs/EX1-MIB.bin \
  581. $(APP)/src/use_v1.erl | sort > $(APP)/EXPECT
  582. $t touch $(APP)/mibs/EX1-MIB.mib
  583. $t $(MAKE) -C $(APP) $v
  584. $t find $(APP) -type f -newer $(APP)/mibs/EX1-MIB.mib | sort | diff $(APP)/EXPECT -
  585. $t rm $(APP)/EXPECT
  586. $i "Check that the application was compiled correctly"
  587. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  588. ok = application:start($(APP)), \
  589. {ok, Mods = [use_v1, use_v2]} \
  590. = application:get_key($(APP), modules), \
  591. [{module, M} = code:load_file(M) || M <- Mods], \
  592. halt()"
  593. $i "Clean the application"
  594. $t $(MAKE) -C $(APP) clean $v
  595. $i "Check that source files still exist"
  596. $t test -f $(APP)/Makefile
  597. $t test -f $(APP)/erlang.mk
  598. $t test -f $(APP)/include/unrelated.hrl
  599. $t test -f $(APP)/mibs/EX1-MIB.mib
  600. $t test -f $(APP)/mibs/OTP-REG.mib
  601. $t test -f $(APP)/src/$(APP).app.src
  602. $t test -f $(APP)/src/use_v1.erl
  603. $t test -f $(APP)/src/use_v2.erl
  604. $i "Check that all build artifacts are removed, including intermediates"
  605. $t test ! -e $(APP)/$(APP).d
  606. $t test ! -e $(APP)/ebin/
  607. $t test ! -e $(APP)/include/EX1-MIB.hrl
  608. $t test ! -e $(APP)/include/OTP-REG.hrl
  609. $t test ! -e $(APP)/priv/mibs/
  610. $i "Build the application again"
  611. $t $(MAKE) -C $(APP) $v
  612. $i "Check that all compiled files exist"
  613. $t test -f $(APP)/$(APP).d
  614. $t test -f $(APP)/ebin/$(APP).app
  615. $t test -f $(APP)/ebin/use_v1.beam
  616. $t test -f $(APP)/ebin/use_v2.beam
  617. $t test -f $(APP)/include/EX1-MIB.hrl
  618. $t test -f $(APP)/include/OTP-REG.hrl
  619. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  620. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  621. $i "Check that the application was compiled correctly"
  622. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  623. ok = application:start($(APP)), \
  624. {ok, Mods = [use_v1, use_v2]} \
  625. = application:get_key($(APP), modules), \
  626. [{module, M} = code:load_file(M) || M <- Mods], \
  627. halt()"
  628. core-app-no-makedep: build clean-core-app-no-makedep
  629. $i "Bootstrap a new OTP library named $(APP)"
  630. $t mkdir $(APP)/
  631. $t cp ../erlang.mk $(APP)/
  632. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  633. $i "Set NO_MAKEDEP ?= 1 in the Makefile"
  634. $t sed -i.bak '2i\
  635. NO_MAKEDEP ?= 1\
  636. ' $(APP)/Makefile
  637. $i "Generate .hrl files"
  638. $t mkdir $(APP)/include/
  639. $t touch $(APP)/include/blue.hrl $(APP)/include/red.hrl
  640. $i "Generate .erl files dependent from headers"
  641. $t printf "%s\n" "-module(use_blue)." "-include(\"blue.hrl\")." > $(APP)/src/use_blue.erl
  642. $t printf "%s\n" "-module(use_red)." "-include(\"red.hrl\")." > $(APP)/src/use_red.erl
  643. $i "Build the application"
  644. $t $(MAKE) -C $(APP) $v
  645. $i "Check that all compiled files exist"
  646. $t test -f $(APP)/$(APP).d
  647. $t test -f $(APP)/ebin/$(APP).app
  648. $t test -f $(APP)/ebin/use_blue.beam
  649. $t test -f $(APP)/ebin/use_red.beam
  650. $i "Check that the application was compiled correctly"
  651. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  652. ok = application:start($(APP)), \
  653. {ok, Mods = [use_blue, use_red]} \
  654. = application:get_key($(APP), modules), \
  655. [{module, M} = code:load_file(M) || M <- Mods], \
  656. halt()"
  657. $i "Touch one .hrl file; check that only required files are rebuilt"
  658. # The use_red.erl gets touched because of its dependency to red.hrl.
  659. $t printf "%s\n" \
  660. $(APP)/ebin/$(APP).app \
  661. $(APP)/ebin/use_red.beam \
  662. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  663. $t touch $(APP)/include/red.hrl
  664. $t $(MAKE) -C $(APP) $v
  665. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  666. $t rm $(APP)/EXPECT
  667. $i "Check that the application was compiled correctly"
  668. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  669. ok = application:start($(APP)), \
  670. {ok, Mods = [use_blue, use_red]} \
  671. = application:get_key($(APP), modules), \
  672. [{module, M} = code:load_file(M) || M <- Mods], \
  673. halt()"
  674. $i "Touch one .hrl file; disable NO_MAKEDEP and check that only required files are rebuilt"
  675. # The use_red.erl gets touched because of its dependency to red.hrl.
  676. $t printf "%s\n" \
  677. $(APP)/$(APP).d \
  678. $(APP)/ebin/$(APP).app \
  679. $(APP)/ebin/use_red.beam \
  680. $(APP)/src/use_red.erl | sort > $(APP)/EXPECT
  681. $t touch $(APP)/include/red.hrl
  682. $t NO_MAKEDEP= $(MAKE) -C $(APP) $v
  683. $t find $(APP) -type f -newer $(APP)/include/red.hrl | sort | diff $(APP)/EXPECT -
  684. $t rm $(APP)/EXPECT
  685. $i "Check that the application was compiled correctly"
  686. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  687. ok = application:start($(APP)), \
  688. {ok, Mods = [use_blue, use_red]} \
  689. = application:get_key($(APP), modules), \
  690. [{module, M} = code:load_file(M) || M <- Mods], \
  691. halt()"
  692. $i "Clean the application"
  693. $t $(MAKE) -C $(APP) clean $v
  694. $i "Check that source files still exist"
  695. $t test -f $(APP)/Makefile
  696. $t test -f $(APP)/erlang.mk
  697. $t test -f $(APP)/include/blue.hrl
  698. $t test -f $(APP)/include/red.hrl
  699. $t test -f $(APP)/src/$(APP).app.src
  700. $t test -f $(APP)/src/use_blue.erl
  701. $t test -f $(APP)/src/use_red.erl
  702. $i "Check that all build artifacts are removed"
  703. $t test ! -e $(APP)/$(APP).d
  704. $t test ! -e $(APP)/ebin/
  705. $i "Build the application again"
  706. $t $(MAKE) -C $(APP) $v
  707. $i "Check that all compiled files exist"
  708. $t test -f $(APP)/$(APP).d
  709. $t test -f $(APP)/ebin/$(APP).app
  710. $t test -f $(APP)/ebin/use_blue.beam
  711. $t test -f $(APP)/ebin/use_red.beam
  712. $i "Check that the application was compiled correctly"
  713. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  714. ok = application:start($(APP)), \
  715. {ok, Mods = [use_blue, use_red]} \
  716. = application:get_key($(APP), modules), \
  717. [{module, M} = code:load_file(M) || M <- Mods], \
  718. halt()"
  719. core-app-xrl: build clean-core-app-xrl
  720. $i "Bootstrap a new OTP library named $(APP)"
  721. $t mkdir $(APP)/
  722. $t cp ../erlang.mk $(APP)/
  723. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  724. $i "Download .xrl files from Robert"
  725. $t curl -s -o $(APP)/src/erlang_scan.xrl https://raw.githubusercontent.com/rvirding/leex/master/examples/erlang_scan.xrl
  726. $t curl -s -o $(APP)/src/lfe_scan.xrl https://raw.githubusercontent.com/rvirding/leex/master/examples/lfe_scan.xrl
  727. $i "Generate unrelated .erl files"
  728. $t echo "-module(boy)." > $(APP)/src/boy.erl
  729. $t echo "-module(girl)." > $(APP)/src/girl.erl
  730. $i "Disable warnings; our test .xrl files aren't perfect"
  731. $t echo "ERLC_OPTS=+debug_info" >> $(APP)/Makefile
  732. $i "Build the application"
  733. $t $(MAKE) -C $(APP) $v
  734. $i "Check that all compiled files exist"
  735. $t test -f $(APP)/$(APP).d
  736. $t test -f $(APP)/ebin/$(APP).app
  737. $t test -f $(APP)/ebin/boy.beam
  738. $t test -f $(APP)/ebin/erlang_scan.beam
  739. $t test -f $(APP)/ebin/girl.beam
  740. $t test -f $(APP)/ebin/lfe_scan.beam
  741. $t test -f $(APP)/src/erlang_scan.erl
  742. $t test -f $(APP)/src/lfe_scan.erl
  743. $i "Check that the application was compiled correctly"
  744. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  745. ok = application:start($(APP)), \
  746. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  747. = application:get_key($(APP), modules), \
  748. [{module, M} = code:load_file(M) || M <- Mods], \
  749. halt()"
  750. $i "Touch one .xrl file; check that only required files are rebuilt"
  751. $t printf "%s\n" \
  752. $(APP)/$(APP).d \
  753. $(APP)/ebin/$(APP).app \
  754. $(APP)/ebin/erlang_scan.beam \
  755. $(APP)/src/erlang_scan.erl | sort > $(APP)/EXPECT
  756. $t touch $(APP)/src/erlang_scan.xrl
  757. $t $(MAKE) -C $(APP) $v
  758. $t find $(APP) -type f -newer $(APP)/src/erlang_scan.xrl | sort | diff $(APP)/EXPECT -
  759. $t rm $(APP)/EXPECT
  760. $i "Check that the application was compiled correctly"
  761. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  762. ok = application:start($(APP)), \
  763. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  764. = application:get_key($(APP), modules), \
  765. [{module, M} = code:load_file(M) || M <- Mods], \
  766. halt()"
  767. $i "Clean the application"
  768. $t $(MAKE) -C $(APP) clean $v
  769. $i "Check that source files still exist"
  770. $t test -f $(APP)/Makefile
  771. $t test -f $(APP)/erlang.mk
  772. $t test -f $(APP)/src/$(APP).app.src
  773. $t test -f $(APP)/src/boy.erl
  774. $t test -f $(APP)/src/erlang_scan.xrl
  775. $t test -f $(APP)/src/girl.erl
  776. $t test -f $(APP)/src/lfe_scan.xrl
  777. $i "Check that all build artifacts are removed, including intermediates"
  778. $t test ! -e $(APP)/$(APP).d
  779. $t test ! -e $(APP)/ebin/
  780. $t test ! -e $(APP)/src/erlang_scan.erl
  781. $t test ! -e $(APP)/src/lfe_scan.erl
  782. $i "Build the application again"
  783. $t $(MAKE) -C $(APP) $v
  784. $i "Check that all compiled files exist"
  785. $t test -f $(APP)/$(APP).d
  786. $t test -f $(APP)/ebin/$(APP).app
  787. $t test -f $(APP)/ebin/boy.beam
  788. $t test -f $(APP)/ebin/erlang_scan.beam
  789. $t test -f $(APP)/ebin/girl.beam
  790. $t test -f $(APP)/ebin/lfe_scan.beam
  791. $t test -f $(APP)/src/erlang_scan.erl
  792. $t test -f $(APP)/src/lfe_scan.erl
  793. $i "Check that the application was compiled correctly"
  794. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  795. ok = application:start($(APP)), \
  796. {ok, Mods = [boy, erlang_scan, girl, lfe_scan]} \
  797. = application:get_key($(APP), modules), \
  798. [{module, M} = code:load_file(M) || M <- Mods], \
  799. halt()"
  800. core-app-xrl-include: build clean-core-app-xrl-include
  801. $i "Bootstrap a new OTP library named $(APP)"
  802. $t mkdir $(APP)/
  803. $t cp ../erlang.mk $(APP)/
  804. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  805. $i "Download a .xrl file with numerous includes from Gordon"
  806. $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
  807. $t curl -s -o $(APP)/src/errvals.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/errvals.hrl
  808. $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
  809. $t curl -s -o $(APP)/src/muin_records.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/muin_records.hrl
  810. $t curl -s -o $(APP)/src/typechecks.hrl https://raw.githubusercontent.com/hypernumbers/hypernumbers/master/lib/hypernumbers-1.0/include/typechecks.hrl
  811. $i "Generate unrelated .erl files"
  812. $t echo "-module(boy)." > $(APP)/src/boy.erl
  813. $t echo "-module(girl)." > $(APP)/src/girl.erl
  814. $i "Disable warnings; our test .xrl files aren't perfect"
  815. $t echo "ERLC_OPTS=+debug_info" >> $(APP)/Makefile
  816. $i "Build the application"
  817. $t $(MAKE) -C $(APP) $v
  818. $i "Check that all compiled files exist"
  819. $t test -f $(APP)/$(APP).d
  820. $t test -f $(APP)/ebin/$(APP).app
  821. $t test -f $(APP)/ebin/boy.beam
  822. $t test -f $(APP)/ebin/girl.beam
  823. $t test -f $(APP)/ebin/xfl_lexer.beam
  824. $t test -f $(APP)/src/xfl_lexer.erl
  825. $i "Check that the application was compiled correctly"
  826. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  827. ok = application:start($(APP)), \
  828. {ok, Mods = [boy, girl, xfl_lexer]} \
  829. = application:get_key($(APP), modules), \
  830. [{module, M} = code:load_file(M) || M <- Mods], \
  831. halt()"
  832. $i "Touch the .xrl file; check that only required files are rebuilt"
  833. $t printf "%s\n" \
  834. $(APP)/$(APP).d \
  835. $(APP)/ebin/$(APP).app \
  836. $(APP)/ebin/xfl_lexer.beam \
  837. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  838. $t touch $(APP)/src/xfl_lexer.xrl
  839. $t $(MAKE) -C $(APP) $v
  840. $t find $(APP) -type f -newer $(APP)/src/xfl_lexer.xrl | sort | diff $(APP)/EXPECT -
  841. $t rm $(APP)/EXPECT
  842. $i "Check that the application was compiled correctly"
  843. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  844. ok = application:start($(APP)), \
  845. {ok, Mods = [boy, girl, xfl_lexer]} \
  846. = application:get_key($(APP), modules), \
  847. [{module, M} = code:load_file(M) || M <- Mods], \
  848. halt()"
  849. $i "Touch a .hrl file included directly; check that only required files are rebuilt"
  850. $t printf "%s\n" \
  851. $(APP)/$(APP).d \
  852. $(APP)/ebin/$(APP).app \
  853. $(APP)/ebin/xfl_lexer.beam \
  854. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  855. $t touch $(APP)/src/typechecks.hrl
  856. $t $(MAKE) -C $(APP) $v
  857. $t find $(APP) -type f -newer $(APP)/src/typechecks.hrl | sort | diff $(APP)/EXPECT -
  858. $t rm $(APP)/EXPECT
  859. $i "Check that the application was compiled correctly"
  860. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  861. ok = application:start($(APP)), \
  862. {ok, Mods = [boy, girl, xfl_lexer]} \
  863. = application:get_key($(APP), modules), \
  864. [{module, M} = code:load_file(M) || M <- Mods], \
  865. halt()"
  866. $i "Touch a .hrl file included indirectly; check that only required files are rebuilt"
  867. $t printf "%s\n" \
  868. $(APP)/$(APP).d \
  869. $(APP)/ebin/$(APP).app \
  870. $(APP)/ebin/xfl_lexer.beam \
  871. $(APP)/src/xfl_lexer.erl | sort > $(APP)/EXPECT
  872. $t touch $(APP)/src/errvals.hrl
  873. $t $(MAKE) -C $(APP) $v
  874. $t find $(APP) -type f -newer $(APP)/src/errvals.hrl | sort | diff $(APP)/EXPECT -
  875. $t rm $(APP)/EXPECT
  876. $i "Check that the application was compiled correctly"
  877. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  878. ok = application:start($(APP)), \
  879. {ok, Mods = [boy, girl, xfl_lexer]} \
  880. = application:get_key($(APP), modules), \
  881. [{module, M} = code:load_file(M) || M <- Mods], \
  882. halt()"
  883. $i "Clean the application"
  884. $t $(MAKE) -C $(APP) clean $v
  885. $i "Check that source files still exist"
  886. $t test -f $(APP)/Makefile
  887. $t test -f $(APP)/erlang.mk
  888. $t test -f $(APP)/src/$(APP).app.src
  889. $t test -f $(APP)/src/boy.erl
  890. $t test -f $(APP)/src/girl.erl
  891. $t test -f $(APP)/src/errvals.hrl
  892. $t test -f $(APP)/src/muin_proc_dict.hrl
  893. $t test -f $(APP)/src/muin_records.hrl
  894. $t test -f $(APP)/src/typechecks.hrl
  895. $t test -f $(APP)/src/xfl_lexer.xrl
  896. $i "Check that all build artifacts are removed, including intermediates"
  897. $t test ! -e $(APP)/$(APP).d
  898. $t test ! -e $(APP)/ebin/
  899. $t test ! -e $(APP)/src/xfl_lexer.erl
  900. $i "Build the application again"
  901. $t $(MAKE) -C $(APP) $v
  902. $i "Check that all compiled files exist"
  903. $t test -f $(APP)/$(APP).d
  904. $t test -f $(APP)/ebin/$(APP).app
  905. $t test -f $(APP)/ebin/boy.beam
  906. $t test -f $(APP)/ebin/girl.beam
  907. $t test -f $(APP)/ebin/xfl_lexer.beam
  908. $t test -f $(APP)/src/xfl_lexer.erl
  909. $i "Check that the application was compiled correctly"
  910. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  911. ok = application:start($(APP)), \
  912. {ok, Mods = [boy, girl, xfl_lexer]} \
  913. = application:get_key($(APP), modules), \
  914. [{module, M} = code:load_file(M) || M <- Mods], \
  915. halt()"
  916. core-app-yrl: build clean-core-app-yrl
  917. $i "Bootstrap a new OTP library named $(APP)"
  918. $t mkdir $(APP)/
  919. $t cp ../erlang.mk $(APP)/
  920. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  921. $i "Download .yrl files from Erlang/OTP"
  922. $t curl -s -o $(APP)/src/xmerl_xpath_parse.yrl $(OTP_MASTER)/lib/xmerl/src/xmerl_xpath_parse.yrl
  923. $t curl -s -o $(APP)/src/xref_parser.yrl $(OTP_MASTER)/lib/tools/src/xref_parser.yrl
  924. $i "Generate unrelated .erl files"
  925. $t echo "-module(boy)." > $(APP)/src/boy.erl
  926. $t echo "-module(girl)." > $(APP)/src/girl.erl
  927. $i "Build the application"
  928. $t $(MAKE) -C $(APP) $v
  929. $i "Check that all compiled files exist"
  930. $t test -f $(APP)/$(APP).d
  931. $t test -f $(APP)/ebin/$(APP).app
  932. $t test -f $(APP)/ebin/boy.beam
  933. $t test -f $(APP)/ebin/girl.beam
  934. $t test -f $(APP)/ebin/xmerl_xpath_parse.beam
  935. $t test -f $(APP)/ebin/xref_parser.beam
  936. $t test -f $(APP)/src/xmerl_xpath_parse.erl
  937. $t test -f $(APP)/src/xref_parser.erl
  938. $i "Check that the application was compiled correctly"
  939. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  940. ok = application:start($(APP)), \
  941. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  942. = application:get_key($(APP), modules), \
  943. [{module, M} = code:load_file(M) || M <- Mods], \
  944. halt()"
  945. $i "Touch one .yrl file; check that only required files are rebuilt"
  946. $t printf "%s\n" \
  947. $(APP)/$(APP).d \
  948. $(APP)/ebin/$(APP).app \
  949. $(APP)/ebin/xref_parser.beam \
  950. $(APP)/src/xref_parser.erl | sort > $(APP)/EXPECT
  951. $t touch $(APP)/src/xref_parser.yrl
  952. $t $(MAKE) -C $(APP) $v
  953. $t find $(APP) -type f -newer $(APP)/src/xref_parser.yrl | sort | diff $(APP)/EXPECT -
  954. $t rm $(APP)/EXPECT
  955. $i "Check that the application was compiled correctly"
  956. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  957. ok = application:start($(APP)), \
  958. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  959. = application:get_key($(APP), modules), \
  960. [{module, M} = code:load_file(M) || M <- Mods], \
  961. halt()"
  962. $i "Clean the application"
  963. $t $(MAKE) -C $(APP) clean $v
  964. $i "Check that source files still exist"
  965. $t test -f $(APP)/Makefile
  966. $t test -f $(APP)/erlang.mk
  967. $t test -f $(APP)/src/$(APP).app.src
  968. $t test -f $(APP)/src/boy.erl
  969. $t test -f $(APP)/src/girl.erl
  970. $t test -f $(APP)/src/xmerl_xpath_parse.yrl
  971. $t test -f $(APP)/src/xref_parser.yrl
  972. $i "Check that all build artifacts are removed, including intermediates"
  973. $t test ! -e $(APP)/$(APP).d
  974. $t test ! -e $(APP)/ebin/
  975. $t test ! -e $(APP)/src/xmerl_xpath_parse.erl
  976. $t test ! -e $(APP)/src/xref_parser.erl
  977. $i "Build the application again"
  978. $t $(MAKE) -C $(APP) $v
  979. $i "Check that all compiled files exist"
  980. $t test -f $(APP)/$(APP).d
  981. $t test -f $(APP)/ebin/$(APP).app
  982. $t test -f $(APP)/ebin/boy.beam
  983. $t test -f $(APP)/ebin/girl.beam
  984. $t test -f $(APP)/ebin/xmerl_xpath_parse.beam
  985. $t test -f $(APP)/ebin/xref_parser.beam
  986. $t test -f $(APP)/src/xmerl_xpath_parse.erl
  987. $t test -f $(APP)/src/xref_parser.erl
  988. $i "Check that the application was compiled correctly"
  989. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  990. ok = application:start($(APP)), \
  991. {ok, Mods = [boy, girl, xmerl_xpath_parse, xref_parser]} \
  992. = application:get_key($(APP), modules), \
  993. [{module, M} = code:load_file(M) || M <- Mods], \
  994. halt()"
  995. core-app-yrl-include: build clean-core-app-yrl-include
  996. $i "Bootstrap a new OTP library named $(APP)"
  997. $t mkdir $(APP)/
  998. $t cp ../erlang.mk $(APP)/
  999. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1000. $i "Download a .yrl file with includes from Erlang/OTP"
  1001. $t curl -s -o $(APP)/src/core_parse.yrl $(OTP_MASTER)/lib/compiler/src/core_parse.yrl
  1002. $t curl -s -o $(APP)/src/core_parse.hrl $(OTP_MASTER)/lib/compiler/src/core_parse.hrl
  1003. $i "Generate unrelated .erl files"
  1004. $t echo "-module(boy)." > $(APP)/src/boy.erl
  1005. $t echo "-module(girl)." > $(APP)/src/girl.erl
  1006. $i "Build the application"
  1007. $t $(MAKE) -C $(APP) $v
  1008. $i "Check that all compiled files exist"
  1009. $t test -f $(APP)/$(APP).d
  1010. $t test -f $(APP)/ebin/$(APP).app
  1011. $t test -f $(APP)/ebin/boy.beam
  1012. $t test -f $(APP)/ebin/core_parse.beam
  1013. $t test -f $(APP)/ebin/girl.beam
  1014. $t test -f $(APP)/src/core_parse.erl
  1015. $i "Check that the application was compiled correctly"
  1016. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1017. ok = application:start($(APP)), \
  1018. {ok, Mods = [boy, core_parse, girl]} \
  1019. = application:get_key($(APP), modules), \
  1020. [{module, M} = code:load_file(M) || M <- Mods], \
  1021. halt()"
  1022. $i "Touch the .yrl file; check that only required files are rebuilt"
  1023. $t printf "%s\n" \
  1024. $(APP)/$(APP).d \
  1025. $(APP)/ebin/$(APP).app \
  1026. $(APP)/ebin/core_parse.beam \
  1027. $(APP)/src/core_parse.erl | sort > $(APP)/EXPECT
  1028. $t touch $(APP)/src/core_parse.yrl
  1029. $t $(MAKE) -C $(APP) $v
  1030. $t find $(APP) -type f -newer $(APP)/src/core_parse.yrl | sort | diff $(APP)/EXPECT -
  1031. $t rm $(APP)/EXPECT
  1032. $i "Check that the application was compiled correctly"
  1033. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1034. ok = application:start($(APP)), \
  1035. {ok, Mods = [boy, core_parse, girl]} \
  1036. = application:get_key($(APP), modules), \
  1037. [{module, M} = code:load_file(M) || M <- Mods], \
  1038. halt()"
  1039. $i "Touch the .hrl file included; check that only required files are rebuilt"
  1040. $t printf "%s\n" \
  1041. $(APP)/$(APP).d \
  1042. $(APP)/ebin/$(APP).app \
  1043. $(APP)/ebin/core_parse.beam \
  1044. $(APP)/src/core_parse.erl | sort > $(APP)/EXPECT
  1045. $t touch $(APP)/src/core_parse.hrl
  1046. $t $(MAKE) -C $(APP) $v
  1047. $t find $(APP) -type f -newer $(APP)/src/core_parse.hrl | sort | diff $(APP)/EXPECT -
  1048. $t rm $(APP)/EXPECT
  1049. $i "Check that the application was compiled correctly"
  1050. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1051. ok = application:start($(APP)), \
  1052. {ok, Mods = [boy, core_parse, girl]} \
  1053. = application:get_key($(APP), modules), \
  1054. [{module, M} = code:load_file(M) || M <- Mods], \
  1055. halt()"
  1056. $i "Clean the application"
  1057. $t $(MAKE) -C $(APP) clean $v
  1058. $i "Check that source files still exist"
  1059. $t test -f $(APP)/Makefile
  1060. $t test -f $(APP)/erlang.mk
  1061. $t test -f $(APP)/src/$(APP).app.src
  1062. $t test -f $(APP)/src/boy.erl
  1063. $t test -f $(APP)/src/core_parse.hrl
  1064. $t test -f $(APP)/src/core_parse.yrl
  1065. $t test -f $(APP)/src/girl.erl
  1066. $i "Check that all build artifacts are removed, including intermediates"
  1067. $t test ! -e $(APP)/$(APP).d
  1068. $t test ! -e $(APP)/ebin/
  1069. $t test ! -e $(APP)/src/core_parse.erl
  1070. $i "Build the application again"
  1071. $t $(MAKE) -C $(APP) $v
  1072. $i "Check that all compiled files exist"
  1073. $t test -f $(APP)/$(APP).d
  1074. $t test -f $(APP)/ebin/$(APP).app
  1075. $t test -f $(APP)/ebin/boy.beam
  1076. $t test -f $(APP)/ebin/core_parse.beam
  1077. $t test -f $(APP)/ebin/girl.beam
  1078. $t test -f $(APP)/src/core_parse.erl
  1079. $i "Check that the application was compiled correctly"
  1080. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1081. ok = application:start($(APP)), \
  1082. {ok, Mods = [boy, core_parse, girl]} \
  1083. = application:get_key($(APP), modules), \
  1084. [{module, M} = code:load_file(M) || M <- Mods], \
  1085. halt()"
  1086. clean-core-app: $(CORE_APP_CLEAN_TARGETS)
  1087. $(CORE_APP_CLEAN_TARGETS):
  1088. $t rm -rf $(APP_TO_CLEAN)/
  1089. # Core: Erlang.mk upgrade.
  1090. CORE_UPGRADE_CASES = alt-erlangmk-repo no-config custom-config renamed-config custom-build-dir
  1091. CORE_UPGRADE_TARGETS = $(addprefix core-upgrade-,$(CORE_UPGRADE_CASES))
  1092. CORE_UPGRADE_CLEAN_TARGETS = $(addprefix clean-,$(CORE_UPGRADE_TARGETS))
  1093. .PHONY: core-upgrade $(CORE_UPGRADE_TARGETS) $(CORE_UPGRADE_CLEAN_TARGETS)
  1094. core-upgrade: $(CORE_UPGRADE_TARGETS)
  1095. core-upgrade-alt-erlangmk-repo: build clean-core-upgrade-alt-erlangmk-repo
  1096. $i "Bootstrap a new OTP library named $(APP)"
  1097. $t mkdir $(APP)/
  1098. $t cp ../erlang.mk $(APP)/
  1099. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1100. $i "Fork erlang.mk locally and modify it"
  1101. $t git clone -q file://$(abspath $(CURDIR)/..) $(APP)/alt-erlangmk-repo
  1102. $t sed -i.bak '1i\
  1103. # Copyright (c) erlang.mk Testsuite!\
  1104. ' $(APP)/alt-erlangmk-repo/core/core.mk
  1105. $t (cd $(APP)/alt-erlangmk-repo && \
  1106. git checkout -q -b test-copyright && \
  1107. git commit -q -a -m 'Add Testsuite copyright')
  1108. $i "Point application to an alternate erlang.mk repository"
  1109. $t sed -i.bak '2i\
  1110. ERLANG_MK_REPO = file://$(abspath $(APP)/alt-erlangmk-repo)\
  1111. ERLANG_MK_COMMIT = test-copyright\
  1112. ' $(APP)/Makefile
  1113. $i "Update erlang.mk"
  1114. $t $(MAKE) -C $(APP) erlang-mk $v
  1115. $i "Check our modification is there"
  1116. $t grep -q "# Copyright (c) erlang.mk Testsuite!" $(APP)/erlang.mk
  1117. core-upgrade-no-config: build clean-core-upgrade-no-config
  1118. $i "Bootstrap a new OTP library named $(APP)"
  1119. $t mkdir $(APP)/
  1120. $t cp ../erlang.mk $(APP)/
  1121. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1122. $i "Append a rule to the Erlang.mk file for testing purposes"
  1123. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  1124. $i "Check that the test rule works as intended"
  1125. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  1126. $i "Upgrade Erlang.mk"
  1127. $t $(MAKE) -C $(APP) erlang-mk $v
  1128. $i "Check that the rule is gone"
  1129. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  1130. core-upgrade-custom-config: build clean-core-upgrade-custom-config
  1131. $i "Bootstrap a new OTP library named $(APP)"
  1132. $t mkdir $(APP)/
  1133. $t cp ../erlang.mk $(APP)/
  1134. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1135. $i "Create a custom build.config file without plugins"
  1136. $t echo "core/*" > $(APP)/build.config
  1137. $i "Upgrade Erlang.mk"
  1138. $t $(MAKE) -C $(APP) erlang-mk $v
  1139. $i "Check that the bootstrap plugin is gone"
  1140. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  1141. core-upgrade-renamed-config: build clean-core-upgrade-renamed-config
  1142. $i "Bootstrap a new OTP library named $(APP)"
  1143. $t mkdir $(APP)/
  1144. $t cp ../erlang.mk $(APP)/
  1145. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1146. $i "Create a custom build.config file without plugins; name it my.build.config"
  1147. $t echo "core/*" > $(APP)/my.build.config
  1148. $i "Set ERLANG_MK_BUILD_CONFIG=my.build.config in the Makefile"
  1149. $t echo "ERLANG_MK_BUILD_CONFIG = my.build.config" >> $(APP)/Makefile
  1150. $i "Upgrade Erlang.mk"
  1151. $t $(MAKE) -C $(APP) erlang-mk $v
  1152. $i "Check that the bootstrap plugin is gone"
  1153. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  1154. core-upgrade-custom-build-dir: build clean-core-upgrade-custom-build-dir
  1155. $i "Bootstrap a new OTP library named $(APP)"
  1156. $t mkdir $(APP)/
  1157. $t cp ../erlang.mk $(APP)/
  1158. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1159. $i "Append a rule to the Erlang.mk file for testing purposes"
  1160. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  1161. $i "Check that the test rule works as intended"
  1162. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  1163. $i "Create the custom build directory"
  1164. $t mkdir $(APP)/custom/
  1165. $t test -d $(APP)/custom/
  1166. $i "Upgrade Erlang.mk with a custom build directory"
  1167. $t ERLANG_MK_BUILD_DIR=custom $(MAKE) -C $(APP) erlang-mk $v
  1168. $i "Check that the rule is gone"
  1169. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  1170. $i "Check that the custom build directory is gone"
  1171. $t test ! -d $(APP)/custom/
  1172. clean-core-upgrade: $(CORE_UPGRADE_CLEAN_TARGETS)
  1173. $(CORE_UPGRADE_CLEAN_TARGETS):
  1174. $t rm -rf $(APP_TO_CLEAN)/
  1175. # Bootstrap plugin.
  1176. BOOTSTRAP_CASES = app lib rel templates
  1177. BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
  1178. BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
  1179. .PHONY: bootstrap $(BOOTSTRAP_TARGETS) $(BOOTSTRAP_CLEAN_TARGETS)
  1180. bootstrap: $(BOOTSTRAP_TARGETS)
  1181. bootstrap-app: build clean-bootstrap-app
  1182. $i "Bootstrap a new OTP application named $(APP)"
  1183. $t mkdir $(APP)/
  1184. $t cp ../erlang.mk $(APP)/
  1185. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  1186. $i "Check that all bootstrapped files exist"
  1187. $t test -f $(APP)/Makefile
  1188. $t test -f $(APP)/src/$(APP).app.src
  1189. $t test -f $(APP)/src/$(APP)_app.erl
  1190. $t test -f $(APP)/src/$(APP)_sup.erl
  1191. $i "Build the application"
  1192. $t $(MAKE) -C $(APP) $v
  1193. $i "Check that all compiled files exist"
  1194. $t test -f $(APP)/ebin/$(APP).app
  1195. $t test -f $(APP)/ebin/$(APP)_app.beam
  1196. $t test -f $(APP)/ebin/$(APP)_sup.beam
  1197. $i "Check that the application was compiled correctly"
  1198. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1199. ok = application:start($(APP)), \
  1200. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  1201. {module, $(APP)_app} = code:load_file($(APP)_app), \
  1202. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  1203. halt()"
  1204. bootstrap-lib: build clean-bootstrap-lib
  1205. $i "Bootstrap a new OTP library named $(APP)"
  1206. $t mkdir $(APP)/
  1207. $t cp ../erlang.mk $(APP)/
  1208. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1209. $i "Check that all bootstrapped files exist"
  1210. $t test -f $(APP)/Makefile
  1211. $t test -f $(APP)/src/$(APP).app.src
  1212. $i "Build the application"
  1213. $t $(MAKE) -C $(APP) $v
  1214. $i "Check that all compiled files exist"
  1215. $t test -f $(APP)/ebin/$(APP).app
  1216. $i "Check that the application was compiled correctly"
  1217. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1218. ok = application:start($(APP)), \
  1219. {ok, []} = application:get_key($(APP), modules), \
  1220. halt()"
  1221. bootstrap-rel: build clean-bootstrap-rel
  1222. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  1223. $t mkdir $(APP)/
  1224. $t cp ../erlang.mk $(APP)/
  1225. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  1226. $i "Check that all bootstrapped files exist"
  1227. $t test -f $(APP)/Makefile
  1228. $t test -f $(APP)/relx.config
  1229. $t test -f $(APP)/rel/sys.config
  1230. $t test -f $(APP)/rel/vm.args
  1231. $t test -f $(APP)/src/$(APP).app.src
  1232. $t test -f $(APP)/src/$(APP)_app.erl
  1233. $t test -f $(APP)/src/$(APP)_sup.erl
  1234. $i "Build the application and the release"
  1235. $t $(MAKE) -C $(APP) $v
  1236. $i "Check that all compiled files exist"
  1237. $t test -f $(APP)/ebin/$(APP).app
  1238. $t test -f $(APP)/ebin/$(APP)_app.beam
  1239. $t test -f $(APP)/ebin/$(APP)_sup.beam
  1240. $i "Check that the release was generated"
  1241. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  1242. $i "Check that the release can be started and stopped"
  1243. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  1244. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  1245. $i "Check that there's no erl_crash.dump file"
  1246. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  1247. bootstrap-templates: build clean-bootstrap-templates
  1248. $i "Bootstrap a new OTP library named $(APP)"
  1249. $t mkdir $(APP)/
  1250. $t cp ../erlang.mk $(APP)/
  1251. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  1252. $i "Check that we can get the list of templates"
  1253. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  1254. $i "Generate one of each template"
  1255. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  1256. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  1257. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  1258. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  1259. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  1260. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  1261. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  1262. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  1263. # Here we disable warnings because templates contain missing behaviors.
  1264. $i "Build the application"
  1265. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  1266. $i "Check that all compiled files exist"
  1267. $t test -f $(APP)/ebin/$(APP).app
  1268. $t test -f $(APP)/ebin/my_fsm.beam
  1269. $t test -f $(APP)/ebin/my_server.beam
  1270. $t test -f $(APP)/ebin/my_sup.beam
  1271. $i "Check that all the modules can be loaded"
  1272. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  1273. ok = application:start($(APP)), \
  1274. {ok, Mods = [my_fsm, my_http, my_loop, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  1275. = application:get_key($(APP), modules), \
  1276. [{module, M} = code:load_file(M) || M <- Mods], \
  1277. halt()"
  1278. clean-bootstrap: $(BOOTSTRAP_CLEAN_TARGETS)
  1279. $(BOOTSTRAP_CLEAN_TARGETS):
  1280. $t rm -rf $(APP_TO_CLEAN)/
  1281. ########################################
  1282. # Legacy tests.
  1283. ct: app1
  1284. $i "ct: Testing ct and related targets."
  1285. $i "Setting up test suite."
  1286. $t mkdir -p app1/test
  1287. $t printf "%s\n" \
  1288. "-module(m_SUITE)." \
  1289. "-export([all/0, testcase1/1])." \
  1290. "all() -> [testcase1]." \
  1291. "testcase1(_) -> 2 = m:succ(1)." \
  1292. > app1/test/m_SUITE.erl
  1293. $t $(MAKE) -C app1 ct $v
  1294. $i "Checking files created by '$(MAKE) ct'."
  1295. $t [ -e app1/test/m_SUITE.beam ]
  1296. $t [ -e app1/ebin/m.beam ]
  1297. $t [ -e app1/logs ]
  1298. $i "Checking that '$(MAKE) clean' does not delete logs."
  1299. $t $(MAKE) -C app1 clean $v
  1300. $t [ -e app1/logs ]
  1301. $i "Testing target 'ct-mysuite' where mysuite_SUITE is a test suite."
  1302. $t $(MAKE) -C app1 ct-m $v
  1303. $i "Checking that '$(MAKE) ct' returns non-zero for a failing suite."
  1304. $t printf "%s\n" \
  1305. "-module(failing_SUITE)." \
  1306. "-export([all/0, testcase1/1])." \
  1307. "all() -> [testcase1]." \
  1308. "testcase1(_) -> 42 = m:succ(1)." \
  1309. > app1/test/failing_SUITE.erl
  1310. $t if $(MAKE) -C app1 ct-failing $v ; then false ; fi
  1311. $i "Checking that '$(MAKE) distclean-ct' deletes logs."
  1312. $t $(MAKE) -C app1 distclean-ct $v
  1313. $t [ ! -e app1/logs ]
  1314. $t [ -e app1/ebin/m.beam ]
  1315. $i "Cleaning up test data."
  1316. $t rm -rf app1/test
  1317. $i "Test 'ct' passed."
  1318. eunit: app1
  1319. $i "eunit: Testing the 'eunit' target."
  1320. $i "Running eunit test case inside module src/t.erl"
  1321. $t $(call create-module-t)
  1322. $t $(MAKE) -C app1 distclean $v
  1323. $t $(MAKE) -C app1 eunit $v
  1324. $i "Checking that the eunit test in module t."
  1325. $t echo t | cmp app1/test-eunit.log -
  1326. $t rm app1/test-eunit.log
  1327. $i "Running eunit tests in a separate directory."
  1328. $t mkdir -p app1/eunit
  1329. $t printf '%s\n' \
  1330. '-module(t_tests).' \
  1331. '-include_lib("eunit/include/eunit.hrl").' \
  1332. 'succ_test() ->' \
  1333. ' ?assertEqual(2, t:succ(1)),' \
  1334. ' os:cmd("echo t_tests >> test-eunit.log").' \
  1335. > app1/eunit/t_tests.erl
  1336. $t printf '%s\n' \
  1337. '-module(x_tests).' \
  1338. '-include_lib("eunit/include/eunit.hrl").' \
  1339. 'succ_test() ->' \
  1340. ' ?assertEqual(2, t:succ(1)),' \
  1341. ' os:cmd("echo x_tests >> test-eunit.log").' \
  1342. > app1/eunit/x_tests.erl
  1343. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  1344. $t $(MAKE) -C app1 eunit TEST_DIR=eunit $v
  1345. $i "Checking that '$(MAKE) eunit' didn't run the tests in t_tests twice, etc."
  1346. $t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
  1347. $t rm app1/test-eunit.log
  1348. $i "Checking that '$(MAKE) eunit' returns non-zero for a failing test."
  1349. $t rm -f app1/eunit/*
  1350. $t printf "%s\n" \
  1351. "-module(t_tests)." \
  1352. '-include_lib("eunit/include/eunit.hrl").' \
  1353. "succ_test() ->" \
  1354. " ?assertEqual(42, t:succ(1))." \
  1355. > app1/eunit/t_tests.erl
  1356. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  1357. $t if $(MAKE) -C app1 eunit TEST_DIR=eunit $v ; then false ; fi
  1358. $t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
  1359. $i "Test 'eunit' passed."
  1360. # TODO: do coverage for 'tests' instead of 'eunit ct' when triq is fixed
  1361. tests-cover: app1
  1362. $i "tests-cover: Testing 'eunit' and 'ct' with COVER=1"
  1363. $i "Setting up eunit and ct suites."
  1364. $t $(call create-module-t)
  1365. $t mkdir -p app1/test
  1366. $t printf "%s\n" \
  1367. "-module(m_SUITE)." \
  1368. "-export([all/0, testcase1/1])." \
  1369. "all() -> [testcase1]." \
  1370. "testcase1(_) -> 2 = m:succ(1)." \
  1371. > app1/test/m_SUITE.erl
  1372. $i "Running tests with coverage analysis."
  1373. $t $(MAKE) -C app1 eunit ct COVER=1 $v
  1374. $t [ -e app1/test-eunit.log ]
  1375. $t [ -e app1/eunit.coverdata ]
  1376. $t [ -e app1/ct.coverdata ]
  1377. $i "Generating coverage report."
  1378. $t $(MAKE) -C app1 cover-report COVER=1 $v
  1379. $t [ -e app1/cover/m.COVER.html ]
  1380. $t [ -e app1/cover/t.COVER.html ]
  1381. $t [ -e app1/cover/index.html ]
  1382. $i "Checking combined coverage from eunit and ct."
  1383. $t [ `grep 'Total: 100%' app1/cover/index.html | wc -l` -eq 1 ]
  1384. $i "Checking that cover-report-clean removes cover report."
  1385. $t $(MAKE) -C app1 cover-report-clean $v
  1386. $t [ ! -e app1/cover ]
  1387. $i "Checking that coverdata-clean removes cover data."
  1388. $t $(MAKE) -C app1 coverdata-clean $v
  1389. $t [ ! -e app1/eunit.coverdata ]
  1390. @# clean up
  1391. $t rm -rf app1/src/t.erl app1/test app1/test-eunit.log
  1392. $t $(MAKE) -C app1 clean $v
  1393. $i "Test 'tests-cover' passed."
  1394. docs: app1
  1395. $i "docs: Testing EDoc including DOC_DEPS."
  1396. $t printf "%s\n" \
  1397. "PROJECT = app1" \
  1398. "DOC_DEPS = edown" \
  1399. "dep_edown = git https://github.com/uwiger/edown.git 0.7" \
  1400. "EDOC_OPTS = {doclet, edown_doclet}" \
  1401. "include erlang.mk" \
  1402. "distclean:: distclean-doc-md" \
  1403. "distclean-doc-md:" \
  1404. " rm -rf doc/*.md" \
  1405. > app1/Makefile-doc
  1406. $i "Downloading doc deps (edown) and building docs."
  1407. $t $(MAKE) -C app1 -f Makefile-doc docs $v
  1408. $i "Checking that '$(MAKE) docs' using edown generated a markdown file."
  1409. $t [ -e app1/doc/m.md ]
  1410. $i "Checking that '$(MAKE) distclean' deletes all generated doc files."
  1411. $t $(MAKE) -C app1 -f Makefile-doc distclean $v
  1412. $t [ "`ls app1/doc/`" = "" ]
  1413. $i "Cleaning up test data."
  1414. $t rm app1/Makefile-doc
  1415. $i "Test 'docs' passed."
  1416. define app1_setup
  1417. $i "Setting up app."
  1418. $t mkdir -p app1
  1419. $t cd .. && $(MAKE)
  1420. $t cp ../erlang.mk app1/
  1421. $t $(MAKE) -C app1 -f erlang.mk bootstrap-lib
  1422. $t printf "%s\n" \
  1423. "-module(m)." \
  1424. "-export([succ/1])." \
  1425. "succ(N) -> N + 1." \
  1426. > app1/src/m.erl
  1427. endef
  1428. define pkg_test_target
  1429. pkg-$(1)-clean:
  1430. $t rm -rf app1 erl_crash.dump
  1431. pkg-$(1)-app1:
  1432. $(call app1_setup)
  1433. # Running 'make' twice to make sure it recompiles fine.
  1434. pkg-$(1): pkg-$(1)-clean pkg-$(1)-app1
  1435. $i
  1436. $i " pkgs: Checking that '$(1)' builds correctly"
  1437. $i
  1438. $t printf "%s\n" \
  1439. "PROJECT = app1" \
  1440. "DEPS = $(1)" \
  1441. "include erlang.mk" \
  1442. > app1/Makefile
  1443. $t \
  1444. if [ "$(1)" = "amqp_client" ]; then \
  1445. $(MAKE) -C app1 RABBITMQ_CLIENT_PATCH=1; \
  1446. elif [ "$(1)" = "rabbit" ]; then \
  1447. $(MAKE) -C app1 RABBITMQ_SERVER_PATCH=1; \
  1448. else \
  1449. $(MAKE) -C app1; \
  1450. fi; \
  1451. if [ $$$$? -ne 0 ]; then \
  1452. echo "$(1): make error" >> pkgs.log; \
  1453. else \
  1454. $(MAKE) -C app1; if [ $$$$? -ne 0 ]; then \
  1455. echo "$(1): re-make error" >> pkgs.log; \
  1456. else \
  1457. find . -type f -name erl_crash.dump; if [ $$$$? -ne 0 ]; then \
  1458. echo "$(1): erl_crash.dump found" >> pkgs.log; \
  1459. else \
  1460. erl +A0 -noinput -boot start_clean -pa app1/deps/*/ebin -eval " \
  1461. Apps = [list_to_atom(App) || \"app1/deps/\" ++ App \
  1462. <- filelib:wildcard(\"app1/deps/*\")], \
  1463. [begin \
  1464. io:format(\"Loading application ~p~n\", [App]), \
  1465. case application:load(App) of \
  1466. {error, _} -> ok; \
  1467. ok -> \
  1468. {ok, Mods} = application:get_key(App, modules), \
  1469. [try io:format(\" Loading module ~p~n\", [Mod]), \
  1470. {module, Mod} = code:load_file(Mod) \
  1471. catch C:R -> timer:sleep(500), erlang:C(R) \
  1472. end || Mod <- Mods] \
  1473. end \
  1474. end || App <- Apps], \
  1475. halt()."; if [ $$$$? -ne 0 ]; then \
  1476. echo "$(1): load error" >> pkgs.log; \
  1477. fi \
  1478. fi \
  1479. fi \
  1480. fi
  1481. endef
  1482. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  1483. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_test_target,$(pkg))))
  1484. pkgs: $(addprefix pkg-,$(PACKAGES))
  1485. @if [ -f pkgs.log ]; then \
  1486. echo "+-------------------------------+"; \
  1487. echo "| ERRORS WHILE TESTING PACKAGES |"; \
  1488. echo "+-------------------------------+"; \
  1489. cat pkgs.log; \
  1490. exit 33; \
  1491. fi
  1492. # Test application used for testing.
  1493. app1:
  1494. $(call app1_setup)
  1495. # Extra module in app1 used for testing eunit
  1496. define create-module-t
  1497. printf '%s\n' \
  1498. '-module(t).' \
  1499. '-export([succ/1]).' \
  1500. 'succ(N) -> N + 1.' \
  1501. '-ifdef(TEST).' \
  1502. '-include_lib("eunit/include/eunit.hrl").' \
  1503. 'succ_test() ->' \
  1504. ' ?assertEqual(2, succ(1)),' \
  1505. ' os:cmd("echo t >> test-eunit.log").' \
  1506. '-endif.' \
  1507. > app1/src/t.erl
  1508. endef