浏览代码

some TODOs done

avkonst 11 年之前
父节点
当前提交
bfc4d432c4

+ 1 - 1
mainline/doc/home.html

@@ -410,7 +410,7 @@ file: __global__: comment
             <h1>Create plugin</h1>
           </div>
           <h2>New metric</h2>
-          <p>...</p>
+          <p>describe METRIXPLUSPLUS_PATH environment variable</p>
           <h2>New language</h2>
           <p>...</p>
           <h2>New analysis tool</h2>

+ 6 - 4
mainline/ext/std/tools/collect.py

@@ -46,13 +46,17 @@ class Plugin(mpp.api.Plugin, mpp.api.Parent, mpp.api.IConfigurable, mpp.api.IRun
                          help="Defines the pattern to exclude files from processing [default: %default]")
         parser.add_option("--non-recursively", "--nr", action="store_true", default=False,
                          help="If the option is set (True), sub-directories are not processed [default: %default]")
+        self.optparser = parser
     
     def configure(self, options):
-        self.non_recursively = options.__dict__['non_recursively']
-        self.add_exclude_rule(re.compile(options.__dict__['exclude_files']))
         self.is_proctime_enabled = options.__dict__['std.general.proctime']
         self.is_procerrors_enabled = options.__dict__['std.general.procerrors']
         self.is_size_enabled = options.__dict__['std.general.size']
+        try:
+            self.add_exclude_rule(re.compile(options.__dict__['exclude_files']))
+        except Exception as e:
+            self.optparser.error("option --exclude-files: " + str(e))
+        self.non_recursively = options.__dict__['non_recursively']
 
     def initialize(self):
         fields = []
@@ -83,8 +87,6 @@ class Plugin(mpp.api.Plugin, mpp.api.Parent, mpp.api.IConfigurable, mpp.api.IRun
         return None
 
     def add_exclude_rule(self, re_compiled_pattern):
-        # TODO file name may have special regexp symbols what causes an exception
-        # For example try to run a collection with "--db-file=metrix++" option
         self.exclude_rules.append(re_compiled_pattern)
 
     def add_exclude_file(self, file_path):

+ 4 - 2
mainline/ext/std/tools/debug.py

@@ -22,6 +22,7 @@ import logging
 import cgi
 
 import mpp.api
+import mpp.utils
 
 class Plugin(mpp.api.Plugin, mpp.api.IConfigurable, mpp.api.IRunable):
     
@@ -63,7 +64,9 @@ def dumphtml(args, loader):
         
         result += '<table><tr><td><pre>'
         last_pos = 0
-        for marker in data.iterate_markers():
+        for marker in data.iterate_markers(filter_group= mpp.api.Marker.T.COMMENT |
+                                           mpp.api.Marker.T.STRING |
+                                           mpp.api.Marker.T.PREPROCESSOR):
             result += (cgi.escape(text[last_pos:marker.begin]))
             if marker.get_type() == data.get_marker_types().STRING:
                 result += ('<span style="color:#0000FF">')
@@ -72,7 +75,6 @@ def dumphtml(args, loader):
             elif marker.get_type() == data.get_marker_types().PREPROCESSOR:
                 result += ('<span style="color:#990000">')
             else:
-                # TODO add tests for debug tool
                 assert False, "Uknown marker type"
             result += (cgi.escape(text[marker.begin:marker.end]))
             result += ('</span>')

+ 0 - 1
mainline/metrixpp.py

@@ -46,7 +46,6 @@ def main():
 
     loader = mpp.internal.loader.Loader()
     mpp_paths = []
-    # TODO document this feature
     if 'METRIXPLUSPLUS_PATH' in os.environ.keys():
         mpp_paths = os.environ['METRIXPLUSPLUS_PATH'].split(os.pathsep)
     args = loader.load(command, mpp_paths, sys.argv[3:])

+ 9 - 8
mainline/mpp/api.py

@@ -316,8 +316,7 @@ class FileData(LoadableData):
         self.markers.append(Marker(offset_begin, offset_end, group))
         self.loader.db.create_marker(self.file_id, offset_begin, offset_end, group)
         
-    def iterate_markers(self, filter_group = Marker.T.COMMENT |
-                         Marker.T.STRING | Marker.T.PREPROCESSOR,
+    def iterate_markers(self, filter_group = Marker.T.ANY,
                          region_id = None, exclude_children = True, merge = False):
         self.load_markers()
         
@@ -1088,6 +1087,10 @@ class Plugin(BasePlugin):
                 self.is_updated = self.is_updated or is_created
 
 class SimpleMetricMixin(object):
+
+    class AliasError(Exception):
+        def __init__(self, alias):
+            Exception.__init__(self, "Unknown alias: " + str(alias))
     
     def declare_metric(self, is_active, field,
                        pattern_to_search_or_map_of_patterns,
@@ -1131,8 +1134,11 @@ class SimpleMetricMixin(object):
             
         field_data = self._fields[metric_name]
         text = data.get_content()
-        # TODO raise exception if alias is bad
+        
+        if alias not in field_data[4].keys():
+            raise self.AliasError(alias)
         pattern_to_search = field_data[4][alias]
+        
         for region in data.iterate_regions(filter_group=field_data[5]):
             count = 0
             for marker in data.iterate_markers(
@@ -1168,11 +1174,6 @@ class IParser(object):
 class ICode(object):
     pass
 
-# refactor and remove
-class ITool(object):
-    def run(self, tool_args):
-        raise InterfaceNotImplemented(self)
-
 class CallbackNotImplemented(Exception):
     
     def __init__(self, obj, callback_name):

+ 1 - 4
mainline/mpp/dbf.py

@@ -50,12 +50,9 @@ class Plugin(mpp.api.Plugin, mpp.api.IConfigurable):
         
     def initialize(self):
         
-        # TODO refactor and remove self.get_plugin_loader() != None
-        if self.get_plugin_loader() != None and self.get_plugin_loader().get_action() == 'collect':
+        if self.get_plugin_loader().get_action() == 'collect':
             if os.path.exists(self.dbfile):
                 logging.warn("Removing existing file: " + self.dbfile)
-                # TODO can reuse existing db file to speed up the processing?
-                # TODO add option to choose to remove or to overwrite?
                 try:
                     os.unlink(self.dbfile)
                 except:

+ 3 - 1
mainline/mpp/internal/loader.py

@@ -151,7 +151,9 @@ class Loader(object):
         self.action = command
 
         optparser =mpp.cmdparser.MultiOptionParser(
-            usage="Usage: %prog {command} [options] -- [path 1] ... [path N]".format(command=command))
+            usage="Usage: python %prog --help\n"
+                  "       python %prog {command} --help\n"
+                  "       python %prog {command} [options] -- [path 1] ... [path N]".format(command=command))
 
         for item in self.iterate_plugins():
             if (isinstance(item, mpp.api.IConfigurable)):

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

@@ -225,5 +225,13 @@ class Test(tests.common.TestCase):
         runner = tests.common.ToolRunner('view', ['--format=txt'], prefix='txt')
         self.assertExec(runner.run())
 
+    def test_debug_tool(self):
+
+        runner = tests.common.ToolRunner('collect')
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('debug', dirs_list=['./simple.cpp'])
+        self.assertExec(runner.run())
+
 if __name__ == '__main__':
     unittest.main()

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


+ 103 - 0
mainline/tests/general/test_basic/test_debug_tool_debug_default_stdout.gold.txt

@@ -0,0 +1,103 @@
+<html><body><table><tr><td><pre>
+
+<span style="color:#009900">// Just produce any code in order to test basic workflow</span>
+namespace hmm
+{
+
+class A
+{
+
+	A()
+	{
+		<span style="color:#009900">/* first funtion */</span>
+		this-&gt;m_member = 10;
+		if (a &amp; b)
+		{
+			for (int i = 0; i &lt; 0 &amp;&amp; i &gt; 0; i++)
+			{
+				int a; <span style="color:#009900">// right?</span>
+			}
+		}
+	}
+
+	int func(int param = 5)
+	{
+		class embeded
+		{
+			embeded()
+			{
+				int a = 10;
+				if (true)
+				{
+					<span style="color:#009900">// again crazy</span>
+				}
+			}
+		};
+		if (a);
+	}
+
+	int never(int how_long = 999)
+	{
+		while(true)
+		{
+
+		}
+		return 1;
+	}
+
+	int m_member = 10;
+};
+
+}
+</pre></td><td><pre><span style="background-color:#F0F010"><a href="#line0" id=line"0"></a>
+
+<span style="background-color:#F0F070"><a href="#line4" id=line"4"></a>// Just produce any code in order to test basic workflow
+namespace hmm
+{
+
+<span style="background-color:#F0F0D0"><a href="#line7" id=line"7"></a>class A
+{
+
+	<span style="background-color:#F0F030"><a href="#line10" id=line"10"></a>A()
+	{
+		/* first funtion */
+		this-&gt;m_member = 10;
+		if (a &amp; b)
+		{
+			for (int i = 0; i &lt; 0 &amp;&amp; i &gt; 0; i++)
+			{
+				int a; // right?
+			}
+		}
+	}</span>
+
+	<span style="background-color:#F030F0"><a href="#line23" id=line"23"></a>int func(int param = 5)
+	{
+		<span style="background-color:#F0F090"><a href="#line25" id=line"25"></a>class embeded
+		{
+			<span style="background-color:#F0F0E0"><a href="#line27" id=line"27"></a>embeded()
+			{
+				int a = 10;
+				if (true)
+				{
+					// again crazy
+				}
+			}</span>
+		}</span>;
+		if (a);
+	}</span>
+
+	<span style="background-color:#F0F030"><a href="#line39" id=line"39"></a>int never(int how_long = 999)
+	{
+		while(true)
+		{
+
+		}
+		return 1;
+	}</span>
+
+	int m_member = 10;
+}</span>;
+
+}</span>
+</span></pre></td></tr></table></body></html>

+ 3 - 1
mainline/tests/general/test_basic/test_help_collect_default_stdout.gold.txt

@@ -1,4 +1,6 @@
-Usage: metrix++.py collect [options] -- [path 1] ... [path N]
+Usage: python metrix++.py --help
+       python metrix++.py collect --help
+       python metrix++.py collect [options] -- [path 1] ... [path N]
 
 Options:
   -h, --help            show this help message and exit

+ 3 - 1
mainline/tests/general/test_basic/test_help_export_default_stdout.gold.txt

@@ -1,4 +1,6 @@
-Usage: metrix++.py export [options] -- [path 1] ... [path N]
+Usage: python metrix++.py --help
+       python metrix++.py export --help
+       python metrix++.py export [options] -- [path 1] ... [path N]
 
 Options:
   -h, --help            show this help message and exit

+ 3 - 1
mainline/tests/general/test_basic/test_help_info_default_stdout.gold.txt

@@ -1,4 +1,6 @@
-Usage: metrix++.py info [options] -- [path 1] ... [path N]
+Usage: python metrix++.py --help
+       python metrix++.py info --help
+       python metrix++.py info [options] -- [path 1] ... [path N]
 
 Options:
   -h, --help            show this help message and exit

+ 3 - 1
mainline/tests/general/test_basic/test_help_limit_default_stdout.gold.txt

@@ -1,4 +1,6 @@
-Usage: metrix++.py limit [options] -- [path 1] ... [path N]
+Usage: python metrix++.py --help
+       python metrix++.py limit --help
+       python metrix++.py limit [options] -- [path 1] ... [path N]
 
 Options:
   -h, --help            show this help message and exit

+ 3 - 1
mainline/tests/general/test_basic/test_help_view_default_stdout.gold.txt

@@ -1,4 +1,6 @@
-Usage: metrix++.py view [options] -- [path 1] ... [path N]
+Usage: python metrix++.py --help
+       python metrix++.py view --help
+       python metrix++.py view [options] -- [path 1] ... [path N]
 
 Options:
   -h, --help            show this help message and exit