plugin_cover.mk 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489
  1. # Common Test plugin.
  2. COVER_TARGETS = $(call list_targets,cover)
  3. .PHONY: cover $(COVER_TARGETS)
  4. cover: $(COVER_TARGETS)
  5. cover-ct: init
  6. $i "Bootstrap a new OTP application named $(APP)"
  7. $t mkdir $(APP)/
  8. $t cp ../erlang.mk $(APP)/
  9. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  10. $i "Generate a Common Test suite"
  11. $t mkdir $(APP)/test
  12. $t printf "%s\n" \
  13. "-module($(APP)_SUITE)." \
  14. "-export([all/0, ok/1])." \
  15. "all() -> [ok]." \
  16. "ok(_) -> application:start($(APP))." > $(APP)/test/$(APP)_SUITE.erl
  17. $i "Run Common Test with code coverage enabled"
  18. $t $(MAKE) -C $(APP) ct COVER=1 $v
  19. $i "Check that the generated files exist"
  20. $t test -f $(APP)/cover/ct.coverdata
  21. $t test -f $(APP)/test/ct.cover.spec
  22. $i "Check that the generated files are removed on clean"
  23. $t $(MAKE) -C $(APP) clean $v
  24. $t test ! -e $(APP)/cover/ct.coverdata
  25. $t test ! -e $(APP)/test/ct.cover.spec
  26. cover-ct-incl-apps: init
  27. $i "Bootstrap a new OTP application named $(APP)"
  28. $t mkdir $(APP)/
  29. $t cp ../erlang.mk $(APP)/
  30. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  31. $i "Create a new application app_one"
  32. $t $(MAKE) -C $(APP) new-app in=app_one $v
  33. $i "Create a new application app_two"
  34. $t $(MAKE) -C $(APP) new-app in=app_two $v
  35. $i "Create a new application app_three"
  36. $t $(MAKE) -C $(APP) new-app in=app_three $v
  37. $i "Add all three apps to LOCAL_DEPS"
  38. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile
  39. ifdef LEGACY
  40. $i "Add all three apps to the applications key in the .app.src file"
  41. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src
  42. endif
  43. $i "Add app_one and app_three to the code coverage"
  44. $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_APPS = app_one app_three\n"}' $(APP)/Makefile
  45. $i "Generate a Common Test suite"
  46. $t mkdir $(APP)/test
  47. $t printf "%s\n" \
  48. "-module($(APP)_SUITE)." \
  49. "-export([all/0, ok/1])." \
  50. "all() -> [ok]." \
  51. "ok(_) -> application:ensure_all_started($(APP))." > $(APP)/test/$(APP)_SUITE.erl
  52. $i "Run Common Test with code coverage enabled"
  53. $t $(MAKE) -C $(APP) ct COVER=1 $v
  54. $i "Check that app_one and app_three were covered, but app_two wasn't"
  55. $t test -f $(APP)/logs/ct_run.*/app_one_app.COVER.html
  56. $t test -f $(APP)/logs/ct_run.*/app_three_app.COVER.html
  57. $t ! test -e $(APP)/logs/ct_run.*/app_two_app.COVER.html
  58. cover-ct-incl-apps-default: init
  59. $i "Bootstrap a new OTP application named $(APP)"
  60. $t mkdir $(APP)/
  61. $t cp ../erlang.mk $(APP)/
  62. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  63. $i "Create a new application app_one"
  64. $t $(MAKE) -C $(APP) new-app in=app_one $v
  65. $i "Create a new application app_two"
  66. $t $(MAKE) -C $(APP) new-app in=app_two $v
  67. $i "Create a new application app_three"
  68. $t $(MAKE) -C $(APP) new-app in=app_three $v
  69. $i "Add all three apps to LOCAL_DEPS"
  70. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile
  71. ifdef LEGACY
  72. $i "Add all three apps to the applications key in the .app.src file"
  73. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src
  74. endif
  75. $i "Generate a Common Test suite"
  76. $t mkdir $(APP)/test
  77. $t printf "%s\n" \
  78. "-module($(APP)_SUITE)." \
  79. "-export([all/0, ok/1])." \
  80. "all() -> [ok]." \
  81. "ok(_) -> application:ensure_all_started($(APP))." > $(APP)/test/$(APP)_SUITE.erl
  82. $i "Run Common Test with code coverage enabled"
  83. $t $(MAKE) -C $(APP) ct COVER=1 $v
  84. $i "Check that all apps were covered by default"
  85. $t test -f $(APP)/logs/ct_run.*/app_one_app.COVER.html
  86. $t test -f $(APP)/logs/ct_run.*/app_two_app.COVER.html
  87. $t test -f $(APP)/logs/ct_run.*/app_three_app.COVER.html
  88. cover-ct-incl-deps: init
  89. $i "Bootstrap a new OTP application named $(APP)"
  90. $t mkdir $(APP)/
  91. $t cp ../erlang.mk $(APP)/
  92. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  93. $i "Add Cowboy 1.0.0 to the list of dependencies"
  94. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy_commit = 1.0.0\n"}' $(APP)/Makefile
  95. ifdef LEGACY
  96. $i "Add Cowboy to the applications key in the .app.src file"
  97. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowboy,\n"}' $(APP)/src/$(APP).app.src
  98. endif
  99. $i "Add Cowboy and Cowlib to the code coverage"
  100. $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DEPS = cowboy cowlib\n"}' $(APP)/Makefile
  101. $i "Generate a Common Test suite"
  102. $t mkdir $(APP)/test
  103. $t printf "%s\n" \
  104. "-module($(APP)_SUITE)." \
  105. "-export([all/0, ok/1])." \
  106. "all() -> [ok]." \
  107. "ok(_) -> application:ensure_all_started($(APP))." > $(APP)/test/$(APP)_SUITE.erl
  108. $i "Run Common Test with code coverage enabled"
  109. $t $(MAKE) -C $(APP) ct COVER=1 $v
  110. $i "Check that Cowboy and Cowlib were covered, but Ranch wasn't"
  111. $t test -f $(APP)/logs/ct_run.*/cowboy_app.COVER.html
  112. $t test -f $(APP)/logs/ct_run.*/cow_http_hd.COVER.html
  113. $t ! test -e $(APP)/logs/ct_run.*/ranch_app.COVER.html
  114. cover-custom-dir: init
  115. $i "Bootstrap a new OTP application named $(APP)"
  116. $t mkdir $(APP)/
  117. $t cp ../erlang.mk $(APP)/
  118. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  119. $i "Set COVER_DATA_DIR in the Makefile"
  120. $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DATA_DIR = custom_dir\n"}' $(APP)/Makefile
  121. $i "Generate a module containing EUnit tests"
  122. $t printf "%s\n" \
  123. "-module($(APP))." \
  124. "-ifdef(TEST)." \
  125. "-include_lib(\"eunit/include/eunit.hrl\")." \
  126. "ok_test() -> ok." \
  127. "-endif." > $(APP)/src/$(APP).erl
  128. $i "Generate a Common Test suite"
  129. $t mkdir $(APP)/test
  130. $t printf "%s\n" \
  131. "-module($(APP)_SUITE)." \
  132. "-export([all/0, ok/1])." \
  133. "all() -> [ok]." \
  134. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  135. $i "Run Common Test with code coverage enabled"
  136. $t $(MAKE) -C $(APP) ct COVER=1 $v
  137. $i "Run EUnit with code coverage enabled"
  138. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  139. $i "Check that the generated file exists"
  140. $t test -f $(APP)/custom_dir/ct.coverdata
  141. $t test -f $(APP)/custom_dir/eunit.coverdata
  142. $i "Merge coverdata files into all.coverdata"
  143. $t $(MAKE) -C $(APP) all.coverdata $v
  144. $t test -f $(APP)/custom_dir/all.coverdata
  145. $i "Check that the generated file is removed on clean"
  146. $t $(MAKE) -C $(APP) clean $v
  147. $t test ! -e $(APP)/custom_dir/eunit.coverdata
  148. $t test ! -e $(APP)/custom_dir/ct.coverdata
  149. $t test ! -e $(APP)/custom_dir/all.coverdata
  150. $i "Check that the custom dir is removed on distclean"
  151. $t $(MAKE) -C $(APP) distclean $v
  152. $t test ! -e $(APP)/custom_dir/
  153. $i "Check that the custom dir is not removed if not empty"
  154. $t mkdir $(APP)/custom_dir
  155. $t touch $(APP)/custom_dir/file
  156. $t $(MAKE) -C $(APP) distclean $v
  157. $t test -f $(APP)/custom_dir/file
  158. cover-eunit: init
  159. $i "Bootstrap a new OTP application named $(APP)"
  160. $t mkdir $(APP)/
  161. $t cp ../erlang.mk $(APP)/
  162. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  163. $i "Generate a module containing EUnit tests"
  164. $t printf "%s\n" \
  165. "-module($(APP))." \
  166. "-ifdef(TEST)." \
  167. "-include_lib(\"eunit/include/eunit.hrl\")." \
  168. "ok_test() -> ok." \
  169. "-endif." > $(APP)/src/$(APP).erl
  170. $i "Run EUnit with code coverage enabled"
  171. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  172. $i "Check that the generated file exists"
  173. $t test -f $(APP)/cover/eunit.coverdata
  174. $i "Check that the generated file is removed on clean"
  175. $t $(MAKE) -C $(APP) clean $v
  176. $t test ! -e $(APP)/cover/eunit.coverdata
  177. cover-eunit-apps-only: init
  178. $i "Create a multi application repository with no root application"
  179. $t mkdir $(APP)/
  180. $t cp ../erlang.mk $(APP)/
  181. $t echo "include erlang.mk" > $(APP)/Makefile
  182. $i "Create a new application named my_app"
  183. $t $(MAKE) -C $(APP) new-app in=my_app $v
  184. $i "Generate a module containing EUnit tests in my_app"
  185. $t printf "%s\n" \
  186. "-module(my_app)." \
  187. "-ifdef(TEST)." \
  188. "-include_lib(\"eunit/include/eunit.hrl\")." \
  189. "ok_test() -> ok." \
  190. "-endif." > $(APP)/apps/my_app/src/my_app.erl
  191. $i "Run EUnit with code coverage enabled"
  192. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  193. $i "Check that no file was generated in the top-level directory"
  194. $t ! test -f $(APP)/cover/eunit.coverdata
  195. $i "Check that the generated file exists"
  196. $t test -f $(APP)/apps/my_app/cover/eunit.coverdata
  197. cover-eunit-incl-apps: init
  198. $i "Bootstrap a new OTP application named $(APP)"
  199. $t mkdir $(APP)/
  200. $t cp ../erlang.mk $(APP)/
  201. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  202. $i "Create a new application app_one"
  203. $t $(MAKE) -C $(APP) new-app in=app_one $v
  204. $i "Create a new application app_two"
  205. $t $(MAKE) -C $(APP) new-app in=app_two $v
  206. $i "Create a new application app_three"
  207. $t $(MAKE) -C $(APP) new-app in=app_three $v
  208. $i "Add all three apps to LOCAL_DEPS"
  209. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile
  210. ifdef LEGACY
  211. $i "Add all three apps to the applications key in the .app.src file"
  212. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src
  213. endif
  214. $i "Add app_one and app_three to the code coverage"
  215. $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_APPS = app_one app_three\n"}' $(APP)/Makefile
  216. $i "Generate a module containing EUnit tests"
  217. $t printf "%s\n" \
  218. "-module($(APP))." \
  219. "-ifdef(TEST)." \
  220. "-include_lib(\"eunit/include/eunit.hrl\")." \
  221. "ok_test() -> application:ensure_all_started($(APP))." \
  222. "-endif." > $(APP)/src/$(APP).erl
  223. $i "Run EUnit with code coverage enabled"
  224. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  225. $i "Build the cover report"
  226. $t $(MAKE) -C $(APP) cover-report $v
  227. $i "Check that app_one and app_three were covered, but app_two wasn't"
  228. $t test -f $(APP)/cover/app_one_app.COVER.html
  229. $t test -f $(APP)/cover/app_three_app.COVER.html
  230. $t ! test -e $(APP)/cover/app_two_app.COVER.html
  231. cover-eunit-incl-apps-default: init
  232. $i "Bootstrap a new OTP application named $(APP)"
  233. $t mkdir $(APP)/
  234. $t cp ../erlang.mk $(APP)/
  235. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  236. $i "Create a new application app_one"
  237. $t $(MAKE) -C $(APP) new-app in=app_one $v
  238. $i "Create a new application app_two"
  239. $t $(MAKE) -C $(APP) new-app in=app_two $v
  240. $i "Create a new application app_three"
  241. $t $(MAKE) -C $(APP) new-app in=app_three $v
  242. $i "Add all three apps to LOCAL_DEPS"
  243. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = app_one app_two app_three\n"}' $(APP)/Makefile
  244. ifdef LEGACY
  245. $i "Add all three apps to the applications key in the .app.src file"
  246. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tapp_one,\n\t\tapp_two,\n\t\tapp_three,\n"}' $(APP)/src/$(APP).app.src
  247. endif
  248. $i "Generate a module containing EUnit tests"
  249. $t printf "%s\n" \
  250. "-module($(APP))." \
  251. "-ifdef(TEST)." \
  252. "-include_lib(\"eunit/include/eunit.hrl\")." \
  253. "ok_test() -> application:ensure_all_started($(APP))." \
  254. "-endif." > $(APP)/src/$(APP).erl
  255. $i "Run EUnit with code coverage enabled"
  256. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  257. $i "Build the cover report"
  258. $t $(MAKE) -C $(APP) cover-report $v
  259. $i "Check that all apps were covered by default"
  260. $t test -f $(APP)/cover/app_one_app.COVER.html
  261. $t test -f $(APP)/cover/app_two_app.COVER.html
  262. $t test -f $(APP)/cover/app_three_app.COVER.html
  263. cover-eunit-incl-deps: init
  264. $i "Bootstrap a new OTP application named $(APP)"
  265. $t mkdir $(APP)/
  266. $t cp ../erlang.mk $(APP)/
  267. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  268. $i "Add Cowboy 1.0.0 to the list of dependencies"
  269. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowboy\ndep_cowboy_commit = 1.0.0\n"}' $(APP)/Makefile
  270. ifdef LEGACY
  271. $i "Add Cowboy to the applications key in the .app.src file"
  272. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tcowboy,\n"}' $(APP)/src/$(APP).app.src
  273. endif
  274. $i "Add Cowboy and Cowlib to the code coverage"
  275. $t perl -ni.bak -e 'print;if ($$.==1) {print "COVER_DEPS = cowboy cowlib\n"}' $(APP)/Makefile
  276. $i "Generate a module containing EUnit tests"
  277. $t printf "%s\n" \
  278. "-module($(APP))." \
  279. "-ifdef(TEST)." \
  280. "-include_lib(\"eunit/include/eunit.hrl\")." \
  281. "ok_test() -> application:ensure_all_started($(APP))." \
  282. "-endif." > $(APP)/src/$(APP).erl
  283. $i "Run EUnit with code coverage enabled"
  284. $t $(MAKE) -C $(APP) eunit COVER=1 $v
  285. $i "Build the cover report"
  286. $t $(MAKE) -C $(APP) cover-report $v
  287. $i "Check that Cowboy and Cowlib were covered, but Ranch wasn't"
  288. $t test -f $(APP)/cover/cowboy_app.COVER.html
  289. $t test -f $(APP)/cover/cow_http_hd.COVER.html
  290. $t ! test -e $(APP)/cover/ranch_app.COVER.html
  291. cover-proper: init
  292. $i "Bootstrap a new OTP application named $(APP)"
  293. $t mkdir $(APP)/
  294. $t cp ../erlang.mk $(APP)/
  295. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  296. $i "Add PropEr to the list of dependencies"
  297. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = proper\n"}' $(APP)/Makefile
  298. $i "Generate a module containing Proper properties"
  299. $t printf "%s\n" \
  300. "-module($(APP))." \
  301. "-ifdef(TEST)." \
  302. "-include_lib(\"proper/include/proper.hrl\")." \
  303. "prop_foo() -> ?FORALL(_, any(), true)." \
  304. "-endif." > $(APP)/src/$(APP).erl
  305. $i "Run PropEr with code coverage enabled"
  306. $t $(MAKE) -C $(APP) proper COVER=1 $v
  307. $i "Check that the generated file exists"
  308. $t test -f $(APP)/cover/proper.coverdata
  309. $i "Check that the generated file is removed on clean"
  310. $t $(MAKE) -C $(APP) clean $v
  311. $t test ! -e $(APP)/cover/proper.coverdata
  312. cover-report-and-merge: init
  313. $i "Bootstrap a new OTP application named $(APP)"
  314. $t mkdir $(APP)/
  315. $t cp ../erlang.mk $(APP)/
  316. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  317. $i "Generate a Common Test suite"
  318. $t mkdir $(APP)/test
  319. $t printf "%s\n" \
  320. "-module($(APP)_SUITE)." \
  321. "-export([all/0, ok/1])." \
  322. "all() -> [ok]." \
  323. "ok(_) -> ok." > $(APP)/test/$(APP)_SUITE.erl
  324. $i "Generate a module containing EUnit tests"
  325. $t printf "%s\n" \
  326. "-module($(APP))." \
  327. "-ifdef(TEST)." \
  328. "-include_lib(\"eunit/include/eunit.hrl\")." \
  329. "ok_test() -> ok." \
  330. "-endif." > $(APP)/src/$(APP).erl
  331. $i "Run tests with code coverage enabled"
  332. $t $(MAKE) -C $(APP) tests COVER=1 $v
  333. $i "Check that the generated files exist"
  334. $t test -f $(APP)/cover/$(APP).COVER.html
  335. $t test -f $(APP)/cover/index.html
  336. $t test -f $(APP)/cover/ct.coverdata
  337. $t test -f $(APP)/cover/eunit.coverdata
  338. $t test -f $(APP)/test/ct.cover.spec
  339. $i "Merge coverdata files into all.coverdata"
  340. $t $(MAKE) -C $(APP) all.coverdata $v
  341. $t test -f $(APP)/cover/all.coverdata
  342. $i "Check that the generated files are removed on clean"
  343. $t $(MAKE) -C $(APP) clean $v
  344. $t test ! -e $(APP)/cover/all.coverdata
  345. $t test ! -e $(APP)/cover/ct.coverdata
  346. $t test ! -e $(APP)/cover/eunit.coverdata
  347. $t test ! -e $(APP)/test/ct.cover.spec
  348. $i "Check that the cover report is removed on distclean"
  349. $t $(MAKE) -C $(APP) distclean $v
  350. $t test ! -e $(APP)/cover/
  351. cover-triq: init
  352. $i "Bootstrap a new OTP application named $(APP)"
  353. $t mkdir $(APP)/
  354. $t cp ../erlang.mk $(APP)/
  355. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  356. $i "Add Triq to the list of dependencies"
  357. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = triq\n"}' $(APP)/Makefile
  358. $i "Generate a module containing Triq properties"
  359. $t printf "%s\n" \
  360. "-module($(APP))." \
  361. "-ifdef(TEST)." \
  362. "-include_lib(\"triq/include/triq.hrl\")." \
  363. "prop_foo() -> ?FORALL(_, any(), true)." \
  364. "-endif." > $(APP)/src/$(APP).erl
  365. $i "Run Triq with code coverage enabled"
  366. $t $(MAKE) -C $(APP) triq COVER=1 $v
  367. $i "Check that the generated file exists"
  368. $t test -f $(APP)/cover/triq.coverdata
  369. $i "Check that the generated file is removed on clean"
  370. $t $(MAKE) -C $(APP) clean $v
  371. $t test ! -e $(APP)/cover/triq.coverdata