Makefile 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971
  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 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/EX1-MIB.bin
  369. $t test ! -e $(APP)/priv/mibs/OTP-REG.bin
  370. $i "Build the application again"
  371. $t $(MAKE) -C $(APP) $v
  372. $i "Check that all compiled files exist"
  373. $t test -f $(APP)/$(APP).d
  374. $t test -f $(APP)/ebin/$(APP).app
  375. $t test -f $(APP)/ebin/use_v1.beam
  376. $t test -f $(APP)/ebin/use_v2.beam
  377. $t test -f $(APP)/include/EX1-MIB.hrl
  378. $t test -f $(APP)/include/OTP-REG.hrl
  379. $t test -f $(APP)/priv/mibs/EX1-MIB.bin
  380. $t test -f $(APP)/priv/mibs/OTP-REG.bin
  381. $i "Check that the application was compiled correctly"
  382. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  383. ok = application:start($(APP)), \
  384. {ok, Mods = [use_v1, use_v2]} \
  385. = application:get_key($(APP), modules), \
  386. [{module, M} = code:load_file(M) || M <- Mods], \
  387. halt()"
  388. clean-core-app: $(CORE_APP_CLEAN_TARGETS)
  389. $(CORE_APP_CLEAN_TARGETS):
  390. $t rm -rf $(APP_TO_CLEAN)/
  391. # Core: Erlang.mk upgrade.
  392. CORE_UPGRADE_CASES = no-config custom-config renamed-config custom-build-dir
  393. CORE_UPGRADE_TARGETS = $(addprefix core-upgrade-,$(CORE_UPGRADE_CASES))
  394. CORE_UPGRADE_CLEAN_TARGETS = $(addprefix clean-,$(CORE_UPGRADE_TARGETS))
  395. .PHONY: core-upgrade $(CORE_UPGRADE_TARGETS) $(CORE_UPGRADE_CLEAN_TARGETS)
  396. core-upgrade: $(CORE_UPGRADE_TARGETS)
  397. core-upgrade-no-config: build clean-core-upgrade-no-config
  398. $i "Bootstrap a new OTP library named $(APP)"
  399. $t mkdir $(APP)/
  400. $t cp ../erlang.mk $(APP)/
  401. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  402. $i "Append a rule to the Erlang.mk file for testing purposes"
  403. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  404. $i "Check that the test rule works as intended"
  405. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  406. $i "Upgrade Erlang.mk"
  407. $t $(MAKE) -C $(APP) erlang-mk $v
  408. $i "Check that the rule is gone"
  409. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  410. core-upgrade-custom-config: build clean-core-upgrade-custom-config
  411. $i "Bootstrap a new OTP library named $(APP)"
  412. $t mkdir $(APP)/
  413. $t cp ../erlang.mk $(APP)/
  414. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  415. $i "Create a custom build.config file without plugins"
  416. $t echo "core/*" > $(APP)/build.config
  417. $i "Upgrade Erlang.mk"
  418. $t $(MAKE) -C $(APP) erlang-mk $v
  419. $i "Check that the bootstrap plugin is gone"
  420. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  421. core-upgrade-renamed-config: build clean-core-upgrade-renamed-config
  422. $i "Bootstrap a new OTP library named $(APP)"
  423. $t mkdir $(APP)/
  424. $t cp ../erlang.mk $(APP)/
  425. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  426. $i "Create a custom build.config file without plugins; name it my.build.config"
  427. $t echo "core/*" > $(APP)/my.build.config
  428. $i "Set ERLANG_MK_BUILD_CONFIG=my.build.config in the Makefile"
  429. $t echo "ERLANG_MK_BUILD_CONFIG = my.build.config" >> $(APP)/Makefile
  430. $i "Upgrade Erlang.mk"
  431. $t $(MAKE) -C $(APP) erlang-mk $v
  432. $i "Check that the bootstrap plugin is gone"
  433. $t if $(MAKE) -C $(APP) list-templates $v; then false; fi
  434. core-upgrade-custom-build-dir: build clean-core-upgrade-custom-build-dir
  435. $i "Bootstrap a new OTP library named $(APP)"
  436. $t mkdir $(APP)/
  437. $t cp ../erlang.mk $(APP)/
  438. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  439. $i "Append a rule to the Erlang.mk file for testing purposes"
  440. $t echo "erlang_mk_upgrade_test_rule: ; @echo FAIL" >> $(APP)/erlang.mk
  441. $i "Check that the test rule works as intended"
  442. $t test "FAIL" = "`$(MAKE) -C $(APP) --no-print-directory erlang_mk_upgrade_test_rule V=0`"
  443. $i "Create the custom build directory"
  444. $t mkdir $(APP)/custom/
  445. $t test -d $(APP)/custom/
  446. $i "Upgrade Erlang.mk with a custom build directory"
  447. $t ERLANG_MK_BUILD_DIR=custom $(MAKE) -C $(APP) erlang-mk $v
  448. $i "Check that the rule is gone"
  449. $t if $(MAKE) -C $(APP) erlang_mk_upgrade_test_rule $v; then false; fi
  450. $i "Check that the custom build directory is gone"
  451. $t test ! -d $(APP)/custom/
  452. clean-core-upgrade: $(CORE_UPGRADE_CLEAN_TARGETS)
  453. $(CORE_UPGRADE_CLEAN_TARGETS):
  454. $t rm -rf $(APP_TO_CLEAN)/
  455. # Bootstrap plugin.
  456. BOOTSTRAP_CASES = app lib rel templates
  457. BOOTSTRAP_TARGETS = $(addprefix bootstrap-,$(BOOTSTRAP_CASES))
  458. BOOTSTRAP_CLEAN_TARGETS = $(addprefix clean-,$(BOOTSTRAP_TARGETS))
  459. .PHONY: bootstrap $(BOOTSTRAP_TARGETS) $(BOOTSTRAP_CLEAN_TARGETS)
  460. bootstrap: $(BOOTSTRAP_TARGETS)
  461. bootstrap-app: build clean-bootstrap-app
  462. $i "Bootstrap a new OTP application named $(APP)"
  463. $t mkdir $(APP)/
  464. $t cp ../erlang.mk $(APP)/
  465. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  466. $i "Check that all bootstrapped files exist"
  467. $t test -f $(APP)/Makefile
  468. $t test -f $(APP)/src/$(APP).app.src
  469. $t test -f $(APP)/src/$(APP)_app.erl
  470. $t test -f $(APP)/src/$(APP)_sup.erl
  471. $i "Build the application"
  472. $t $(MAKE) -C $(APP) $v
  473. $i "Check that all compiled files exist"
  474. $t test -f $(APP)/ebin/$(APP).app
  475. $t test -f $(APP)/ebin/$(APP)_app.beam
  476. $t test -f $(APP)/ebin/$(APP)_sup.beam
  477. $i "Check that the application was compiled correctly"
  478. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  479. ok = application:start($(APP)), \
  480. {ok, [$(APP)_app, $(APP)_sup]} = application:get_key($(APP), modules), \
  481. {module, $(APP)_app} = code:load_file($(APP)_app), \
  482. {module, $(APP)_sup} = code:load_file($(APP)_sup), \
  483. halt()"
  484. bootstrap-lib: build clean-bootstrap-lib
  485. $i "Bootstrap a new OTP library named $(APP)"
  486. $t mkdir $(APP)/
  487. $t cp ../erlang.mk $(APP)/
  488. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  489. $i "Check that all bootstrapped files exist"
  490. $t test -f $(APP)/Makefile
  491. $t test -f $(APP)/src/$(APP).app.src
  492. $i "Build the application"
  493. $t $(MAKE) -C $(APP) $v
  494. $i "Check that all compiled files exist"
  495. $t test -f $(APP)/ebin/$(APP).app
  496. $i "Check that the application was compiled correctly"
  497. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  498. ok = application:start($(APP)), \
  499. {ok, []} = application:get_key($(APP), modules), \
  500. halt()"
  501. bootstrap-rel: build clean-bootstrap-rel
  502. $i "Bootstrap a new release-enabled OTP application named $(APP)"
  503. $t mkdir $(APP)/
  504. $t cp ../erlang.mk $(APP)/
  505. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap bootstrap-rel $v
  506. $i "Check that all bootstrapped files exist"
  507. $t test -f $(APP)/Makefile
  508. $t test -f $(APP)/relx.config
  509. $t test -f $(APP)/rel/sys.config
  510. $t test -f $(APP)/rel/vm.args
  511. $t test -f $(APP)/src/$(APP).app.src
  512. $t test -f $(APP)/src/$(APP)_app.erl
  513. $t test -f $(APP)/src/$(APP)_sup.erl
  514. $i "Build the application and the release"
  515. $t $(MAKE) -C $(APP) $v
  516. $i "Check that all compiled files exist"
  517. $t test -f $(APP)/ebin/$(APP).app
  518. $t test -f $(APP)/ebin/$(APP)_app.beam
  519. $t test -f $(APP)/ebin/$(APP)_sup.beam
  520. $i "Check that the release was generated"
  521. $t test -f $(APP)/_rel/$(APP)_release/bin/$(APP)_release
  522. $i "Check that the release can be started and stopped"
  523. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release start $v
  524. $t $(APP)/_rel/$(APP)_release/bin/$(APP)_release stop $v
  525. $i "Check that there's no erl_crash.dump file"
  526. $t test ! -f $(APP)/_rel/$(APP)_release/erl_crash.dump
  527. bootstrap-templates: build clean-bootstrap-templates
  528. $i "Bootstrap a new OTP library named $(APP)"
  529. $t mkdir $(APP)/
  530. $t cp ../erlang.mk $(APP)/
  531. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  532. $i "Check that we can get the list of templates"
  533. $t test `$(MAKE) -C $(APP) --no-print-directory list-templates V=0 | wc -l` -eq 1
  534. $i "Generate one of each template"
  535. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_fsm n=my_fsm
  536. $t $(MAKE) -C $(APP) --no-print-directory new t=gen_server n=my_server
  537. $t $(MAKE) -C $(APP) --no-print-directory new t=supervisor n=my_sup
  538. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_http n=my_http
  539. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_loop n=my_loop
  540. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_rest n=my_rest
  541. $t $(MAKE) -C $(APP) --no-print-directory new t=cowboy_ws n=my_ws
  542. $t $(MAKE) -C $(APP) --no-print-directory new t=ranch_protocol n=my_protocol
  543. # Here we disable warnings because templates contain missing behaviors.
  544. $i "Build the application"
  545. $t $(MAKE) -C $(APP) ERLC_OPTS=+debug_info $v
  546. $i "Check that all compiled files exist"
  547. $t test -f $(APP)/ebin/$(APP).app
  548. $t test -f $(APP)/ebin/my_fsm.beam
  549. $t test -f $(APP)/ebin/my_server.beam
  550. $t test -f $(APP)/ebin/my_sup.beam
  551. $i "Check that all the modules can be loaded"
  552. $t $(ERL) -pa $(APP)/ebin/ -eval " \
  553. ok = application:start($(APP)), \
  554. {ok, Mods = [my_fsm, my_http, my_loop, my_protocol, my_rest, my_server, my_sup, my_ws]} \
  555. = application:get_key($(APP), modules), \
  556. [{module, M} = code:load_file(M) || M <- Mods], \
  557. halt()"
  558. clean-bootstrap: $(BOOTSTRAP_CLEAN_TARGETS)
  559. $(BOOTSTRAP_CLEAN_TARGETS):
  560. $t rm -rf $(APP_TO_CLEAN)/
  561. ########################################
  562. # Legacy tests.
  563. app: app1
  564. $i "app: Testing the 'app' target."
  565. $t $(MAKE) -C app1 app $v
  566. $i "Checking the modules line in the generated .app file."
  567. $t [ `grep -E "{modules, *\['m'\]}" app1/ebin/app1.app | wc -l` -eq 1 ]
  568. $t [ -e app1/ebin/m.beam ]
  569. $i "Checking that '$(MAKE) clean-app' deletes ebin."
  570. $t $(MAKE) -C app1 clean-app $v
  571. $t [ ! -e app1/ebin ]
  572. $i "Checking that '$(MAKE) app' returns non-zero on compile errors."
  573. $t printf "%s\n" \
  574. "-module(syntax_error)." \
  575. "foo lorem_ipsum dolor sit amet." \
  576. > app1/src/syntax_error.erl
  577. $t if $(MAKE) -C app1 app $v ; then false ; fi
  578. $t rm app1/src/syntax_error.erl
  579. $i "Test 'app' passed."
  580. ct: app1
  581. $i "ct: Testing ct and related targets."
  582. $i "Setting up test suite."
  583. $t mkdir -p app1/test
  584. $t printf "%s\n" \
  585. "-module(m_SUITE)." \
  586. "-export([all/0, testcase1/1])." \
  587. "all() -> [testcase1]." \
  588. "testcase1(_) -> 2 = m:succ(1)." \
  589. > app1/test/m_SUITE.erl
  590. $t $(MAKE) -C app1 ct $v
  591. $i "Checking files created by '$(MAKE) ct'."
  592. $t [ -e app1/test/m_SUITE.beam ]
  593. $t [ -e app1/ebin/m.beam ]
  594. $t [ -e app1/logs ]
  595. $i "Checking that '$(MAKE) clean' does not delete logs."
  596. $t $(MAKE) -C app1 clean $v
  597. $t [ -e app1/logs ]
  598. $i "Testing target 'ct-mysuite' where mysuite_SUITE is a test suite."
  599. $t $(MAKE) -C app1 ct-m $v
  600. $i "Checking that '$(MAKE) ct' returns non-zero for a failing suite."
  601. $t printf "%s\n" \
  602. "-module(failing_SUITE)." \
  603. "-export([all/0, testcase1/1])." \
  604. "all() -> [testcase1]." \
  605. "testcase1(_) -> 42 = m:succ(1)." \
  606. > app1/test/failing_SUITE.erl
  607. $t if $(MAKE) -C app1 ct-failing $v ; then false ; fi
  608. $i "Checking that '$(MAKE) distclean-ct' deletes logs."
  609. $t $(MAKE) -C app1 distclean-ct $v
  610. $t [ ! -e app1/logs ]
  611. $t [ -e app1/ebin/m.beam ]
  612. $i "Cleaning up test data."
  613. $t rm -rf app1/test
  614. $i "Test 'ct' passed."
  615. eunit: app1
  616. $i "eunit: Testing the 'eunit' target."
  617. $i "Running eunit test case inside module src/t.erl"
  618. $t $(call create-module-t)
  619. $t $(MAKE) -C app1 distclean $v
  620. $t $(MAKE) -C app1 eunit $v
  621. $i "Checking that the eunit test in module t."
  622. $t echo t | cmp app1/test-eunit.log -
  623. $t rm app1/test-eunit.log
  624. $i "Running eunit tests in a separate directory."
  625. $t mkdir -p app1/eunit
  626. $t printf '%s\n' \
  627. '-module(t_tests).' \
  628. '-include_lib("eunit/include/eunit.hrl").' \
  629. 'succ_test() ->' \
  630. ' ?assertEqual(2, t:succ(1)),' \
  631. ' os:cmd("echo t_tests >> test-eunit.log").' \
  632. > app1/eunit/t_tests.erl
  633. $t printf '%s\n' \
  634. '-module(x_tests).' \
  635. '-include_lib("eunit/include/eunit.hrl").' \
  636. 'succ_test() ->' \
  637. ' ?assertEqual(2, t:succ(1)),' \
  638. ' os:cmd("echo x_tests >> test-eunit.log").' \
  639. > app1/eunit/x_tests.erl
  640. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  641. $t $(MAKE) -C app1 eunit TEST_DIR=eunit $v
  642. $i "Checking that '$(MAKE) eunit' didn't run the tests in t_tests twice, etc."
  643. $t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
  644. $t rm app1/test-eunit.log
  645. $i "Checking that '$(MAKE) eunit' returns non-zero for a failing test."
  646. $t rm -f app1/eunit/*
  647. $t printf "%s\n" \
  648. "-module(t_tests)." \
  649. '-include_lib("eunit/include/eunit.hrl").' \
  650. "succ_test() ->" \
  651. " ?assertEqual(42, t:succ(1))." \
  652. > app1/eunit/t_tests.erl
  653. $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
  654. $t if $(MAKE) -C app1 eunit TEST_DIR=eunit $v ; then false ; fi
  655. $t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
  656. $i "Test 'eunit' passed."
  657. # TODO: do coverage for 'tests' instead of 'eunit ct' when triq is fixed
  658. tests-cover: app1
  659. $i "tests-cover: Testing 'eunit' and 'ct' with COVER=1"
  660. $i "Setting up eunit and ct suites."
  661. $t $(call create-module-t)
  662. $t mkdir -p app1/test
  663. $t printf "%s\n" \
  664. "-module(m_SUITE)." \
  665. "-export([all/0, testcase1/1])." \
  666. "all() -> [testcase1]." \
  667. "testcase1(_) -> 2 = m:succ(1)." \
  668. > app1/test/m_SUITE.erl
  669. $i "Running tests with coverage analysis."
  670. $t $(MAKE) -C app1 eunit ct COVER=1 $v
  671. $t [ -e app1/test-eunit.log ]
  672. $t [ -e app1/eunit.coverdata ]
  673. $t [ -e app1/ct.coverdata ]
  674. $i "Generating coverage report."
  675. $t $(MAKE) -C app1 cover-report COVER=1 $v
  676. $t [ -e app1/cover/m.COVER.html ]
  677. $t [ -e app1/cover/t.COVER.html ]
  678. $t [ -e app1/cover/index.html ]
  679. $i "Checking combined coverage from eunit and ct."
  680. $t [ `grep 'Total: 100%' app1/cover/index.html | wc -l` -eq 1 ]
  681. $i "Checking that cover-report-clean removes cover report."
  682. $t $(MAKE) -C app1 cover-report-clean $v
  683. $t [ ! -e app1/cover ]
  684. $i "Checking that coverdata-clean removes cover data."
  685. $t $(MAKE) -C app1 coverdata-clean $v
  686. $t [ ! -e app1/eunit.coverdata ]
  687. @# clean up
  688. $t rm -rf app1/src/t.erl app1/test app1/test-eunit.log
  689. $t $(MAKE) -C app1 clean $v
  690. $i "Test 'tests-cover' passed."
  691. docs: app1
  692. $i "docs: Testing EDoc including DOC_DEPS."
  693. $t printf "%s\n" \
  694. "PROJECT = app1" \
  695. "DOC_DEPS = edown" \
  696. "dep_edown = git https://github.com/uwiger/edown.git 0.7" \
  697. "EDOC_OPTS = {doclet, edown_doclet}" \
  698. "include erlang.mk" \
  699. "distclean:: distclean-doc-md" \
  700. "distclean-doc-md:" \
  701. " rm -rf doc/*.md" \
  702. > app1/Makefile-doc
  703. $i "Downloading doc deps (edown) and building docs."
  704. $t $(MAKE) -C app1 -f Makefile-doc docs $v
  705. $i "Checking that '$(MAKE) docs' using edown generated a markdown file."
  706. $t [ -e app1/doc/m.md ]
  707. $i "Checking that '$(MAKE) distclean' deletes all generated doc files."
  708. $t $(MAKE) -C app1 -f Makefile-doc distclean $v
  709. $t [ "`ls app1/doc/`" = "" ]
  710. $i "Cleaning up test data."
  711. $t rm app1/Makefile-doc
  712. $i "Test 'docs' passed."
  713. define app1_setup
  714. $i "Setting up app."
  715. $t mkdir -p app1
  716. $t cd .. && $(MAKE)
  717. $t cp ../erlang.mk app1/
  718. $t $(MAKE) -C app1 -f erlang.mk bootstrap-lib
  719. $t printf "%s\n" \
  720. "-module(m)." \
  721. "-export([succ/1])." \
  722. "succ(N) -> N + 1." \
  723. > app1/src/m.erl
  724. endef
  725. define pkg_test_target
  726. pkg-$(1)-clean:
  727. $t rm -rf app1 erl_crash.dump
  728. pkg-$(1)-app1:
  729. $(call app1_setup)
  730. # Running 'make' twice to make sure it recompiles fine.
  731. pkg-$(1): pkg-$(1)-clean pkg-$(1)-app1
  732. $i
  733. $i " pkgs: Checking that '$(1)' builds correctly"
  734. $i
  735. $t printf "%s\n" \
  736. "PROJECT = app1" \
  737. "DEPS = $(1)" \
  738. "include erlang.mk" \
  739. > app1/Makefile
  740. $t \
  741. if [ "$(1)" = "amqp_client" ]; then \
  742. $(MAKE) -C app1 RABBITMQ_CLIENT_PATCH=1; \
  743. elif [ "$(1)" = "rabbit" ]; then \
  744. $(MAKE) -C app1 RABBITMQ_SERVER_PATCH=1; \
  745. else \
  746. $(MAKE) -C app1; \
  747. fi; \
  748. if [ $$$$? -ne 0 ]; then \
  749. echo "$(1): make error" >> pkgs.log; \
  750. else \
  751. $(MAKE) -C app1; if [ $$$$? -ne 0 ]; then \
  752. echo "$(1): re-make error" >> pkgs.log; \
  753. else \
  754. find . -type f -name erl_crash.dump; if [ $$$$? -ne 0 ]; then \
  755. echo "$(1): erl_crash.dump found" >> pkgs.log; \
  756. else \
  757. erl +A0 -noinput -boot start_clean -pa app1/deps/*/ebin -eval " \
  758. Apps = [list_to_atom(App) || \"app1/deps/\" ++ App \
  759. <- filelib:wildcard(\"app1/deps/*\")], \
  760. [begin \
  761. io:format(\"Loading application ~p~n\", [App]), \
  762. case application:load(App) of \
  763. {error, _} -> ok; \
  764. ok -> \
  765. {ok, Mods} = application:get_key(App, modules), \
  766. [try io:format(\" Loading module ~p~n\", [Mod]), \
  767. {module, Mod} = code:load_file(Mod) \
  768. catch C:R -> timer:sleep(500), erlang:C(R) \
  769. end || Mod <- Mods] \
  770. end \
  771. end || App <- Apps], \
  772. halt()."; if [ $$$$? -ne 0 ]; then \
  773. echo "$(1): load error" >> pkgs.log; \
  774. fi \
  775. fi \
  776. fi \
  777. fi
  778. endef
  779. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
  780. $(foreach pkg,$(PACKAGES),$(eval $(call pkg_test_target,$(pkg))))
  781. pkgs: $(addprefix pkg-,$(PACKAGES))
  782. @if [ -f pkgs.log ]; then \
  783. echo "+-------------------------------+"; \
  784. echo "| ERRORS WHILE TESTING PACKAGES |"; \
  785. echo "+-------------------------------+"; \
  786. cat pkgs.log; \
  787. exit 33; \
  788. fi
  789. # Test application used for testing.
  790. app1:
  791. $(call app1_setup)
  792. # Extra module in app1 used for testing eunit
  793. define create-module-t
  794. printf '%s\n' \
  795. '-module(t).' \
  796. '-export([succ/1]).' \
  797. 'succ(N) -> N + 1.' \
  798. '-ifdef(TEST).' \
  799. '-include_lib("eunit/include/eunit.hrl").' \
  800. 'succ_test() ->' \
  801. ' ?assertEqual(2, succ(1)),' \
  802. ' os:cmd("echo t >> test-eunit.log").' \
  803. '-endif.' \
  804. > app1/src/t.erl
  805. endef