Makefile 38 KB

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