test_basic.py 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. #
  2. # Metrix++, Copyright 2009-2013, Metrix++ Project
  3. # Link: http://metrixplusplus.sourceforge.net
  4. #
  5. # This file is a part of Metrix++ Tool.
  6. #
  7. # Metrix++ is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, version 3 of the License.
  10. #
  11. # Metrix++ is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Metrix++. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. import unittest
  20. import tests.common
  21. class Test(tests.common.TestCase):
  22. def test_workflow(self):
  23. # first collection
  24. runner = tests.common.ToolRunner('collect',
  25. ['--std.code.complexity.cyclomatic',
  26. '--std.code.lines.total',
  27. '--std.code.lines.code',
  28. '--std.code.lines.preprocessor',
  29. '--std.code.lines.comments',
  30. '--std.suppress',
  31. '--log-level=INFO'],
  32. check_stderr=[(0, -1)],
  33. save_prev=True)
  34. self.assertExec(runner.run())
  35. runner = tests.common.ToolRunner('view',
  36. ['--log-level=INFO', '--format=xml'],
  37. check_stderr=[(0, -1)])
  38. self.assertExec(runner.run())
  39. runner = tests.common.ToolRunner('limit',
  40. ['--log-level=INFO',
  41. '--max-limit=std.code.complexity:cyclomatic:0'],
  42. check_stderr=[(0, -1)],
  43. exit_code=8)
  44. self.assertExec(runner.run())
  45. runner = tests.common.ToolRunner('info',
  46. ['--log-level=INFO'],
  47. check_stderr=[(0, -1)],
  48. exit_code=0)
  49. self.assertExec(runner.run())
  50. runner = tests.common.ToolRunner('export',
  51. ['--log-level=INFO'],
  52. check_stderr=[(0, -1)])
  53. self.assertExec(runner.run())
  54. # second collection
  55. runner = tests.common.ToolRunner('collect',
  56. ['--std.code.complexity.cyclomatic',
  57. '--std.code.lines.total',
  58. '--std.code.lines.code',
  59. '--std.code.lines.preprocessor',
  60. '--std.code.lines.comments',
  61. '--std.suppress',
  62. '--log-level=INFO'],
  63. check_stderr=[(0, -1)],
  64. prefix='second',
  65. cwd="sources_changed",
  66. use_prev=True)
  67. self.assertExec(runner.run())
  68. runner = tests.common.ToolRunner('view',
  69. ['--log-level=INFO', '--format=xml'],
  70. check_stderr=[(0, -1)],
  71. prefix='second',
  72. use_prev=True)
  73. self.assertExec(runner.run())
  74. runner = tests.common.ToolRunner('view',
  75. ['--log-level=INFO', '--format=xml'],
  76. check_stderr=[(0, -1)],
  77. prefix='second_per_file',
  78. dirs_list=['./simple.cpp'],
  79. use_prev=True)
  80. self.assertExec(runner.run())
  81. runner = tests.common.ToolRunner('view',
  82. ['--log-level=INFO', '--scope-mode=all'],
  83. check_stderr=[(0, -1)],
  84. prefix='second_txt_all',
  85. use_prev=True)
  86. self.assertExec(runner.run())
  87. runner = tests.common.ToolRunner('view',
  88. ['--log-level=INFO', '--scope-mode=all'],
  89. check_stderr=[(0, -1)],
  90. prefix='second_per_file_txt_all',
  91. dirs_list=['./simple.cpp'],
  92. use_prev=True)
  93. self.assertExec(runner.run())
  94. runner = tests.common.ToolRunner('view',
  95. ['--log-level=INFO', '--scope-mode=touched'],
  96. check_stderr=[(0, -1)],
  97. prefix='second_txt_touched',
  98. use_prev=True)
  99. self.assertExec(runner.run())
  100. runner = tests.common.ToolRunner('view',
  101. ['--log-level=INFO', '--scope-mode=touched'],
  102. check_stderr=[(0, -1)],
  103. prefix='second_per_file_txt_touched',
  104. dirs_list=['./simple.cpp'],
  105. use_prev=True)
  106. self.assertExec(runner.run())
  107. runner = tests.common.ToolRunner('view',
  108. ['--log-level=INFO', '--scope-mode=new'],
  109. check_stderr=[(0, -1)],
  110. prefix='second_txt_new',
  111. use_prev=True)
  112. self.assertExec(runner.run())
  113. runner = tests.common.ToolRunner('view',
  114. ['--log-level=INFO', '--scope-mode=new'],
  115. check_stderr=[(0, -1)],
  116. prefix='second_per_file_txt_new',
  117. dirs_list=['./simple.cpp'],
  118. use_prev=True)
  119. self.assertExec(runner.run())
  120. runner = tests.common.ToolRunner('limit',
  121. ['--log-level=INFO',
  122. '--max-limit=std.code.complexity:cyclomatic:0'],
  123. check_stderr=[(0, -1)],
  124. exit_code=6,
  125. prefix='second',
  126. use_prev=True)
  127. self.assertExec(runner.run())
  128. runner = tests.common.ToolRunner('limit',
  129. ['--log-level=INFO',
  130. '--max-limit=std.code.complexity:cyclomatic:0',
  131. '--warn-mode=all'],
  132. check_stderr=[(0, -1)],
  133. exit_code=6,
  134. prefix='second_warn_all',
  135. use_prev=True)
  136. self.assertExec(runner.run())
  137. runner = tests.common.ToolRunner('limit',
  138. ['--log-level=INFO',
  139. '--max-limit=std.code.complexity:cyclomatic:0',
  140. '--warn-mode=touched'],
  141. check_stderr=[(0, -1)],
  142. exit_code=4,
  143. prefix='second_warn_touched',
  144. use_prev=True)
  145. self.assertExec(runner.run())
  146. runner = tests.common.ToolRunner('limit',
  147. ['--log-level=INFO',
  148. '--max-limit=std.code.complexity:cyclomatic:0',
  149. '--warn-mode=trend'],
  150. check_stderr=[(0, -1)],
  151. exit_code=3,
  152. prefix='second_warn_trend',
  153. use_prev=True)
  154. self.assertExec(runner.run())
  155. runner = tests.common.ToolRunner('limit',
  156. ['--log-level=INFO',
  157. '--max-limit=std.code.complexity:cyclomatic:0',
  158. '--warn-mode=new'],
  159. check_stderr=[(0, -1)],
  160. exit_code=2,
  161. prefix='second_warn_new',
  162. use_prev=True)
  163. self.assertExec(runner.run())
  164. runner = tests.common.ToolRunner('info',
  165. ['--log-level=INFO'],
  166. check_stderr=[(0, -1)],
  167. prefix='second',
  168. use_prev=True)
  169. self.assertExec(runner.run())
  170. runner = tests.common.ToolRunner('export',
  171. ['--log-level=INFO'],
  172. check_stderr=[(0, -1)],
  173. prefix='second',
  174. use_prev=True)
  175. self.assertExec(runner.run())
  176. def test_help(self):
  177. runner = tests.common.ToolRunner('--help')
  178. self.assertExec(runner.run())
  179. runner = tests.common.ToolRunner('unknown', exit_code=2)
  180. self.assertExec(runner.run())
  181. runner = tests.common.ToolRunner('collect', ['--help'])
  182. self.assertExec(runner.run())
  183. runner = tests.common.ToolRunner('info', ['--help'])
  184. self.assertExec(runner.run())
  185. runner = tests.common.ToolRunner('view', ['--help'])
  186. self.assertExec(runner.run())
  187. runner = tests.common.ToolRunner('limit', ['--help'])
  188. self.assertExec(runner.run())
  189. runner = tests.common.ToolRunner('export', ['--help'])
  190. self.assertExec(runner.run())
  191. def test_view_format(self):
  192. # note: --scope-mode is tested in workflow test above
  193. runner = tests.common.ToolRunner('collect', ['--std.code.complexity.cyclomatic'], save_prev=True)
  194. self.assertExec(runner.run())
  195. runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
  196. self.assertExec(runner.run())
  197. runner = tests.common.ToolRunner('view', ['--format=python'], prefix='python')
  198. self.assertExec(runner.run())
  199. runner = tests.common.ToolRunner('view', ['--format=xml'], prefix='xml')
  200. self.assertExec(runner.run())
  201. runner = tests.common.ToolRunner('collect',
  202. ['--std.code.complexity.cyclomatic'],
  203. prefix='nest',
  204. cwd="sources_changed",
  205. use_prev=True)
  206. self.assertExec(runner.run())
  207. runner = tests.common.ToolRunner('view',
  208. ['--nest-regions', '--format=xml'],
  209. prefix='nest',
  210. use_prev=True)
  211. self.assertExec(runner.run())
  212. runner = tests.common.ToolRunner('view',
  213. ['--nest-regions', '--format=xml'],
  214. prefix='nest_per_file',
  215. dirs_list=['./simple.cpp'],
  216. use_prev=True)
  217. self.assertExec(runner.run())
  218. def test_std_general_metrics(self):
  219. runner = tests.common.ToolRunner('collect',
  220. ['--std.general.size',
  221. '--std.general.procerrors',
  222. '--std.general.proctime'])
  223. self.assertExec(runner.run())
  224. runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
  225. self.assertExec(runner.run())
  226. runner = tests.common.ToolRunner('view',
  227. ['--nest-regions', '--format=txt'],
  228. prefix='nest_per_file',
  229. dirs_list=['./simple.cpp'])
  230. self.assertExec(runner.run())
  231. def test_std_lines_metrics(self):
  232. runner = tests.common.ToolRunner('collect',
  233. ['--std.code.lines.code',
  234. '--std.code.lines.preprocessor',
  235. '--std.code.lines.comments',
  236. '--std.code.lines.total'])
  237. self.assertExec(runner.run())
  238. runner = tests.common.ToolRunner('view',
  239. ['--nest-regions', '--format=txt'],
  240. prefix='nest_per_file',
  241. dirs_list=['./simple.cpp'])
  242. self.assertExec(runner.run())
  243. runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
  244. self.assertExec(runner.run())
  245. def test_std_filelines_metrics(self):
  246. runner = tests.common.ToolRunner('collect',
  247. ['--std.code.filelines.code',
  248. '--std.code.filelines.preprocessor',
  249. '--std.code.filelines.comments',
  250. '--std.code.filelines.total'])
  251. self.assertExec(runner.run())
  252. runner = tests.common.ToolRunner('view',
  253. ['--nest-regions', '--format=txt'],
  254. prefix='nest_per_file',
  255. dirs_list=['./simple.cpp'])
  256. self.assertExec(runner.run())
  257. runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
  258. self.assertExec(runner.run())
  259. def test_std_complexity_maxindent(self):
  260. runner = tests.common.ToolRunner('collect',
  261. ['--std.code.complexity.maxindent'])
  262. self.assertExec(runner.run())
  263. runner = tests.common.ToolRunner('view',
  264. ['--nest-regions'],
  265. prefix='nest_per_file',
  266. dirs_list=['./simple.cpp'])
  267. self.assertExec(runner.run())
  268. runner = tests.common.ToolRunner('view')
  269. self.assertExec(runner.run())
  270. def test_std_code_magic(self):
  271. runner = tests.common.ToolRunner('collect',
  272. ['--std.code.magic.numbers'])
  273. self.assertExec(runner.run())
  274. runner = tests.common.ToolRunner('view',
  275. ['--nest-regions'],
  276. prefix='nest_per_file',
  277. dirs_list=['./simple.cpp'])
  278. self.assertExec(runner.run())
  279. runner = tests.common.ToolRunner('view')
  280. self.assertExec(runner.run())
  281. runner = tests.common.ToolRunner('collect',
  282. ['--std.code.magic.numbers', '--std.code.magic.numbers.simplier'],
  283. prefix='nozeros',)
  284. self.assertExec(runner.run())
  285. runner = tests.common.ToolRunner('view',
  286. ['--nest-regions'],
  287. prefix='nozeros_nest_per_file',
  288. dirs_list=['./simple.cpp'])
  289. self.assertExec(runner.run())
  290. runner = tests.common.ToolRunner('view', prefix='nozeros')
  291. self.assertExec(runner.run())
  292. def test_std_member_metrics(self):
  293. runner = tests.common.ToolRunner('collect',
  294. ['--std.code.member.fields',
  295. '--std.code.member.globals',
  296. '--std.code.member.classes',
  297. '--std.code.member.structs',
  298. '--std.code.member.interfaces',
  299. '--std.code.member.types',
  300. '--std.code.member.methods',
  301. '--std.code.member.namespaces'])
  302. self.assertExec(runner.run())
  303. runner = tests.common.ToolRunner('view',
  304. ['--nest-regions', '--format=txt'],
  305. prefix='nest_per_file',
  306. dirs_list=['./simple.cpp'])
  307. self.assertExec(runner.run())
  308. runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
  309. self.assertExec(runner.run())
  310. if __name__ == '__main__':
  311. unittest.main()