Просмотр исходного кода

preliminary version of todo marker counter

avkonst 12 лет назад
Родитель
Сommit
0aa4f46f9e
18 измененных файлов с 367 добавлено и 0 удалено
  1. 4 0
      mainline/CHANGELOG.md
  2. 27 0
      mainline/ext/std/code/todo.ini
  3. 67 0
      mainline/ext/std/code/todo.py
  4. 9 0
      mainline/tests/general/test_basic/test_help_collect_default_stdout.gold.txt
  5. 2 0
      mainline/tests/general/test_basic/test_workflow_info_default_stdout.gold.txt
  6. 2 0
      mainline/tests/general/test_basic/test_workflow_info_second_stdout.gold.txt
  7. 69 0
      mainline/tests/general/test_std_code_todo.py
  8. 16 0
      mainline/tests/general/test_std_code_todo/sources/test.cpp
  9. 33 0
      mainline/tests/general/test_std_code_todo/sources/test.cs
  10. 0 0
      mainline/tests/general/test_std_code_todo/test_comments_collect_default_stdout.gold.txt
  11. 57 0
      mainline/tests/general/test_std_code_todo/test_comments_view_files_stdout.gold.txt
  12. 0 0
      mainline/tests/general/test_std_code_todo/test_strings_collect_default_stdout.gold.txt
  13. 52 0
      mainline/tests/general/test_std_code_todo/test_strings_view_files_stdout.gold.txt
  14. 6 0
      mainline/tests/general/test_std_code_todo/test_tags_collect_badtag_stderr.gold.txt
  15. 0 0
      mainline/tests/general/test_std_code_todo/test_tags_collect_badtag_stdout.gold.txt
  16. 0 0
      mainline/tests/general/test_std_code_todo/test_tags_collect_default_stdout.gold.txt
  17. 21 0
      mainline/tests/general/test_std_code_todo/test_tags_view_default_stdout.gold.txt
  18. 2 0
      mainline/tests/system/test_boost_parts/test_workflow_info_default_stdout.gold.txt

+ 4 - 0
mainline/CHANGELOG.md

@@ -1,3 +1,7 @@
+## 1.3 (August, 2013)
+- Deprecated and dropped support for callback based implementation of advanced counters
+(use MetricPluginMixin.*Counter classes instead)
+
 ## 1.2 (August, 2013)
 - **Feature** suppressions capability for limit tool
 - **Feature** distribution tables and graphs in viewer

+ 27 - 0
mainline/ext/std/code/todo.ini

@@ -0,0 +1,27 @@
+;
+;    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/>.
+;
+
+[Plugin]
+version: 1.0
+package: std.code
+module:  todo
+class:   Plugin
+depends: None
+actions: collect
+enabled: True

+ 67 - 0
mainline/ext/std/code/todo.py

@@ -0,0 +1,67 @@
+#
+#    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 mpp.api
+import re
+
+class Plugin(mpp.api.Plugin,
+             mpp.api.IConfigurable,
+             mpp.api.Child,
+             mpp.api.MetricPluginMixin):
+    
+    def declare_configuration(self, parser):
+        self.parser = parser
+        parser.add_option("--std.code.todo.comments", "--sctc",
+            action="store_true", default=False,
+            help="Enables collection of number of todo/fixme/etc markers in comments [default: %default]")
+        parser.add_option("--std.code.todo.strings", "--scts",
+            action="store_true", default=False,
+            help="Enables collection of number of todo/fixme/etc markers in strings [default: %default]")
+        parser.add_option("--std.code.todo.tags", "--sctt", type=str,
+            default="TODO,ToDo,FIXME,FixMe,TBD,HACK,XXX",
+            help="A list of typical todo markers to search, separated by comma [default: %default]")
+    
+    def configure(self, options):
+        self.is_active_comments = options.__dict__['std.code.todo.comments']
+        self.is_active_strings = options.__dict__['std.code.todo.strings']
+        self.tags_list = options.__dict__['std.code.todo.tags'].split(',')
+        self.tags_list.sort()
+        for tag in self.tags_list:
+            if re.match(r'''^[A-Za-z0-9]+$''', tag) == None:
+                self.parser.error('option --std.code.todo.tags: tag {0} includes not allowed symbols'.
+                                  format(tag))
+        self.pattern_to_search = re.compile('[^a-zA-Z]{0}[^a-zA-Z]'.format('|'.join(self.tags_list)))
+
+    def initialize(self):
+        self.declare_metric(self.is_active_comments,
+                            self.Field('comments', int, non_zero=True),
+                            self.pattern_to_search,
+                            marker_type_mask=mpp.api.Marker.T.COMMENT,
+                            region_type_mask=mpp.api.Region.T.ANY)
+        self.declare_metric(self.is_active_strings,
+                            self.Field('strings', int, non_zero=True),
+                            self.pattern_to_search,
+                            marker_type_mask=mpp.api.Marker.T.STRING,
+                            region_type_mask=mpp.api.Region.T.ANY)
+        
+        super(Plugin, self).initialize(fields=self.get_fields(),
+            properties=[self.Property('tags', ','.join(self.tags_list))])
+        
+        if self.is_active() == True:
+            self.subscribe_by_parents_interface(mpp.api.ICode)

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

@@ -56,6 +56,15 @@ Options:
   --std.code.magic.numbers.simplier, --scmns
                         Is set, 0, -1 and 1 numbers are not counted in
                         'std.code.magic.numbers' metric [default: False]
+  --std.code.todo.comments, --sctc
+                        Enables collection of number of todo/fixme/etc markers
+                        in comments [default: False]
+  --std.code.todo.strings, --scts
+                        Enables collection of number of todo/fixme/etc markers
+                        in strings [default: False]
+  --std.code.todo.tags=STD.CODE.TODO.TAGS, --sctt=STD.CODE.TODO.TAGS
+                        A list of typical todo markers to search, separated by
+                        comma [default: TODO,ToDo,FIXME,FixMe,TBD,HACK,XXX]
   --std.suppress, --ss  If set (True), suppression markers are collected from
                         comments in code. Suppressions are used by post-
                         processing tools, like limit, to remove false-positive

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

@@ -10,6 +10,8 @@ test_workflow.db:: info: Created using plugins and settings:
 	std.code.lines:version: 1.1
 	std.code.magic:version: 1.0
 	std.code.magic:number.simplier: False
+	std.code.todo:version: 1.0
+	std.code.todo:tags: FIXME,FixMe,HACK,TBD,TODO,ToDo,XXX
 	std.suppress:version: 1.0
 
 test_workflow.db:: info: Collected metrics:

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

@@ -10,6 +10,8 @@ test_workflow.db:: info: Created using plugins and settings:
 	std.code.lines:version: 1.1
 	std.code.magic:version: 1.0
 	std.code.magic:number.simplier: False
+	std.code.todo:version: 1.0
+	std.code.todo:tags: FIXME,FixMe,HACK,TBD,TODO,ToDo,XXX
 	std.suppress:version: 1.0
 
 test_workflow.db:: info: Collected metrics:

+ 69 - 0
mainline/tests/general/test_std_code_todo.py

@@ -0,0 +1,69 @@
+#
+#    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 Test(tests.common.TestCase):
+
+    def test_comments(self):
+        
+        runner = tests.common.ToolRunner('collect', ['--std.code.todo.comments'])
+        self.assertExec(runner.run())
+
+        dirs_list = [os.path.join('.', each) for each in os.listdir(self.get_content_paths().cwd)]
+        runner = tests.common.ToolRunner('view',
+                                         opts_list=['--nest-regions', '--format=txt'],
+                                         dirs_list=dirs_list,
+                                         prefix='files')
+        self.assertExec(runner.run())
+
+    def test_strings(self):
+        
+        runner = tests.common.ToolRunner('collect', ['--std.code.todo.strings'])
+        self.assertExec(runner.run())
+
+        dirs_list = [os.path.join('.', each) for each in os.listdir(self.get_content_paths().cwd)]
+        runner = tests.common.ToolRunner('view',
+                                         opts_list=['--nest-regions', '--format=txt'],
+                                         dirs_list=dirs_list,
+                                         prefix='files')
+        self.assertExec(runner.run())
+
+    def test_tags(self):
+        
+        runner = tests.common.ToolRunner('collect', ['--sctc', '--scts',
+                                                     '--std.code.todo.tags=FIX-ME,FIXME'],
+                                         exit_code=2,
+                                         prefix='badtag',
+                                         check_stderr=[(0, -1)])
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('collect', ['--sctc', '--scts',
+                                                     '--std.code.todo.tags=TOBEDONE,TODO,FIXME'])
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('view',)
+        self.assertExec(runner.run())
+
+if __name__ == '__main__':
+    unittest.main()

+ 16 - 0
mainline/tests/general/test_std_code_todo/sources/test.cpp

@@ -0,0 +1,16 @@
+
+int main()
+{
+	//TODO marker is here
+	//ToDo
+	//FIXME is here
+	//FixMe is here
+	/*TBD is here*/
+	//HACK is here
+	//XXX is here
+	//All here: TODO,ToDo,FIXME,FixMe,TBD,HACK,XXX
+	// no heretodoss
+	// no heretodo
+	// no todoss
+	//TOBEDONE
+}

+ 33 - 0
mainline/tests/general/test_std_code_todo/sources/test.cs

@@ -0,0 +1,33 @@
+
+class MainClass
+{
+		//TODO marker is here
+		//ToDo
+		//FIXME is here
+		//FixMe is here
+		/*TBD is here*/
+		//HACK is here
+		//XXX is here
+
+	int main()
+	{
+		//TODO marker is here
+		//ToDo
+		//FIXME is here
+		//FixMe is here
+		/*TBD is here*/
+		//HACK is here
+		//XXX is here
+		//All here: TODO,ToDo,FIXME,FixMe,TBD,HACK,XXX
+		// no heretodoss
+		// no heretodo
+		// no todoss
+		//TOBEDONE
+	}
+
+		//All here: TODO,ToDo,FIXME,FixMe,TBD,HACK,XXX
+		// no heretodoss
+		// no heretodo
+		// no todoss
+		//TOBEDONE
+}

+ 0 - 0
mainline/tests/general/test_std_code_todo/test_comments_collect_default_stdout.gold.txt


+ 57 - 0
mainline/tests/general/test_std_code_todo/test_comments_view_files_stdout.gold.txt

@@ -0,0 +1,57 @@
+./test.cpp:0: info: Metrics per '__global__' region
+	Region name    : __global__
+	Region type    : global
+	Offsets        : 0-237
+	Line numbers   : 1-17
+	Modified       : None
+
+.   ./test.cpp:2: info: Metrics per 'main' region
+    	Region name    : main
+    	Region type    : function
+    	Offsets        : 1-236
+    	Line numbers   : 2-16
+    	Modified       : None
+    	std.code.todo:comments: 13
+
+./test.cpp:: info: Overall metrics for 'std.code.todo:comments' metric
+	Average        : 13.0 (excluding zero metric values)
+	Minimum        : 13
+	Maximum        : 13
+	Total          : 13.0
+	Distribution   : 1 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+	            13 : 1.000 : 1.000 : 1	||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
+./test.cs:0: info: Metrics per '__global__' region
+	Region name    : __global__
+	Region type    : global
+	Offsets        : 0-507
+	Line numbers   : 1-34
+	Modified       : None
+
+.   ./test.cs:2: info: Metrics per 'MainClass' region
+    	Region name    : MainClass
+    	Region type    : class
+    	Offsets        : 1-506
+    	Line numbers   : 2-33
+    	Modified       : None
+    	std.code.todo:comments: 13
+
+.   .   ./test.cs:12: info: Metrics per 'main' region
+        	Region name    : main
+        	Region type    : function
+        	Offsets        : 141-390
+        	Line numbers   : 12-26
+        	Modified       : None
+        	std.code.todo:comments: 13
+
+./test.cs:: info: Overall metrics for 'std.code.todo:comments' metric
+	Average        : 13.0 (excluding zero metric values)
+	Minimum        : 13
+	Maximum        : 13
+	Total          : 26.0
+	Distribution   : 2 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+	            13 : 1.000 : 1.000 : 2	||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
+

+ 0 - 0
mainline/tests/general/test_std_code_todo/test_strings_collect_default_stdout.gold.txt


+ 52 - 0
mainline/tests/general/test_std_code_todo/test_strings_view_files_stdout.gold.txt

@@ -0,0 +1,52 @@
+./test.cpp:0: info: Metrics per '__global__' region
+	Region name    : __global__
+	Region type    : global
+	Offsets        : 0-237
+	Line numbers   : 1-17
+	Modified       : None
+
+.   ./test.cpp:2: info: Metrics per 'main' region
+    	Region name    : main
+    	Region type    : function
+    	Offsets        : 1-236
+    	Line numbers   : 2-16
+    	Modified       : None
+
+./test.cpp:: info: Overall metrics for 'std.code.todo:strings' metric
+	Average        : None (excluding zero metric values)
+	Minimum        : None
+	Maximum        : None
+	Total          : 0.0
+	Distribution   : 0 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+
+./test.cs:0: info: Metrics per '__global__' region
+	Region name    : __global__
+	Region type    : global
+	Offsets        : 0-507
+	Line numbers   : 1-34
+	Modified       : None
+
+.   ./test.cs:2: info: Metrics per 'MainClass' region
+    	Region name    : MainClass
+    	Region type    : class
+    	Offsets        : 1-506
+    	Line numbers   : 2-33
+    	Modified       : None
+
+.   .   ./test.cs:12: info: Metrics per 'main' region
+        	Region name    : main
+        	Region type    : function
+        	Offsets        : 141-390
+        	Line numbers   : 12-26
+        	Modified       : None
+
+./test.cs:: info: Overall metrics for 'std.code.todo:strings' metric
+	Average        : None (excluding zero metric values)
+	Minimum        : None
+	Maximum        : None
+	Total          : 0.0
+	Distribution   : 0 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+
+

+ 6 - 0
mainline/tests/general/test_std_code_todo/test_tags_collect_badtag_stderr.gold.txt

@@ -0,0 +1,6 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+Usage: python metrix++.py --help
+       python metrix++.py collect --help
+       python metrix++.py collect [options] -- [path 1] ... [path N]
+
+metrix++.py: error: option --std.code.todo.tags: tag FIX-ME includes not allowed symbols

+ 0 - 0
mainline/tests/general/test_std_code_todo/test_tags_collect_badtag_stdout.gold.txt


+ 0 - 0
mainline/tests/general/test_std_code_todo/test_tags_collect_default_stdout.gold.txt


+ 21 - 0
mainline/tests/general/test_std_code_todo/test_tags_view_default_stdout.gold.txt

@@ -0,0 +1,21 @@
+:: info: Overall metrics for 'std.code.todo:strings' metric
+	Average        : None (excluding zero metric values)
+	Minimum        : None
+	Maximum        : None
+	Total          : 0.0
+	Distribution   : 0 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+
+:: info: Overall metrics for 'std.code.todo:comments' metric
+	Average        : 5.0 (excluding zero metric values)
+	Minimum        : 5
+	Maximum        : 5
+	Total          : 15.0
+	Distribution   : 3 regions in total (including 0 suppressed)
+	  Metric value : Ratio : R-sum : Number of regions
+	             5 : 1.000 : 1.000 : 3	||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
+
+:: info: Directory content:
+	Directory      : .
+
+

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

@@ -10,6 +10,8 @@ test_workflow.db:: info: Created using plugins and settings:
 	std.code.lines:version: 1.1
 	std.code.magic:version: 1.0
 	std.code.magic:number.simplier: False
+	std.code.todo:version: 1.0
+	std.code.todo:tags: FIXME,FixMe,HACK,TBD,TODO,ToDo,XXX
 
 test_workflow.db:: info: Collected metrics:
 	std.code.complexity:cyclomatic: