plugin_xref.mk 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. # Xref plugin.
  2. XREF_TARGETS = $(call list_targets,xref)
  3. .PHONY: xref $(XREF_TARGETS)
  4. xref: $(XREF_TARGETS)
  5. xref-check: 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 "Run the Xref plugin"
  11. $t $(MAKE) -C $(APP) xref $v
  12. $i "Create a module with an undefined function call"
  13. $t printf "%s\n" \
  14. "-module(bad)." \
  15. "-export([f/0])." \
  16. "f() -> this_module:does_not_exist()." \
  17. > $(APP)/src/bad.erl
  18. $i "Run the Xref plugin again, expect an error"
  19. $t ! $(MAKE) -C $(APP) xref $v
  20. xref-check-custom: init
  21. $i "Bootstrap a new OTP application named $(APP)"
  22. $t mkdir $(APP)/
  23. $t cp ../erlang.mk $(APP)/
  24. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  25. $i "Run the Xref plugin with undefined_functions"
  26. $t $(MAKE) -C $(APP) xref XREF_CHECKS=undefined_functions $v
  27. $i "Create a module with an unused export"
  28. $t printf "%s\n" \
  29. "-module(bad1)." \
  30. "-export([f/0])." \
  31. "f() -> whereis(user) ! bad_message." \
  32. > $(APP)/src/bad1.erl
  33. $i "Run the Xref plugin with exports_not_used, expect an error"
  34. $t ! $(MAKE) -C $(APP) xref XREF_CHECKS=exports_not_used $v
  35. $i "Run the Xref plugin with multiple checks"
  36. $t $(MAKE) -C $(APP) xref XREF_CHECKS="[undefined_function_calls, undefined_functions]" $v
  37. $i "Create a module with an undefined function call"
  38. $t printf "%s\n" \
  39. "-module(bad2)." \
  40. "-export([f/0])." \
  41. "f() -> this_module:does_not_exist()." \
  42. > $(APP)/src/bad2.erl
  43. $i "Run the Xref plugin with multiple checks, expect an error"
  44. $t ! $(MAKE) -C $(APP) xref XREF_CHECKS="[undefined_function_calls, undefined_functions]" $v
  45. xref-check-informational: init
  46. $i "Bootstrap a new OTP application named $(APP)"
  47. $t mkdir $(APP)/
  48. $t cp ../erlang.mk $(APP)/
  49. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  50. $i "Run the Xref plugin with module_use"
  51. $t $(MAKE) -C $(APP) xref XREF_CHECKS="{module_use, $(APP)_sup}" > $(APP)/output.txt
  52. $i "Confirm that the module was found"
  53. $t grep -q "\- $(APP)_app$$" $(APP)/output.txt
  54. xref-query: init
  55. $i "Bootstrap a new OTP application named $(APP)"
  56. $t mkdir $(APP)/
  57. $t cp ../erlang.mk $(APP)/
  58. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  59. $i "Run the Xref plugin with query XC (external calls)"
  60. $t $(MAKE) -C $(APP) xref q="XC" > $(APP)/output.txt
  61. $i "Confirm that the supervisor:start_link/3 call was found"
  62. $t grep -q "\- supervisor:start_link/3 called by $(APP)_sup:start_link/0$$" $(APP)/output.txt
  63. xref-scope-apps: init
  64. $i "Bootstrap a new OTP library named $(APP)"
  65. $t mkdir $(APP)/
  66. $t cp ../erlang.mk $(APP)/
  67. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v
  68. $i "Create a new library my_app"
  69. $t $(MAKE) -C $(APP) new-lib in=my_app $v
  70. $i "Create a module with an undefined function call inside my_app"
  71. $t printf "%s\n" \
  72. "-module(bad2)." \
  73. "-export([f/0])." \
  74. "f() -> this_module:does_not_exist()." \
  75. > $(APP)/apps/my_app/src/bad2.erl
  76. $i "Run the Xref plugin with apps in the scope, expect an error"
  77. $t ! $(MAKE) -C $(APP) xref XREF_SCOPE="app apps" $v
  78. xref-scope-deps: init
  79. $i "Bootstrap a new OTP application named $(APP)"
  80. $t mkdir $(APP)/
  81. $t cp ../erlang.mk $(APP)/
  82. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  83. $i "Bootstrap a new OTP library named my_dep inside $(APP)"
  84. $t mkdir $(APP)/my_dep
  85. $t cp ../erlang.mk $(APP)/my_dep/
  86. $t $(MAKE) -C $(APP)/my_dep/ -f erlang.mk bootstrap-lib $v
  87. $i "Create a module with an undefined function call inside my_dep"
  88. $t printf "%s\n" \
  89. "-module(bad2)." \
  90. "-export([f/0])." \
  91. "f() -> this_module:does_not_exist()." \
  92. > $(APP)/my_dep/src/bad2.erl
  93. $i "Add my_dep to the list of dependencies"
  94. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = my_dep\ndep_my_dep = cp $(CURDIR)/$(APP)/my_dep/\n"}' $(APP)/Makefile
  95. ifdef LEGACY
  96. $i "Add my_dep to the applications key in the .app.src file"
  97. $t perl -ni.bak -e 'print;if ($$.==7) {print "\t\tmy_dep,\n"}' $(APP)/src/$(APP).app.src
  98. endif
  99. $i "Run the Xref plugin with deps in the scope, expect an error"
  100. $t ! $(MAKE) -C $(APP) xref XREF_SCOPE="app deps" $v
  101. xref-scope-otp: init
  102. $i "Bootstrap a new OTP application named $(APP)"
  103. $t mkdir $(APP)/
  104. $t cp ../erlang.mk $(APP)/
  105. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  106. $i "Run the Xref plugin for module use with OTP in the scope"
  107. $t $(MAKE) -C $(APP) xref XREF_CHECKS="{module_use, asn1ct_pretty_format}" \
  108. XREF_SCOPE="app otp" > $(APP)/output.txt
  109. $i "Confirm that the asn1ct_pretty_format module use was analysed"
  110. $t grep -q "\- asn1ct_pretty_format$$" $(APP)/output.txt
  111. xref-extra-apps: init
  112. $i "Bootstrap a new OTP application named $(APP)"
  113. $t mkdir $(APP)/
  114. $t cp ../erlang.mk $(APP)/
  115. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  116. $i "Bootstrap a new OTP library named extra_app inside $(APP)"
  117. $t mkdir $(APP)/extra_app
  118. $t cp ../erlang.mk $(APP)/extra_app/
  119. $t $(MAKE) -C $(APP)/extra_app/ -f erlang.mk bootstrap-lib $v
  120. $i "Create a module in extra_app with a function call to $(APP)"
  121. $t printf "%s\n" \
  122. "-module(extra)." \
  123. "-export([f/0])." \
  124. "f() -> $(APP)_sup:init([])." \
  125. > $(APP)/extra_app/src/extra.erl
  126. $i "Build extra_app"
  127. $t $(MAKE) -C $(APP)/extra_app $v
  128. $i "Run the Xref plugin for application use with the extra app"
  129. $t $(MAKE) -C $(APP) xref XREF_CHECKS="{application_use, $(APP)}" \
  130. XREF_EXTRA_APP_DIRS="extra_app/" > $(APP)/output.txt
  131. $i "Confirm that the extra_app application call was found"
  132. $t grep -q "\- extra_app$$" $(APP)/output.txt
  133. xref-extra-dirs: init
  134. $i "Bootstrap a new OTP application named $(APP)"
  135. $t mkdir $(APP)/
  136. $t cp ../erlang.mk $(APP)/
  137. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  138. $i "Bootstrap a new OTP library named extra_dir inside $(APP)"
  139. $t mkdir $(APP)/extra_dir
  140. $t cp ../erlang.mk $(APP)/extra_dir/
  141. $t $(MAKE) -C $(APP)/extra_dir/ -f erlang.mk bootstrap-lib $v
  142. $i "Create a module in extra_dir with an undefined function call"
  143. $t printf "%s\n" \
  144. "-module(bad)." \
  145. "-export([f/0])." \
  146. "f() -> this_module:does_not_exist()." \
  147. > $(APP)/extra_dir/src/bad.erl
  148. $i "Build extra_dir"
  149. $t $(MAKE) -C $(APP)/extra_dir $v
  150. $i "Run the Xref plugin with the extra dir, expect an error"
  151. $t ! $(MAKE) -C $(APP) xref XREF_EXTRA_DIRS="extra_dir/ebin/" $v
  152. xref-ignore-inline-fa: init
  153. $i "Bootstrap a new OTP application named $(APP)"
  154. $t mkdir $(APP)/
  155. $t cp ../erlang.mk $(APP)/
  156. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  157. $i "Create a module with an undefined function call and an inline ignore"
  158. $t printf "%s\n" \
  159. "-module(bad)." \
  160. "-export([f/0])." \
  161. "-ignore_xref([{f,0}])." \
  162. "f() -> this_module:does_not_exist()." \
  163. > $(APP)/src/bad.erl
  164. $i "Run the Xref plugin, expect success"
  165. $t $(MAKE) -C $(APP) xref $v
  166. xref-ignore-inline-mfa: init
  167. $i "Bootstrap a new OTP application named $(APP)"
  168. $t mkdir $(APP)/
  169. $t cp ../erlang.mk $(APP)/
  170. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  171. $i "Create a module with an undefined function call and an inline ignore"
  172. $t printf "%s\n" \
  173. "-module(bad)." \
  174. "-export([f/0])." \
  175. "-ignore_xref([{bad,f,0}])." \
  176. "f() -> this_module:does_not_exist()." \
  177. > $(APP)/src/bad.erl
  178. $i "Run the Xref plugin, expect success"
  179. $t $(MAKE) -C $(APP) xref $v
  180. xref-ignore-inline-mod: init
  181. $i "Bootstrap a new OTP application named $(APP)"
  182. $t mkdir $(APP)/
  183. $t cp ../erlang.mk $(APP)/
  184. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  185. $i "Create a module with an undefined function call and an inline ignore"
  186. $t printf "%s\n" \
  187. "-module(bad)." \
  188. "-export([f/0])." \
  189. "-ignore_xref(?MODULE)." \
  190. "f() -> this_module:does_not_exist()." \
  191. > $(APP)/src/bad.erl
  192. $i "Run the Xref plugin, expect success"
  193. $t $(MAKE) -C $(APP) xref $v
  194. xref-ignore-project-wide-mfa: init
  195. $i "Bootstrap a new OTP application named $(APP)"
  196. $t mkdir $(APP)/
  197. $t cp ../erlang.mk $(APP)/
  198. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  199. $i "Create a module with an undefined function call"
  200. $t printf "%s\n" \
  201. "-module(bad)." \
  202. "-export([f/0])." \
  203. "f() -> this_module:does_not_exist()." \
  204. > $(APP)/src/bad.erl
  205. $i "Run the Xref plugin with project-wide ignore, expect success"
  206. $t $(MAKE) -C $(APP) xref XREF_IGNORE="{bad,f,0}" $v
  207. xref-ignore-project-wide-mod: init
  208. $i "Bootstrap a new OTP application named $(APP)"
  209. $t mkdir $(APP)/
  210. $t cp ../erlang.mk $(APP)/
  211. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  212. $i "Create a module with an undefined function call"
  213. $t printf "%s\n" \
  214. "-module(bad)." \
  215. "-export([f/0])." \
  216. "f() -> this_module:does_not_exist()." \
  217. > $(APP)/src/bad.erl
  218. $i "Run the Xref plugin with project-wide ignore, expect success"
  219. $t $(MAKE) -C $(APP) xref XREF_IGNORE="[bad]" $v
  220. xref-ignore-callbacks: init
  221. $i "Bootstrap a new OTP application named $(APP)"
  222. $t mkdir $(APP)/
  223. $t cp ../erlang.mk $(APP)/
  224. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  225. $i "Run the Xref plugin for exports_not_used, expect success"
  226. $t $(MAKE) -C $(APP) xref XREF_CHECKS="exports_not_used" $v
  227. $i "Run the Xref plugin again with explicit ignoring of callbacks, expect success"
  228. $t $(MAKE) -C $(APP) xref XREF_CHECKS="exports_not_used" XREF_IGNORE_CALLBACKS=1 $v
  229. $i "Run the Xref plugin again without ignoring callbacks, expect an error"
  230. $t ! $(MAKE) -C $(APP) xref XREF_CHECKS="exports_not_used" XREF_IGNORE_CALLBACKS=0 $v