plugin_dialyzer.mk 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. # Dialyzer plugin.
  2. DIALYZER_CASES = app apps-only apps-with-local-deps check custom-plt deps erlc-opts local-deps opts plt-apps
  3. DIALYZER_TARGETS = $(addprefix dialyzer-,$(DIALYZER_CASES))
  4. DIALYZER_CLEAN_TARGETS = $(addprefix clean-,$(DIALYZER_TARGETS))
  5. .PHONY: dialyzer $(C_SRC_TARGETS) clean-dialyzer $(DIALYZER_CLEAN_TARGETS)
  6. clean-dialyzer: $(DIALYZER_CLEAN_TARGETS)
  7. $(DIALYZER_CLEAN_TARGETS):
  8. $t rm -rf $(APP_TO_CLEAN)/
  9. dialyzer: $(DIALYZER_TARGETS)
  10. dialyzer-app: build clean-dialyzer-app
  11. $i "Bootstrap a new OTP application named $(APP)"
  12. $t mkdir $(APP)/
  13. $t cp ../erlang.mk $(APP)/
  14. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  15. $i "Run Dialyzer"
  16. $t $(MAKE) -C $(APP) dialyze $v
  17. $i "Check that the PLT file was created"
  18. $t test -f $(APP)/.$(APP).plt
  19. $i "Create a module with a function that has no local return"
  20. $t printf "%s\n" \
  21. "-module(warn_me)." \
  22. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  23. $i "Confirm that Dialyzer errors out"
  24. $t ! $(MAKE) -C $(APP) dialyze $v
  25. $i "Distclean the application"
  26. $t $(MAKE) -C $(APP) distclean $v
  27. $i "Check that the PLT file was removed"
  28. $t test ! -e $(APP)/.$(APP).plt
  29. dialyzer-apps-only: build clean-dialyzer-apps-only
  30. $i "Create a multi application repository with no root application"
  31. $t mkdir $(APP)/
  32. $t cp ../erlang.mk $(APP)/
  33. $t echo "include erlang.mk" > $(APP)/Makefile
  34. $i "Create a new application my_app"
  35. $t $(MAKE) -C $(APP) new-app in=my_app $v
  36. $i "Create a module my_server from gen_server template in my_app"
  37. $t $(MAKE) -C $(APP) new t=gen_server n=my_server in=my_app $v
  38. $i "Add Cowlib to the list of dependencies"
  39. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/apps/my_app/Makefile
  40. $i "Run Dialyzer"
  41. $t $(MAKE) -C $(APP) dialyze $v
  42. $i "Check that the PLT file was created automatically"
  43. $t test -f $(APP)/.$(APP).plt
  44. $i "Confirm that Cowlib was included in the PLT"
  45. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  46. $i "Create a module with a function that has no local return"
  47. $t printf "%s\n" \
  48. "-module(warn_me)." \
  49. "doit() -> 1 = 2, ok." > $(APP)/apps/my_app/src/warn_me.erl
  50. $i "Confirm that Dialyzer errors out"
  51. $t ! $(MAKE) -C $(APP) dialyze $v
  52. dialyzer-apps-with-local-deps: build clean-dialyzer-apps-with-local-deps
  53. $i "Create a multi application repository with no root application"
  54. $t mkdir $(APP)/
  55. $t cp ../erlang.mk $(APP)/
  56. $t echo "include erlang.mk" > $(APP)/Makefile
  57. $i "Create a new application my_app"
  58. $t $(MAKE) -C $(APP) new-app in=my_app $v
  59. $i "Create a new application my_core_app"
  60. $t $(MAKE) -C $(APP) new-app in=my_core_app $v
  61. $i "Add my_core_app to the list of local dependencies for my_app"
  62. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = my_core_app\n"}' $(APP)/apps/my_app/Makefile
  63. $i "Run Dialyzer"
  64. $t $(MAKE) -C $(APP) dialyze $v
  65. $i "Check that the PLT file was created automatically"
  66. $t test -f $(APP)/.$(APP).plt
  67. $i "Confirm that my_core_app was NOT included in the PLT"
  68. $t ! dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q my_core_app
  69. dialyzer-check: build clean-dialyzer-check
  70. $i "Bootstrap a new OTP application named $(APP)"
  71. $t mkdir $(APP)/
  72. $t cp ../erlang.mk $(APP)/
  73. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  74. $i "Run 'make check'"
  75. $t $(MAKE) -C $(APP) check $v
  76. $i "Check that the PLT file was created"
  77. $t test -f $(APP)/.$(APP).plt
  78. $i "Create a module with a function that has no local return"
  79. $t printf "%s\n" \
  80. "-module(warn_me)." \
  81. "doit() -> 1 = 2, ok." > $(APP)/src/warn_me.erl
  82. $i "Confirm that Dialyzer errors out on 'make check'"
  83. $t ! $(MAKE) -C $(APP) check $v
  84. dialyzer-custom-plt: build clean-dialyzer-custom-plt
  85. $i "Bootstrap a new OTP application named $(APP)"
  86. $t mkdir $(APP)/
  87. $t cp ../erlang.mk $(APP)/
  88. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  89. $i "Set a custom DIALYZER_PLT location"
  90. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_PLT = custom.plt\n"}' $(APP)/Makefile
  91. $i "Run Dialyzer"
  92. $t $(MAKE) -C $(APP) dialyze $v
  93. $i "Check that the PLT file was created"
  94. $t test -f $(APP)/custom.plt
  95. $i "Distclean the application"
  96. $t $(MAKE) -C $(APP) distclean $v
  97. $i "Check that the PLT file was removed"
  98. $t test ! -e $(APP)/custom.plt
  99. dialyzer-deps: build clean-dialyzer-deps
  100. $i "Bootstrap a new OTP application named $(APP)"
  101. $t mkdir $(APP)/
  102. $t cp ../erlang.mk $(APP)/
  103. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  104. $i "Add Cowlib to the list of dependencies"
  105. $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = cowlib\n"}' $(APP)/Makefile
  106. $i "Run Dialyzer"
  107. $t $(MAKE) -C $(APP) dialyze $v
  108. $i "Check that the PLT file was created"
  109. $t test -f $(APP)/.$(APP).plt
  110. $i "Confirm that Cowlib was included in the PLT"
  111. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q cowlib
  112. dialyzer-erlc-opts: build clean-dialyzer-erlc-opts
  113. $i "Bootstrap a new OTP application named $(APP)"
  114. $t mkdir $(APP)/
  115. $t cp ../erlang.mk $(APP)/
  116. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  117. $i "Create a header file in a non-standard directory"
  118. $t mkdir $(APP)/exotic/
  119. $t touch $(APP)/exotic/dialyze.hrl
  120. $i "Create a module that includes this header"
  121. $t printf "%s\n" \
  122. "-module(no_warn)." \
  123. "-export([doit/0])." \
  124. "-include(\"dialyze.hrl\")." \
  125. "doit() -> ok." > $(APP)/src/no_warn.erl
  126. $i "Point ERLC_OPTS to the non-standard include directory"
  127. $t perl -ni.bak -e 'print;if ($$.==1) {print "ERLC_OPTS += -I exotic\n"}' $(APP)/Makefile
  128. $i "Run Dialyzer"
  129. $t $(MAKE) -C $(APP) dialyze $v
  130. dialyzer-local-deps: build clean-dialyzer-local-deps
  131. $i "Bootstrap a new OTP application named $(APP)"
  132. $t mkdir $(APP)/
  133. $t cp ../erlang.mk $(APP)/
  134. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  135. $i "Add runtime_tools to the list of local dependencies"
  136. $t perl -ni.bak -e 'print;if ($$.==1) {print "LOCAL_DEPS = runtime_tools\n"}' $(APP)/Makefile
  137. $i "Build the PLT"
  138. $t $(MAKE) -C $(APP) plt $v
  139. $i "Confirm that runtime_tools was included in the PLT"
  140. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools
  141. dialyzer-opts: build clean-dialyzer-opts
  142. $i "Bootstrap a new OTP application named $(APP)"
  143. $t mkdir $(APP)/
  144. $t cp ../erlang.mk $(APP)/
  145. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  146. $i "Make Dialyzer save output to a file"
  147. $t perl -ni.bak -e 'print;if ($$.==1) {print "DIALYZER_OPTS = -o output.txt\n"}' $(APP)/Makefile
  148. $i "Create a module with a function that has no local return"
  149. $t printf "%s\n" \
  150. "-module(warn_me)." \
  151. "-export([doit/0])." \
  152. "doit() -> gen_tcp:connect(a, b, c), ok." > $(APP)/src/warn_me.erl
  153. $i "Run Dialyzer"
  154. $t ! $(MAKE) -C $(APP) dialyze $v
  155. $i "Check that the PLT file was created"
  156. $t test -f $(APP)/.$(APP).plt
  157. $i "Check that the output file was created"
  158. $t test -f $(APP)/output.txt
  159. dialyzer-plt-apps: build clean-dialyzer-plt-apps
  160. $i "Bootstrap a new OTP application named $(APP)"
  161. $t mkdir $(APP)/
  162. $t cp ../erlang.mk $(APP)/
  163. $t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
  164. $i "Add runtime_tools to PLT_APPS"
  165. $t perl -ni.bak -e 'print;if ($$.==1) {print "PLT_APPS = runtime_tools\n"}' $(APP)/Makefile
  166. $i "Build the PLT"
  167. $t $(MAKE) -C $(APP) plt $v
  168. $i "Confirm that runtime_tools was included in the PLT"
  169. $t dialyzer --plt_info --plt $(APP)/.$(APP).plt | grep -q runtime_tools