Browse Source

Improved limit to print number of reported regions per limit. Fixed bug with python format output.

avkonst 10 years ago
parent
commit
76fde46958
34 changed files with 65 additions and 17 deletions
  1. 10 4
      mainline/ext/std/tools/limit.py
  2. 1 1
      mainline/mpp/cout.py
  3. 1 1
      mainline/mpp/utils.py
  4. 1 1
      mainline/tests/general/test_basic/test_view_format_view_python_stdout.gold.txt
  5. 1 1
      mainline/tests/general/test_basic/test_workflow_limit_default_stderr.gold.txt
  6. 2 0
      mainline/tests/general/test_basic/test_workflow_limit_default_stdout.gold.txt
  7. 1 1
      mainline/tests/general/test_basic/test_workflow_limit_second_stderr.gold.txt
  8. 2 0
      mainline/tests/general/test_basic/test_workflow_limit_second_stdout.gold.txt
  9. 1 1
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_all_stderr.gold.txt
  10. 2 0
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_all_stdout.gold.txt
  11. 1 1
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_new_stderr.gold.txt
  12. 2 0
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_new_stdout.gold.txt
  13. 1 1
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_touched_stderr.gold.txt
  14. 2 0
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_touched_stdout.gold.txt
  15. 1 1
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_trend_stderr.gold.txt
  16. 2 0
      mainline/tests/general/test_basic/test_workflow_limit_second_warn_trend_stdout.gold.txt
  17. 2 0
      mainline/tests/general/test_std_code_cpp/test_parser_limit_default_stdout.gold.txt
  18. 2 0
      mainline/tests/general/test_std_code_cs/test_parser_limit_default_stdout.gold.txt
  19. 2 0
      mainline/tests/general/test_std_code_java/test_parser_limit_default_stdout.gold.txt
  20. 2 0
      mainline/tests/general/test_std_suppress/test_basic_limit_1_stdout.gold.txt
  21. 2 0
      mainline/tests/general/test_std_suppress/test_basic_limit_2_stdout.gold.txt
  22. 2 0
      mainline/tests/general/test_std_suppress/test_basic_limit_3_stdout.gold.txt
  23. 2 0
      mainline/tests/general/test_std_suppress/test_basic_limit_4_stdout.gold.txt
  24. 4 0
      mainline/tests/general/test_std_suppress/test_basic_limit_5_stdout.gold.txt
  25. 2 0
      mainline/tests/general/test_std_suppress/test_basic_limit_size_nosup_stdout.gold.txt
  26. 2 0
      mainline/tests/general/test_std_suppress/test_basic_limit_size_stdout.gold.txt
  27. 1 1
      mainline/tests/system/test_boost_parts/test_workflow_limit_default_stderr.gold.txt
  28. 2 0
      mainline/tests/system/test_boost_parts/test_workflow_limit_default_stdout.gold.txt
  29. 1 1
      mainline/tests/system/test_boost_parts/test_workflow_limit_second_new_stderr.gold.txt
  30. 2 0
      mainline/tests/system/test_boost_parts/test_workflow_limit_second_new_stdout.gold.txt
  31. 1 1
      mainline/tests/system/test_boost_parts/test_workflow_limit_second_touched_stderr.gold.txt
  32. 2 0
      mainline/tests/system/test_boost_parts/test_workflow_limit_second_touched_stdout.gold.txt
  33. 1 1
      mainline/tests/system/test_boost_parts/test_workflow_limit_second_trend_stderr.gold.txt
  34. 2 0
      mainline/tests/system/test_boost_parts/test_workflow_limit_second_trend_stdout.gold.txt

+ 10 - 4
mainline/ext/std/tools/limit.py

@@ -76,15 +76,16 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.IRunable):
             self.parser.error("option --warn-mode: The mode '" + options.__dict__['warn_mode'] + "' requires '--db-file-prev' option set")
 
         class Limit(object):
-            def __init__(self, limit_type, limit, namespace, field, db_filter):
+            def __init__(self, limit_type, limit, namespace, field, db_filter, original):
                 self.type = limit_type
                 self.limit = limit
                 self.namespace = namespace
                 self.field = field
                 self.filter = db_filter
+                self.original = original
                 
             def __repr__(self):
-                return "namespace '" + self.namespace + "', filter '" + str(self.filter) + "'"
+                return "'{0}:{1}' {2} {3}".format(self.namespace, self.field, self.filter[1], self.limit)
         
         self.limits = []
         pattern = re.compile(r'''([^:]+)[:]([^:]+)[:]([-+]?[0-9]+(?:[.][0-9]+)?)''')
@@ -93,14 +94,14 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.IRunable):
                 match = re.match(pattern, each)
                 if match == None:
                     self.parser.error("option --max-limit: Invalid format: " + each)
-                limit = Limit("max", float(match.group(3)), match.group(1), match.group(2), (match.group(2), '>', float(match.group(3))))
+                limit = Limit("max", float(match.group(3)), match.group(1), match.group(2), (match.group(2), '>', float(match.group(3))), each)
                 self.limits.append(limit)
         if options.__dict__['min_limit'] != None:
             for each in options.__dict__['min_limit']:  
                 match = re.match(pattern, each)
                 if match == None:
                     self.parser.error("option --min-limit: Invalid format: " + each)
-                limit = Limit("min", float(match.group(3)), match.group(1), match.group(2), (match.group(2), '<', float(match.group(3))))
+                limit = Limit("min", float(match.group(3)), match.group(1), match.group(2), (match.group(2), '<', float(match.group(3))), each)
                 self.limits.append(limit)
 
     def initialize(self):
@@ -173,6 +174,7 @@ def main(plugin, args):
         path = mpp.utils.preprocess_path(path)
         
         for limit in plugin.iterate_limits():
+            warns_count = 0
             logging.info("Applying limit: " + str(limit))
             filters = [limit.filter]
             if modified_file_ids != None:
@@ -232,6 +234,7 @@ def main(plugin, args):
                 if is_sup == True and plugin.no_suppress == False:
                     continue    
                 
+                warns_count += 1
                 exit_code += 1
                 region_cursor = 0
                 region_name = None
@@ -250,6 +253,9 @@ def main(plugin, args):
                                   is_sup)
                 if limit_warnings != None:
                     limit_warnings -= 1
+                    
+            mpp.cout.notify(path, None, mpp.cout.SEVERITY_INFO, "{0} regions exceeded the limit {1}".format(warns_count, str(limit)))
+
     return exit_code
 
 

+ 1 - 1
mainline/mpp/cout.py

@@ -23,7 +23,7 @@ SEVERITY_ERROR   = 0x03
 DETAILS_OFFSET   = 15
 
 def notify(path, cursor, level, message, details = [], indent = 0):
-    notification = (".   " * indent) + path + ":" + str(cursor) + ": "
+    notification = (".   " * indent) + path + ":" + (str(cursor) if cursor != None else "") + ": "
     if level == SEVERITY_INFO:
         notification += "info: "
     elif level == SEVERITY_WARNING:

+ 1 - 1
mainline/mpp/utils.py

@@ -117,7 +117,7 @@ def serialize_to_python(data, root_name = None):
     prefix = ""
     postfix = ""
     if root_name != None:
-        prefix = "{'" + root_name + ": " 
+        prefix = "{'" + root_name + "': " 
         postfix = "}"
     return prefix + data.__repr__() + postfix
 

+ 1 - 1
mainline/tests/general/test_basic/test_view_format_view_python_stdout.gold.txt

@@ -1 +1 @@
-{'view': [{'data: {'info': {'path': './', 'id': 1}, 'file-data': {}, 'subfiles': [u'file_deleted_in_new_sources.cpp', u'simple.cpp'], 'subdirs': [], 'aggregated-data': {'std.code.complexity': {'cyclomatic': {'nonzero': False, 'count': 8, 'avg': 1.375, 'min': 1, 'max': 3, 'distribution-bars': [{'count': 6, 'ratio': 0.75, 'metric': '1'}, {'count': 1, 'ratio': 0.125, 'metric': '2'}, {'count': 1, 'ratio': 0.125, 'metric': '3'}], 'sup': 0, 'total': 11.0}}}}}]}
+{'view': [{'data': {'info': {'path': './', 'id': 1}, 'file-data': {}, 'subfiles': [u'file_deleted_in_new_sources.cpp', u'simple.cpp'], 'subdirs': [], 'aggregated-data': {'std.code.complexity': {'cyclomatic': {'nonzero': False, 'count': 8, 'avg': 1.375, 'min': 1, 'max': 3, 'distribution-bars': [{'count': 6, 'ratio': 0.75, 'metric': '1'}, {'count': 1, 'ratio': 0.125, 'metric': '2'}, {'count': 1, 'ratio': 0.125, 'metric': '3'}], 'sup': 0, 'total': 11.0}}}}}]}

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_default_stderr.gold.txt

@@ -1,4 +1,4 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 0.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 8

+ 2 - 0
mainline/tests/general/test_basic/test_workflow_limit_default_stdout.gold.txt

@@ -70,3 +70,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 8 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_second_stderr.gold.txt

@@ -1,4 +1,4 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 0.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 6

+ 2 - 0
mainline/tests/general/test_basic/test_workflow_limit_second_stdout.gold.txt

@@ -52,3 +52,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 6 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_second_warn_all_stderr.gold.txt

@@ -1,4 +1,4 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 0.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 6

+ 2 - 0
mainline/tests/general/test_basic/test_workflow_limit_second_warn_all_stdout.gold.txt

@@ -52,3 +52,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 6 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_second_warn_new_stderr.gold.txt

@@ -1,5 +1,5 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Identifying changed files...
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 0.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 2

+ 2 - 0
mainline/tests/general/test_basic/test_workflow_limit_second_warn_new_stdout.gold.txt

@@ -16,3 +16,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 2 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_second_warn_touched_stderr.gold.txt

@@ -1,5 +1,5 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Identifying changed files...
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 0.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 4

+ 2 - 0
mainline/tests/general/test_basic/test_workflow_limit_second_warn_touched_stdout.gold.txt

@@ -34,3 +34,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 4 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 1 - 1
mainline/tests/general/test_basic/test_workflow_limit_second_warn_trend_stderr.gold.txt

@@ -1,5 +1,5 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Identifying changed files...
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 0.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 0.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 3

+ 2 - 0
mainline/tests/general/test_basic/test_workflow_limit_second_warn_trend_stdout.gold.txt

@@ -25,3 +25,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 3 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

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

@@ -106,3 +106,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 12 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_code_cs/test_parser_limit_default_stdout.gold.txt

@@ -142,3 +142,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 16 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_code_java/test_parser_limit_default_stdout.gold.txt

@@ -52,3 +52,5 @@
 	Limit          : 5.0
 	Suppressed     : False
 
+./:: info: 6 regions exceeded the limit 'std.code.complexity:cyclomatic' > 5.0
+

+ 2 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_1_stdout.gold.txt

@@ -7,3 +7,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 1 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_2_stdout.gold.txt

@@ -70,3 +70,5 @@
 	Limit          : 0.0
 	Suppressed     : True
 
+./:: info: 8 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_3_stdout.gold.txt

@@ -61,3 +61,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 7 regions exceeded the limit 'std.code.length:total' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_4_stdout.gold.txt

@@ -232,3 +232,5 @@
 	Limit          : 0.0
 	Suppressed     : True
 
+./:: info: 26 regions exceeded the limit 'std.code.length:total' > 0.0
+

+ 4 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_5_stdout.gold.txt

@@ -7,6 +7,8 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 1 regions exceeded the limit 'std.code.complexity:cyclomatic' > 0.0
+
 ./test.c:56: warning: Metric 'std.code.length:total' for region 'no_suppress_cl' exceeds the limit.
 	Metric name    : std.code.length:total
 	Region name    : no_suppress_cl
@@ -70,3 +72,5 @@
 	Limit          : 0.0
 	Suppressed     : False
 
+./:: info: 7 regions exceeded the limit 'std.code.length:total' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_size_nosup_stdout.gold.txt

@@ -7,3 +7,5 @@
 	Limit          : 0.0
 	Suppressed     : True
 
+./:: info: 1 regions exceeded the limit 'std.general:size' > 0.0
+

+ 2 - 0
mainline/tests/general/test_std_suppress/test_basic_limit_size_stdout.gold.txt

@@ -0,0 +1,2 @@
+./:: info: 0 regions exceeded the limit 'std.general:size' > 0.0
+

+ 1 - 1
mainline/tests/system/test_boost_parts/test_workflow_limit_default_stderr.gold.txt

@@ -1,4 +1,4 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 15.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 15.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 3

+ 2 - 0
mainline/tests/system/test_boost_parts/test_workflow_limit_default_stdout.gold.txt

@@ -25,3 +25,5 @@
 	Limit          : 15.0
 	Suppressed     : False
 
+./:: info: 3 regions exceeded the limit 'std.code.complexity:cyclomatic' > 15.0
+

+ 1 - 1
mainline/tests/system/test_boost_parts/test_workflow_limit_second_new_stderr.gold.txt

@@ -1,5 +1,5 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Identifying changed files...
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 15.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 15.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 2 - 0
mainline/tests/system/test_boost_parts/test_workflow_limit_second_new_stdout.gold.txt

@@ -0,0 +1,2 @@
+./:: info: 0 regions exceeded the limit 'std.code.complexity:cyclomatic' > 15.0
+

+ 1 - 1
mainline/tests/system/test_boost_parts/test_workflow_limit_second_touched_stderr.gold.txt

@@ -1,5 +1,5 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Identifying changed files...
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 15.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 15.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 6

+ 2 - 0
mainline/tests/system/test_boost_parts/test_workflow_limit_second_touched_stdout.gold.txt

@@ -52,3 +52,5 @@
 	Limit          : 15.0
 	Suppressed     : False
 
+./:: info: 6 regions exceeded the limit 'std.code.complexity:cyclomatic' > 15.0
+

+ 1 - 1
mainline/tests/system/test_boost_parts/test_workflow_limit_second_trend_stderr.gold.txt

@@ -1,5 +1,5 @@
 [LOG]: WARNING:	Logging enabled with INFO level
 [LOG]: INFO:	Identifying changed files...
 [LOG]: INFO:	Processing: ./
-[LOG]: INFO:	Applying limit: namespace 'std.code.complexity', filter '('cyclomatic', '>', 15.0)'
+[LOG]: INFO:	Applying limit: 'std.code.complexity:cyclomatic' > 15.0
 [LOG]: WARNING:	Done (1 seconds). Exit code: 2

+ 2 - 0
mainline/tests/system/test_boost_parts/test_workflow_limit_second_trend_stdout.gold.txt

@@ -16,3 +16,5 @@
 	Limit          : 15.0
 	Suppressed     : False
 
+./:: info: 2 regions exceeded the limit 'std.code.complexity:cyclomatic' > 15.0
+