Browse Source

lines metrics + tests

avkonst 11 years ago
parent
commit
6a441f1719

+ 0 - 2
mainline/core/db/loader.py

@@ -891,8 +891,6 @@ class Loader(object):
         if self.db == None:
             return None
         
-        # TODO implement restriction for non_zero fields
-
         final_path_like = path_like_filter
         if path != None:
             if self.db.check_dir(path) == False and self.db.check_file(path) == False:

+ 37 - 16
mainline/ext/std/code/lines.py

@@ -35,10 +35,6 @@ class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
                          help="Enables collection of lines of comments metric - "
                          "number of non-empty lines of comments "
                          "[default: %default]")
-        parser.add_option("--std.code.lines.blank", "--sclb", action="store_true", default=False,
-                         help="Enables collection of blank lines metric - "
-                         "number of blank lines, i.e. lines without code or comments "
-                         "[default: %default]")
         parser.add_option("--std.code.lines.total", "--sclt", action="store_true", default=False,
                          help="Enables collection of lines of comments metric - "
                          "number of non-empty lines of comments "
@@ -48,7 +44,6 @@ class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
         self.is_active_code = options.__dict__['std.code.lines.code']
         self.is_active_preprocessor = options.__dict__['std.code.lines.preprocessor']
         self.is_active_comments = options.__dict__['std.code.lines.comments']
-        self.is_active_blank = options.__dict__['std.code.lines.blank']
         self.is_active_total = options.__dict__['std.code.lines.total']
         
     def initialize(self):
@@ -59,8 +54,6 @@ class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
             fields.append(self.Field('preprocessor', int))
         if self.is_active_comments == True:
             fields.append(self.Field('comments', int))
-        if self.is_active_blank == True:
-            fields.append(self.Field('blank', int))
         if self.is_active_total == True:
             fields.append(self.Field('total', int))
         core.api.Plugin.initialize(self, fields=fields)
@@ -74,13 +67,41 @@ class Plugin(core.api.Plugin, core.api.Child, core.api.IConfigurable):
         is_updated = is_updated or self.is_updated
         if is_updated == True:
             if self.is_active_code == True:
-                text = data.get_content(exclude = data.get_marker_types().ALL_EXCEPT_CODE)
-                for region in data.iterate_regions():
-                    count = 0
-                    start_pos = region.get_offset_begin()
-                    for sub_id in region.iterate_subregion_ids():
-                        count += len(self.pattern_line.findall(text, start_pos, data.get_region(sub_id).get_offset_begin()))
-                        start_pos = data.get_region(sub_id).get_offset_end()
-                    count += len(self.pattern_line.findall(text, start_pos, region.get_offset_end()))
-                    region.set_data(self.get_name(), 'code', count)
+                self.count_in_code(data,
+                                   data.get_marker_types().ALL_EXCEPT_CODE,
+                                   'code')
+            if self.is_active_preprocessor == True:
+                self.count_in_markers(data,
+                                      data.get_marker_types().PREPROCESSOR,
+                                      'preprocessor')
+            if self.is_active_comments == True:
+                self.count_in_markers(data,
+                                      data.get_marker_types().COMMENT,
+                                      'comments')
+            if self.is_active_total == True:
+                self.count_in_code(data,
+                                   data.get_marker_types().NONE,
+                                   'total')
     
+    def count_in_code(self, data, exclude, field_name):
+        text = data.get_content(exclude=exclude)
+        for region in data.iterate_regions():
+            count = 0
+            start_pos = region.get_offset_begin()
+            for sub_id in region.iterate_subregion_ids():
+                count += len(self.pattern_line.findall(text, start_pos, data.get_region(sub_id).get_offset_begin()))
+                start_pos = data.get_region(sub_id).get_offset_end()
+            count += len(self.pattern_line.findall(text, start_pos, region.get_offset_end()))
+            region.set_data(self.get_name(), 'code', count)
+        
+    def count_in_markers(self, data, marker_type, field_name):
+        text = data.get_content()
+        for region in data.iterate_regions():
+            count = 0
+            for marker in data.iterate_markers(
+                            filter_group = marker_type,
+                            region_id = region.get_id(),
+                            exclude_children = True):
+                count += len(self.pattern_line.findall(text, marker.get_offset_begin(), marker.get_offset_end()))
+            region.set_data(self.get_name(), field_name, count)
+            

+ 18 - 0
mainline/tests/general/test_basic.py

@@ -207,5 +207,23 @@ class Test(tests.common.TestCase):
                                          dirs_list=['./simple.cpp'])
         self.assertExec(runner.run())
 
+    def test_std_lines_metrics(self):
+
+        runner = tests.common.ToolRunner('collect',
+                                         ['--std.code.lines.code',
+                                          '--std.code.lines.preprocessor',
+                                          '--std.code.lines.comments',
+                                          '--std.code.lines.total'])
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('view',
+                                         ['--nest-regions', '--format=txt'],
+                                         prefix='nest_per_file',
+                                         dirs_list=['./simple.cpp'])
+        self.assertExec(runner.run())
+
 if __name__ == '__main__':
     unittest.main()

+ 0 - 4
mainline/tests/general/test_basic/test_help_collect_default_stdout.gold.txt

@@ -58,10 +58,6 @@ Options:
   --std.code.lines.comments, --sclcom
                         Enables collection of lines of comments metric -
                         number of non-empty lines of comments [default: False]
-  --std.code.lines.blank, --sclb
-                        Enables collection of blank lines metric - number of
-                        blank lines, i.e. lines without code or comments
-                        [default: False]
   --std.code.lines.total, --sclt
                         Enables collection of lines of comments metric -
                         number of non-empty lines of comments [default: False]

+ 6 - 6
mainline/tests/general/test_basic/test_std_general_metrics_view_nest_per_file_stdout.gold.txt

@@ -106,7 +106,7 @@ data:
 .   .   .   .   .   .   .   .   .   .   data: 
 .   .   .   .   .   .   .   .   .   .   subregions:
 .   .   std.general: 
-.   .   .   proctime="0.00399994850159"
+.   .   .   proctime="0.00300002098083"
 .   .   .   size="487"
 .   subfiles:
 .   subdirs:
@@ -121,15 +121,15 @@ data:
 .   .   .   .   distribution-bars:
 .   .   .   proctime: 
 .   .   .   .   count="1"
-.   .   .   .   max="0.00399994850159"
-.   .   .   .   avg="0.00399994850159"
-.   .   .   .   total="0.00399994850159"
-.   .   .   .   min="0.00399994850159" 
+.   .   .   .   max="0.00300002098083"
+.   .   .   .   avg="0.00300002098083"
+.   .   .   .   total="0.00300002098083"
+.   .   .   .   min="0.00300002098083" 
 .   .   .   .   distribution-bars:
 .   .   .   .   
 .   .   .   .   .   distribution-bar: 
 .   .   .   .   .   .   count="1"
-.   .   .   .   .   .   metric="0.00399994850159"
+.   .   .   .   .   .   metric="0.00300002098083"
 .   .   .   .   .   .   ratio="1.0"
 .   .   .   size: 
 .   .   .   .   count="1"

+ 5 - 5
mainline/tests/general/test_basic/test_std_general_metrics_view_txt_stdout.gold.txt

@@ -22,15 +22,15 @@ data:
 .   .   .   .   distribution-bars:
 .   .   .   proctime: 
 .   .   .   .   count="1"
-.   .   .   .   max="0.00399994850159"
-.   .   .   .   avg="0.00399994850159"
-.   .   .   .   total="0.00399994850159"
-.   .   .   .   min="0.00399994850159" 
+.   .   .   .   max="0.00300002098083"
+.   .   .   .   avg="0.00300002098083"
+.   .   .   .   total="0.00300002098083"
+.   .   .   .   min="0.00300002098083" 
 .   .   .   .   distribution-bars:
 .   .   .   .   
 .   .   .   .   .   distribution-bar: 
 .   .   .   .   .   .   count="1"
-.   .   .   .   .   .   metric="0.00399994850159"
+.   .   .   .   .   .   metric="0.00300002098083"
 .   .   .   .   .   .   ratio="1.0"
 .   .   .   size: 
 .   .   .   .   count="1"

+ 0 - 0
mainline/tests/general/test_basic/test_std_lines_metrics_collect_default_stdout.gold.txt


+ 229 - 0
mainline/tests/general/test_basic/test_std_lines_metrics_view_nest_per_file_stdout.gold.txt

@@ -0,0 +1,229 @@
+================================================================================
+Export
+________________________________________________________________________________
+
+--------------------------------------------------------------------------------
+data:  
+.   info: 
+.   .   path="./simple.cpp"
+.   .   id="1"
+.   file-data:  
+.   .   regions:
+.   .   
+.   .   .   region:  
+.   .   .   .   info: 
+.   .   .   .   .   cursor="0"
+.   .   .   .   .   name="__global__"
+.   .   .   .   .   offset_end="487"
+.   .   .   .   .   line_begin="3"
+.   .   .   .   .   type="global"
+.   .   .   .   .   line_end="52"
+.   .   .   .   .   offset_begin="2"
+.   .   .   .   data:  
+.   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   code="0"
+.   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   comments="0"
+.   .   .   .   subregions:
+.   .   .   .   
+.   .   .   .   .   subregion:  
+.   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   cursor="4"
+.   .   .   .   .   .   .   name="hmm"
+.   .   .   .   .   .   .   offset_end="486"
+.   .   .   .   .   .   .   line_begin="3"
+.   .   .   .   .   .   .   type="namespace"
+.   .   .   .   .   .   .   line_end="51"
+.   .   .   .   .   .   .   offset_begin="2"
+.   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   code="5"
+.   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   comments="1"
+.   .   .   .   .   .   subregions:
+.   .   .   .   .   .   
+.   .   .   .   .   .   .   subregion:  
+.   .   .   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   .   .   cursor="7"
+.   .   .   .   .   .   .   .   .   name="A"
+.   .   .   .   .   .   .   .   .   offset_end="482"
+.   .   .   .   .   .   .   .   .   line_begin="7"
+.   .   .   .   .   .   .   .   .   type="class"
+.   .   .   .   .   .   .   .   .   line_end="49"
+.   .   .   .   .   .   .   .   .   offset_begin="76"
+.   .   .   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   .   .   code="4"
+.   .   .   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   .   .   comments="0"
+.   .   .   .   .   .   .   .   subregions:
+.   .   .   .   .   .   .   .   
+.   .   .   .   .   .   .   .   .   subregion:  
+.   .   .   .   .   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   .   .   .   .   cursor="10"
+.   .   .   .   .   .   .   .   .   .   .   name="A"
+.   .   .   .   .   .   .   .   .   .   .   offset_end="234"
+.   .   .   .   .   .   .   .   .   .   .   line_begin="10"
+.   .   .   .   .   .   .   .   .   .   .   type="function"
+.   .   .   .   .   .   .   .   .   .   .   line_end="21"
+.   .   .   .   .   .   .   .   .   .   .   offset_begin="88"
+.   .   .   .   .   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   .   .   .   .   code="12"
+.   .   .   .   .   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   .   .   .   .   comments="2"
+.   .   .   .   .   .   .   .   .   .   subregions:
+.   .   .   .   .   .   .   .   
+.   .   .   .   .   .   .   .   .   subregion:  
+.   .   .   .   .   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   .   .   .   .   cursor="23"
+.   .   .   .   .   .   .   .   .   .   .   name="func"
+.   .   .   .   .   .   .   .   .   .   .   offset_end="386"
+.   .   .   .   .   .   .   .   .   .   .   line_begin="23"
+.   .   .   .   .   .   .   .   .   .   .   type="function"
+.   .   .   .   .   .   .   .   .   .   .   line_end="37"
+.   .   .   .   .   .   .   .   .   .   .   offset_begin="237"
+.   .   .   .   .   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   .   .   .   .   code="5"
+.   .   .   .   .   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   .   .   .   .   comments="0"
+.   .   .   .   .   .   .   .   .   .   subregions:
+.   .   .   .   .   .   .   .   .   .   
+.   .   .   .   .   .   .   .   .   .   .   subregion:  
+.   .   .   .   .   .   .   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   .   .   .   .   .   .   cursor="25"
+.   .   .   .   .   .   .   .   .   .   .   .   .   name="embeded"
+.   .   .   .   .   .   .   .   .   .   .   .   .   offset_end="372"
+.   .   .   .   .   .   .   .   .   .   .   .   .   line_begin="25"
+.   .   .   .   .   .   .   .   .   .   .   .   .   type="class"
+.   .   .   .   .   .   .   .   .   .   .   .   .   line_end="35"
+.   .   .   .   .   .   .   .   .   .   .   .   .   offset_begin="266"
+.   .   .   .   .   .   .   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   code="3"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   comments="0"
+.   .   .   .   .   .   .   .   .   .   .   .   subregions:
+.   .   .   .   .   .   .   .   .   .   .   .   
+.   .   .   .   .   .   .   .   .   .   .   .   .   subregion:  
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   cursor="27"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   name="embeded"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   offset_end="368"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   line_begin="27"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   type="function"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   line_end="34"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   offset_begin="287"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   code="8"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   .   .   comments="1"
+.   .   .   .   .   .   .   .   .   .   .   .   .   .   subregions:
+.   .   .   .   .   .   .   .   
+.   .   .   .   .   .   .   .   .   subregion:  
+.   .   .   .   .   .   .   .   .   .   info: 
+.   .   .   .   .   .   .   .   .   .   .   cursor="39"
+.   .   .   .   .   .   .   .   .   .   .   name="never"
+.   .   .   .   .   .   .   .   .   .   .   offset_end="459"
+.   .   .   .   .   .   .   .   .   .   .   line_begin="39"
+.   .   .   .   .   .   .   .   .   .   .   type="function"
+.   .   .   .   .   .   .   .   .   .   .   line_end="46"
+.   .   .   .   .   .   .   .   .   .   .   offset_begin="389"
+.   .   .   .   .   .   .   .   .   .   data:  
+.   .   .   .   .   .   .   .   .   .   .   std.code.lines: 
+.   .   .   .   .   .   .   .   .   .   .   .   code="7"
+.   .   .   .   .   .   .   .   .   .   .   .   preprocessor="0"
+.   .   .   .   .   .   .   .   .   .   .   .   comments="0"
+.   .   .   .   .   .   .   .   .   .   subregions:
+.   subfiles:
+.   subdirs:
+.   aggregated-data:  
+.   .   std.code.lines:  
+.   .   .   code: 
+.   .   .   .   count="8"
+.   .   .   .   max="12"
+.   .   .   .   avg="5.5"
+.   .   .   .   total="44.0"
+.   .   .   .   min="0" 
+.   .   .   .   distribution-bars:
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="0"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="3"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="4"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="2"
+.   .   .   .   .   .   metric="5"
+.   .   .   .   .   .   ratio="0.25"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="7"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="8"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="12"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   total: 
+.   .   .   .   count="0"
+.   .   .   .   max="None"
+.   .   .   .   avg="None"
+.   .   .   .   total="0.0"
+.   .   .   .   min="None" 
+.   .   .   .   distribution-bars:
+.   .   .   preprocessor: 
+.   .   .   .   count="8"
+.   .   .   .   max="0"
+.   .   .   .   avg="0.0"
+.   .   .   .   total="0.0"
+.   .   .   .   min="0" 
+.   .   .   .   distribution-bars:
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="8"
+.   .   .   .   .   .   metric="0"
+.   .   .   .   .   .   ratio="1.0"
+.   .   .   comments: 
+.   .   .   .   count="8"
+.   .   .   .   max="2"
+.   .   .   .   avg="0.5"
+.   .   .   .   total="4.0"
+.   .   .   .   min="0" 
+.   .   .   .   distribution-bars:
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="5"
+.   .   .   .   .   .   metric="0"
+.   .   .   .   .   .   ratio="0.625"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="2"
+.   .   .   .   .   .   metric="1"
+.   .   .   .   .   .   ratio="0.25"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="2"
+.   .   .   .   .   .   ratio="0.125"
+================================================================================
+
+

+ 101 - 0
mainline/tests/general/test_basic/test_std_lines_metrics_view_txt_stdout.gold.txt

@@ -0,0 +1,101 @@
+================================================================================
+Export
+________________________________________________________________________________
+
+--------------------------------------------------------------------------------
+data:  
+.   info: 
+.   .   path=""
+.   .   id="1"
+.   file-data: 
+.   subfiles:
+.   subdirs:
+.   .   .
+.   aggregated-data:  
+.   .   std.code.lines:  
+.   .   .   code: 
+.   .   .   .   count="8"
+.   .   .   .   max="12"
+.   .   .   .   avg="5.5"
+.   .   .   .   total="44.0"
+.   .   .   .   min="0" 
+.   .   .   .   distribution-bars:
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="0"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="3"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="4"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="2"
+.   .   .   .   .   .   metric="5"
+.   .   .   .   .   .   ratio="0.25"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="7"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="8"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="12"
+.   .   .   .   .   .   ratio="0.125"
+.   .   .   total: 
+.   .   .   .   count="0"
+.   .   .   .   max="None"
+.   .   .   .   avg="None"
+.   .   .   .   total="0.0"
+.   .   .   .   min="None" 
+.   .   .   .   distribution-bars:
+.   .   .   preprocessor: 
+.   .   .   .   count="8"
+.   .   .   .   max="0"
+.   .   .   .   avg="0.0"
+.   .   .   .   total="0.0"
+.   .   .   .   min="0" 
+.   .   .   .   distribution-bars:
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="8"
+.   .   .   .   .   .   metric="0"
+.   .   .   .   .   .   ratio="1.0"
+.   .   .   comments: 
+.   .   .   .   count="8"
+.   .   .   .   max="2"
+.   .   .   .   avg="0.5"
+.   .   .   .   total="4.0"
+.   .   .   .   min="0" 
+.   .   .   .   distribution-bars:
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="5"
+.   .   .   .   .   .   metric="0"
+.   .   .   .   .   .   ratio="0.625"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="2"
+.   .   .   .   .   .   metric="1"
+.   .   .   .   .   .   ratio="0.25"
+.   .   .   .   
+.   .   .   .   .   distribution-bar: 
+.   .   .   .   .   .   count="1"
+.   .   .   .   .   .   metric="2"
+.   .   .   .   .   .   ratio="0.125"
+================================================================================
+
+