test_basic.py 17 KB

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