Parcourir la source

tests for runable api.

avkonst il y a 12 ans
Parent
commit
363c767a41
19 fichiers modifiés avec 361 ajouts et 0 suppressions
  1. 41 0
      mainline/tests/system/test_api_tutorial.py
  2. 18 0
      mainline/tests/system/test_api_tutorial/ext/compare_step1/myext/__init__.py
  3. 27 0
      mainline/tests/system/test_api_tutorial/ext/compare_step1/myext/compare.ini
  4. 27 0
      mainline/tests/system/test_api_tutorial/ext/compare_step1/myext/compare.py
  5. 18 0
      mainline/tests/system/test_api_tutorial/ext/compare_step2/myext/__init__.py
  6. 27 0
      mainline/tests/system/test_api_tutorial/ext/compare_step2/myext/compare.ini
  7. 49 0
      mainline/tests/system/test_api_tutorial/ext/compare_step2/myext/compare.py
  8. 18 0
      mainline/tests/system/test_api_tutorial/ext/compare_step3/myext/__init__.py
  9. 27 0
      mainline/tests/system/test_api_tutorial/ext/compare_step3/myext/compare.ini
  10. 62 0
      mainline/tests/system/test_api_tutorial/ext/compare_step3/myext/compare.py
  11. 35 0
      mainline/tests/system/test_api_tutorial/sources_changed/test.cpp
  12. 3 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_default_stderr.gold.txt
  13. 0 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_default_stdout.gold.txt
  14. 3 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_second_stderr.gold.txt
  15. 0 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_second_stdout.gold.txt
  16. 2 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step1_stderr.gold.txt
  17. 1 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step1_stdout.gold.txt
  18. 2 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step2_stderr.gold.txt
  19. 1 0
      mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step2_stdout.gold.txt

+ 41 - 0
mainline/tests/system/test_api_tutorial.py

@@ -61,6 +61,47 @@ class Test(tests.common.TestCase):
         if METRIXPLUSPLUS_PATH != None:
             os.environ['METRIXPLUSPLUS_PATH'] = METRIXPLUSPLUS_PATH
 
+    def test_runable_plugin_api(self):
+        
+        #
+        # WARNING:
+        # files generated by this test are used by project documents page
+        # so, if the test is changed, html docs should be updated accordingly
+        #
+        METRIXPLUSPLUS_PATH = None
+        if 'METRIXPLUSPLUS_PATH' in os.environ.keys():
+            METRIXPLUSPLUS_PATH = os.environ['METRIXPLUSPLUS_PATH']
+        
+        runner = tests.common.ToolRunner('collect',
+                                         ['--std.code.lines.total',
+                                          '--log-level=INFO'],
+                                         check_stderr=[(0, -1)],
+                                         save_prev=True)
+        self.assertExec(runner.run())
+        
+        runner = tests.common.ToolRunner('collect',
+                                         ['--std.code.lines.total',
+                                          '--log-level=INFO'],
+                                         check_stderr=[(0, -1)],
+                                         prefix='second',
+                                         cwd="sources_changed",
+                                         use_prev=True)
+        self.assertExec(runner.run())
+        
+        for step in range(2):
+            step = step + 1
+            os.environ['METRIXPLUSPLUS_PATH'] = os.path.join(os.path.dirname(os.path.abspath(__file__)),
+                                                             'test_api_tutorial', 'ext', 'compare_step' + str(step))
+            runner = tests.common.ToolRunner('compare',
+                                             ['--log-level=INFO'],
+                                             prefix='step' + str(step),
+                                             check_stderr=[(0, -1)],
+                                             use_prev=True)
+            self.assertExec(runner.run())
+
+        if METRIXPLUSPLUS_PATH != None:
+            os.environ['METRIXPLUSPLUS_PATH'] = METRIXPLUSPLUS_PATH
+
 if __name__ == '__main__':
     unittest.main()
     

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step1/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    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/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step1/myext/compare.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: myext
+module:  compare
+class:   Plugin
+depends: mpp.dbf
+actions: compare
+enabled: True

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step1/myext/compare.py

@@ -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/>.
+#
+
+import mpp.api
+
+class Plugin(mpp.api.Plugin, mpp.api.IRunable):
+    
+    def run(self, args):
+        print args
+        return 0
+

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step2/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    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/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step2/myext/compare.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: myext
+module:  compare
+class:   Plugin
+depends: mpp.dbf
+actions: compare
+enabled: True

+ 49 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step2/myext/compare.py

@@ -0,0 +1,49 @@
+#
+#    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
+# load common utils for post processing tools
+import mpp.utils
+
+class Plugin(mpp.api.Plugin, mpp.api.IRunable):
+    
+    def run(self, args):
+        # get data file reader using standard metrix++ plugin
+        loader = self.get_plugin('mpp.dbf').get_loader()
+        
+        # configure default paths if there are no paths specified
+        # in command line
+        paths = None
+        if len(args) == 0:
+            paths = [""]
+        else:
+            paths = args
+
+        # iterate and print files for every path in paths
+        exit_code = 0
+        for path in paths:
+            file_iterator = loader.iterate_file_data(path)
+            if file_iterator == None:
+                mpp.utils.report_bad_path(path)
+                exit_code += 1
+                continue
+            for file_data in file_iterator:
+                print file_data.get_path(), file_data.get_checksum()
+        return exit_code
+

+ 18 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step3/myext/__init__.py

@@ -0,0 +1,18 @@
+#
+#    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/>.
+#

+ 27 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step3/myext/compare.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: myext
+module:  compare
+class:   Plugin
+depends: mpp.dbf
+actions: compare
+enabled: True

+ 62 - 0
mainline/tests/system/test_api_tutorial/ext/compare_step3/myext/compare.py

@@ -0,0 +1,62 @@
+#
+#    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 mpp.utils
+# load standard routines to print to stdout
+import mpp.cout
+
+class Plugin(mpp.api.Plugin, mpp.api.IRunable):
+    
+    def run(self, args):
+        loader = self.get_plugin('mpp.dbf').get_loader()
+        # get previous db file loader
+        loader_prev = self.get_plugin('mpp.dbf').get_loader_prev()
+        
+        paths = None
+        if len(args) == 0:
+            paths = [""]
+        else:
+            paths = args
+
+        exit_code = 0
+        for path in paths:
+            file_iterator = loader.iterate_file_data(path)
+            if file_iterator == None:
+                mpp.utils.report_bad_path(path)
+                exit_code += 1
+                continue
+            for file_data in file_iterator:
+                # compare here with previous and notify about changes
+                file_data_prev = loader_prev.load_file_data(file_data.get_path())
+                if file_data_prev == None:
+                    mpp.cout.notify(file_data.get_path(), '', mpp.cout.SEVERITY_INFO,
+                                    'File has been added',
+                                    [('Checksum', file_data.get_checksum())])
+                elif file_data.get_checksum() != file_data_prev.get_checksum():
+                    mpp.cout.notify(file_data.get_path(), '', mpp.cout.SEVERITY_INFO,
+                                    'File has been changed',
+                                    [('New checksum', file_data.get_checksum()),
+                                     ('Old checksum', file_data_prev.get_checksum())])
+                else:
+                    mpp.cout.notify(file_data.get_path(), '', mpp.cout.SEVERITY_INFO,
+                                    'File has not been changed',
+                                    [('Checksum', file_data.get_checksum())])
+        return exit_code
+

+ 35 - 0
mainline/tests/system/test_api_tutorial/sources_changed/test.cpp

@@ -0,0 +1,35 @@
+
+
+const unsigned int c = 3;
+unsigned int c = 3;
+int c = 3;
+
+
+int main(int a = 1, int b = -2)
+{
+	const unsigned int c = 3;
+
+	for (int i = 0; i < 100; ++i)
+	{
+		// modified
+	}
+	while (1)
+	{
+		a = 4;
+	}
+}
+
+int simple_func()
+{
+	const unsigned int c = c;
+}
+
+int added()
+{
+
+}
+
+int added2()
+{
+
+}

+ 3 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_default_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 0 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_default_stdout.gold.txt


+ 3 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_second_stderr.gold.txt

@@ -0,0 +1,3 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: INFO:	Processing: ./test.cpp
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 0 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_collect_second_stdout.gold.txt


+ 2 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step1_stderr.gold.txt

@@ -0,0 +1,2 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 1 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step1_stdout.gold.txt

@@ -0,0 +1 @@
+[]

+ 2 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step2_stderr.gold.txt

@@ -0,0 +1,2 @@
+[LOG]: WARNING:	Logging enabled with INFO level
+[LOG]: WARNING:	Done (1 seconds). Exit code: 0

+ 1 - 0
mainline/tests/system/test_api_tutorial/test_runable_plugin_api_compare_step2_stdout.gold.txt

@@ -0,0 +1 @@
+./test.cpp 579671338