test_basic.py 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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.on',
  26. '--general.log-level=INFO'],
  27. check_stderr=[(0, -1)],
  28. save_prev=True)
  29. self.assertExec(runner.run())
  30. runner = tests.common.ToolRunner('export',
  31. ['--general.log-level=INFO', '--general.format=xml'],
  32. check_stderr=[(0, -1)])
  33. self.assertExec(runner.run())
  34. runner = tests.common.ToolRunner('limit',
  35. ['--general.log-level=INFO',
  36. '--general.max-limit=std.code.complexity:cyclomatic:0'],
  37. check_stderr=[(0, -1)],
  38. exit_code=4)
  39. self.assertExec(runner.run())
  40. runner = tests.common.ToolRunner('info',
  41. ['--general.log-level=INFO'],
  42. check_stderr=[(0, -1)],
  43. exit_code=0)
  44. self.assertExec(runner.run())
  45. # second collection
  46. runner = tests.common.ToolRunner('collect',
  47. ['--std.code.complexity.on',
  48. '--general.log-level=INFO'],
  49. check_stderr=[(0, -1)],
  50. prefix='second',
  51. cwd="sources_changed",
  52. use_prev=True)
  53. self.assertExec(runner.run())
  54. runner = tests.common.ToolRunner('export',
  55. ['--general.log-level=INFO', '--general.format=xml'],
  56. check_stderr=[(0, -1)],
  57. prefix='second',
  58. use_prev=True)
  59. self.assertExec(runner.run())
  60. runner = tests.common.ToolRunner('export',
  61. ['--general.log-level=INFO', '--general.format=xml'],
  62. check_stderr=[(0, -1)],
  63. prefix='second_per_file',
  64. dirs_list=['./simple.cpp'],
  65. use_prev=True)
  66. self.assertExec(runner.run())
  67. runner = tests.common.ToolRunner('limit',
  68. ['--general.log-level=INFO',
  69. '--general.max-limit=std.code.complexity:cyclomatic:0'],
  70. check_stderr=[(0, -1)],
  71. exit_code=6,
  72. prefix='second',
  73. use_prev=True)
  74. self.assertExec(runner.run())
  75. runner = tests.common.ToolRunner('limit',
  76. ['--general.log-level=INFO',
  77. '--general.max-limit=std.code.complexity:cyclomatic:0',
  78. '--general.warn=all'],
  79. check_stderr=[(0, -1)],
  80. exit_code=6,
  81. prefix='second_warn_all',
  82. use_prev=True)
  83. self.assertExec(runner.run())
  84. runner = tests.common.ToolRunner('limit',
  85. ['--general.log-level=INFO',
  86. '--general.max-limit=std.code.complexity:cyclomatic:0',
  87. '--general.warn=touched'],
  88. check_stderr=[(0, -1)],
  89. exit_code=4,
  90. prefix='second_warn_touched',
  91. use_prev=True)
  92. self.assertExec(runner.run())
  93. runner = tests.common.ToolRunner('limit',
  94. ['--general.log-level=INFO',
  95. '--general.max-limit=std.code.complexity:cyclomatic:0',
  96. '--general.warn=trend'],
  97. check_stderr=[(0, -1)],
  98. exit_code=3,
  99. prefix='second_warn_trend',
  100. use_prev=True)
  101. self.assertExec(runner.run())
  102. runner = tests.common.ToolRunner('limit',
  103. ['--general.log-level=INFO',
  104. '--general.max-limit=std.code.complexity:cyclomatic:0',
  105. '--general.warn=new'],
  106. check_stderr=[(0, -1)],
  107. exit_code=2,
  108. prefix='second_warn_new',
  109. use_prev=True)
  110. self.assertExec(runner.run())
  111. runner = tests.common.ToolRunner('info',
  112. ['--general.log-level=INFO'],
  113. check_stderr=[(0, -1)],
  114. prefix='second',
  115. use_prev=True)
  116. self.assertExec(runner.run())
  117. def test_help(self):
  118. runner = tests.common.ToolRunner('collect', ['--help'])
  119. self.assertExec(runner.run())
  120. runner = tests.common.ToolRunner('export', ['--help'])
  121. self.assertExec(runner.run())
  122. runner = tests.common.ToolRunner('limit', ['--help'])
  123. self.assertExec(runner.run())
  124. runner = tests.common.ToolRunner('info', ['--help'])
  125. self.assertExec(runner.run())
  126. def test_export_format(self):
  127. runner = tests.common.ToolRunner('collect', ['--std.code.complexity.on'], save_prev=True)
  128. self.assertExec(runner.run())
  129. runner = tests.common.ToolRunner('export', ['--general.format=txt'], prefix='txt')
  130. self.assertExec(runner.run())
  131. runner = tests.common.ToolRunner('export', ['--general.format=python'], prefix='python')
  132. self.assertExec(runner.run())
  133. runner = tests.common.ToolRunner('export', ['--general.format=xml'], prefix='xml')
  134. self.assertExec(runner.run())
  135. runner = tests.common.ToolRunner('collect',
  136. ['--std.code.complexity.on'],
  137. prefix='nest',
  138. cwd="sources_changed",
  139. use_prev=True)
  140. self.assertExec(runner.run())
  141. runner = tests.common.ToolRunner('export',
  142. ['--general.nest-regions', '--general.format=xml'],
  143. prefix='nest',
  144. use_prev=True)
  145. self.assertExec(runner.run())
  146. runner = tests.common.ToolRunner('export',
  147. ['--general.nest-regions', '--general.format=xml'],
  148. prefix='nest_per_file',
  149. dirs_list=['./simple.cpp'],
  150. use_prev=True)
  151. self.assertExec(runner.run())
  152. if __name__ == '__main__':
  153. unittest.main()