Browse Source

Test for C++ parser added

avkonst 12 years ago
parent
commit
1748cc3450

+ 26 - 3
mainline/tests/common.py

@@ -29,7 +29,7 @@ class ToolRunner(object):
 
     def __init__(self,
                  tool_name,
-                 opts_list,
+                 opts_list = [],
                  dirs_list = None,
                  cwd='sources',
                  prefix = "default",
@@ -72,7 +72,7 @@ class ToolRunner(object):
         self.dirs_list = [] 
         if dirs_list != None:
             for each in dirs_list:
-                self.dirs_list = [each]
+                self.dirs_list.append(each)
                
         self.call_args = ['python', os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], tool_name + ".py")] \
                     + db_opts + opts_list + ['--'] + self.dirs_list
@@ -114,6 +114,10 @@ class ToolRunner(object):
                 f = open(real_file_stderr, 'wb');
                 f.write(child_stderr);
                 f.close()
+            else:
+                if os.path.exists(real_file_stderr):
+                    os.unlink(real_file_stderr)
+
 
         if self.save_prev == True:
             shutil.copy2(self.dbfile, self.dbfile_prev)                
@@ -193,9 +197,28 @@ class ToolRunner(object):
     
 class TestCase(unittest.TestCase):
 
+    def get_content_paths(self, cwd='sources'): 
+        curframe = inspect.currentframe()
+        calframe = inspect.getouterframes(curframe, 2)
+        test_name = calframe[1][3]
+        suite_name = os.path.splitext(os.path.basename(calframe[1][1]))[0]
+        group_name = os.path.basename(os.path.dirname(calframe[1][1]))
+        
+        class ContentPaths(object):
+            
+            def __init__(self, cwd, dbfile, dbfile_prev):
+                self.cwd = cwd
+                self.dbfile = dbfile
+                self.dbfile_prev = dbfile_prev
+                
+        return ContentPaths(os.path.join('tests', group_name, suite_name, cwd),
+                            os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tests', group_name, suite_name, test_name + ".db"),
+                            os.path.join(os.environ['METRIXPLUSPLUS_INSTALL_DIR'], 'tests', group_name, suite_name, test_name + ".prev.db"))
+
     def setUp(self):
+        unittest.TestCase.setUp(self)
+
         logging.basicConfig(format="[TEST-LOG]: %(levelname)s:\t%(message)s", level=logging.WARN)
-        
         log_level = os.environ['METRIXPLUSPLUS_LOG_LEVEL']
         if log_level == 'ERROR':
             log_level = logging.ERROR

+ 47 - 0
mainline/tests/general/test_std_code_cpp.py

@@ -0,0 +1,47 @@
+#
+#    Metrix++, Copyright 2009-2013, Metrix++ Project
+#    Link: http://metrixplusplus.sourceforge.net
+#    
+#    This file is a part of Metrix++ Tool.
+#    
+#    Metrix++ is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, version 3 of the License.
+#    
+#    Metrix++ is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+#    GNU General Public License for more details.
+#    
+#    You should have received a copy of the GNU General Public License
+#    along with Metrix++.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+
+import unittest
+import os
+
+import tests.common
+
+class TestBasic(tests.common.TestCase):
+
+    def test_parser(self):
+        
+        runner = tests.common.ToolRunner('collect', ['--std.code.complexity.on'])
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('export')
+        self.assertExec(runner.run())
+        
+        dirs_list = [os.path.join('.', each) for each in os.listdir(self.get_content_paths().cwd)]
+        print dirs_list
+        runner = tests.common.ToolRunner('export', opts_list=['--general.format=txt'], dirs_list=dirs_list, prefix='files')
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('limit',
+                                         ['--general.max-limit=std.code.complexity:cyclomatic:0'],
+                                         exit_code=11)
+        self.assertExec(runner.run())
+
+if __name__ == '__main__':
+    unittest.main()

File diff suppressed because it is too large
+ 1 - 1
mainline/tests/general/test_std_code_cpp/sources/test.c


+ 0 - 0
mainline/tests/general/test_std_code_cpp/test_parser_collect_default_stdout.gold.txt


+ 20 - 0
mainline/tests/general/test_std_code_cpp/test_parser_export_default_stdout.gold.txt

@@ -0,0 +1,20 @@
+<export>
+
+    <data>
+        <info path="" id="1" />
+        <file-data />
+        <subfiles>
+        </subfiles>
+        <subdirs>
+            <subdir>.</subdir>
+        </subdirs>
+        <aggregated-data>
+            <std.code.complexity>
+                <cyclomatic max="2" total="15.0" avg="0.180722891566" min="0" />
+            </std.code.complexity>
+            <std.code.cpp>
+                <mismatched_brackets max="3" total="3.0" avg="None" min="None" />
+            </std.code.cpp>
+        </aggregated-data>
+    </data>
+</export>

File diff suppressed because it is too large
+ 1377 - 0
mainline/tests/general/test_std_code_cpp/test_parser_export_files_stdout.gold.txt


+ 88 - 0
mainline/tests/general/test_std_code_cpp/test_parser_limit_default_stdout.gold.txt

@@ -0,0 +1,88 @@
+./operator_test.hpp:6: warning: Metric 'std.code.complexity/cyclomatic' for region 'policy_mcr' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : policy_mcr
+	Metric value   : 2
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./operator_test.hpp:71: warning: Metric 'std.code.complexity/cyclomatic' for region 'operator &&' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : operator &&
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./operator_test.hpp:72: warning: Metric 'std.code.complexity/cyclomatic' for region 'operator ||' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : operator ||
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test.c:147: warning: Metric 'std.code.complexity/cyclomatic' for region 'uppercase' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : uppercase
+	Metric value   : 2
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test.c:216: warning: Metric 'std.code.complexity/cyclomatic' for region 'reset' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : reset
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test.c:296: warning: Metric 'std.code.complexity/cyclomatic' for region 'save' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : save
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test.c:332: warning: Metric 'std.code.complexity/cyclomatic' for region 'main' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : main
+	Metric value   : 2
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test2.cpp:7: warning: Metric 'std.code.complexity/cyclomatic' for region 'A' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : A
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test3.cpp:39: warning: Metric 'std.code.complexity/cyclomatic' for region 'doColor' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : doColor
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test3.cpp:53: warning: Metric 'std.code.complexity/cyclomatic' for region 'doFont' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : doFont
+	Metric value   : 1
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+
+./test3.cpp:72: warning: Metric 'std.code.complexity/cyclomatic' for region 'doFont222' exceeds the limit.
+	Metric name    : std.code.complexity/cyclomatic
+	Region name    : doFont222
+	Metric value   : 2
+	Modified       : None
+	Change trend   : None
+	Limit          : 0.0
+