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

added tests for report tool, added recent python versions to be tested

stefan 1 год назад
Родитель
Сommit
a82346b122

+ 20 - 0
metrixpp/tests/general/test_basic.py

@@ -258,6 +258,26 @@ class Test(tests.common.TestCase):
                                          use_prev=True)
         self.assertExec(runner.run())
 
+    def test_report_format(self):
+
+        runner = tests.common.ToolRunner('collect', ['--std.code.complexity.cyclomatic'], save_prev=True)
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('report',
+                                         ['--format=txt', '--max-limit=std.code.complexity:cyclomatic:0'],
+                                         prefix='txt')
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('report',
+                                         ['--format=json', '--max-limit=std.code.complexity:cyclomatic:0'],
+                                         prefix='json')
+        self.assertExec(runner.run())
+
+        runner = tests.common.ToolRunner('report',
+                                         ['--format=doxygen', '--max-limit=std.code.complexity:cyclomatic:0'],
+                                         prefix='dox')
+        self.assertExec(runner.run())
+
     def test_std_general_metrics(self):
 
         runner = tests.common.ToolRunner('collect',

+ 1 - 1
metrixpp/tests/general/test_basic/test_help_--help_default_stdout.gold.txt

@@ -13,4 +13,4 @@ Actions:
   view
 
 Options:
-  -h, --help  show this help message and exit
+  -h, --help  show this help message and exit

+ 0 - 0
metrixpp/tests/general/test_basic/test_report_format_collect_default_stdout.gold.txt


+ 64 - 0
metrixpp/tests/general/test_basic/test_report_format_report_dox_stdout.gold.txt

@@ -0,0 +1,64 @@
+/* this file is autogenerated by metrix++ - changes will be overwritten */
+/*!
+\page metrix_overview Metrix overview
+
+\section metrix_sec Metrix Warnings
+
+Metrix Limits exceeded 8 times.
+
+Warning list: \ref metrix_warnings
+
+# metrix overview
+|              file               | warnings |
+| ------------------------------- | -------: |
+| file_deleted_in_new_sources.cpp |        2 |
+| simple.cpp                      |        6 |
+
+
+\file ./file_deleted_in_new_sources.cpp
+
+# metrix
+| warnings |
+| -------: |
+|        2 |
+
+# region metrix
+|     region     | warnings | std.code.complexity.cyclomatic |
+| -------------- | -------: | ------------------------------ |
+| __global__     |        0 | -                              |
+| \ref hmm       |        0 | -                              |
+| \ref B         |        1 |                              1 |
+| \ref never_old |        1 |                              1 |
+
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref B exceeds the limit. (value: 1 > limit: 0.0)
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref never_old exceeds the limit. (value: 1 > limit: 0.0)
+
+
+\file ./simple.cpp
+
+# metrix
+| warnings |
+| -------: |
+|        6 |
+
+# region metrix
+|                 region                 | warnings | std.code.complexity.cyclomatic |
+| -------------------------------------- | -------: | ------------------------------ |
+| __global__                             |        0 | -                              |
+| \ref hmm                               |        0 | -                              |
+| \ref A                                 |        1 |                              3 |
+| \ref func                              |        1 |                              1 |
+| \ref embeded                           |        2 |                              1 |
+| \ref func_to_be_removed_in_new_sources |        1 |                              2 |
+| \ref never                             |        1 |                              1 |
+
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref A exceeds the limit. (value: 3 > limit: 0.0)
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref func exceeds the limit. (value: 1 > limit: 0.0)
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref embeded exceeds the limit. (value: 1 > limit: 0.0)
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref func_to_be_removed_in_new_sources exceeds the limit. (value: 2 > limit: 0.0)
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref embeded exceeds the limit. (value: 1 > limit: 0.0)
+\xrefitem metrix_warnings "Metrix Warning" "Metrix Warnings" Metric 'std.code.complexity:cyclomatic' for region \ref never exceeds the limit. (value: 1 > limit: 0.0)
+
+
+*/
+

+ 195 - 0
metrixpp/tests/general/test_basic/test_report_format_report_json_stdout.gold.txt

@@ -0,0 +1,195 @@
+{
+    "overview": [
+        {
+            "file": "file_deleted_in_new_sources.cpp",
+            "warnings": "2"
+        },
+        {
+            "file": "simple.cpp",
+            "warnings": "6"
+        }
+    ],
+    "warnings": [
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "B",
+            "type": "max",
+            "level": 1,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "never_old",
+            "type": "max",
+            "level": 1,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "A",
+            "type": "max",
+            "level": 3,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "func",
+            "type": "max",
+            "level": 1,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "embeded",
+            "type": "max",
+            "level": 1,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "func_to_be_removed_in_new_sources",
+            "type": "max",
+            "level": 2,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "embeded",
+            "type": "max",
+            "level": 1,
+            "limit": 0.0
+        },
+        {
+            "metric": "std.code.complexity:cyclomatic",
+            "region": "never",
+            "type": "max",
+            "level": 1,
+            "limit": 0.0
+        }
+    ],
+    "files": {
+        "./file_deleted_in_new_sources.cpp": {
+            "warnings": [
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "B",
+                    "type": "max",
+                    "level": 1,
+                    "limit": 0.0
+                },
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "never_old",
+                    "type": "max",
+                    "level": 1,
+                    "limit": 0.0
+                }
+            ],
+            "regions": {
+                "__global__": {
+                    "region": "__global__",
+                    "warnings": "0",
+                    "std.code.complexity.cyclomatic": "-"
+                },
+                "hmm": {
+                    "region": "hmm",
+                    "warnings": "0",
+                    "std.code.complexity.cyclomatic": "-"
+                },
+                "B": {
+                    "region": "B",
+                    "warnings": "1",
+                    "std.code.complexity.cyclomatic": "1"
+                },
+                "never_old": {
+                    "region": "never_old",
+                    "warnings": "1",
+                    "std.code.complexity.cyclomatic": "1"
+                }
+            }
+        },
+        "./simple.cpp": {
+            "warnings": [
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "A",
+                    "type": "max",
+                    "level": 3,
+                    "limit": 0.0
+                },
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "func",
+                    "type": "max",
+                    "level": 1,
+                    "limit": 0.0
+                },
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "embeded",
+                    "type": "max",
+                    "level": 1,
+                    "limit": 0.0
+                },
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "func_to_be_removed_in_new_sources",
+                    "type": "max",
+                    "level": 2,
+                    "limit": 0.0
+                },
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "embeded",
+                    "type": "max",
+                    "level": 1,
+                    "limit": 0.0
+                },
+                {
+                    "metric": "std.code.complexity:cyclomatic",
+                    "region": "never",
+                    "type": "max",
+                    "level": 1,
+                    "limit": 0.0
+                }
+            ],
+            "regions": {
+                "__global__": {
+                    "region": "__global__",
+                    "warnings": "0",
+                    "std.code.complexity.cyclomatic": "-"
+                },
+                "hmm": {
+                    "region": "hmm",
+                    "warnings": "0",
+                    "std.code.complexity.cyclomatic": "-"
+                },
+                "A": {
+                    "region": "A",
+                    "warnings": "1",
+                    "std.code.complexity.cyclomatic": "3"
+                },
+                "func": {
+                    "region": "func",
+                    "warnings": "1",
+                    "std.code.complexity.cyclomatic": "1"
+                },
+                "embeded": {
+                    "region": "embeded",
+                    "warnings": "2",
+                    "std.code.complexity.cyclomatic": "1"
+                },
+                "func_to_be_removed_in_new_sources": {
+                    "region": "func_to_be_removed_in_new_sources",
+                    "warnings": "1",
+                    "std.code.complexity.cyclomatic": "2"
+                },
+                "never": {
+                    "region": "never",
+                    "warnings": "1",
+                    "std.code.complexity.cyclomatic": "1"
+                }
+            }
+        }
+    }
+}

+ 82 - 0
metrixpp/tests/general/test_basic/test_report_format_report_txt_stdout.gold.txt

@@ -0,0 +1,82 @@
+Overview:
+
+file: file_deleted_in_new_sources.cpp
+warnings: 2
+
+file: simple.cpp
+warnings: 6
+
+Warnings:
+Metric 'std.code.complexity:cyclomatic' for region B exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region never_old exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region A exceeds the limit. (value: 3 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region func exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region embeded exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region func_to_be_removed_in_new_sources exceeds the limit. (value: 2 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region embeded exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region never exceeds the limit. (value: 1 > limit: 0.0)
+
+Files:
+
+./file_deleted_in_new_sources.cpp
+warnings: 2
+
+./file_deleted_in_new_sources.cpp region: __global__
+warnings: 0
+std.code.complexity.cyclomatic: -
+
+./file_deleted_in_new_sources.cpp region: hmm
+warnings: 0
+std.code.complexity.cyclomatic: -
+
+./file_deleted_in_new_sources.cpp region: B
+warnings: 1
+std.code.complexity.cyclomatic: 1
+
+./file_deleted_in_new_sources.cpp region: never_old
+warnings: 1
+std.code.complexity.cyclomatic: 1
+
+Warnings for ./file_deleted_in_new_sources.cpp:
+Metric 'std.code.complexity:cyclomatic' for region B exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region never_old exceeds the limit. (value: 1 > limit: 0.0)
+
+./simple.cpp
+warnings: 6
+
+./simple.cpp region: __global__
+warnings: 0
+std.code.complexity.cyclomatic: -
+
+./simple.cpp region: hmm
+warnings: 0
+std.code.complexity.cyclomatic: -
+
+./simple.cpp region: A
+warnings: 1
+std.code.complexity.cyclomatic: 3
+
+./simple.cpp region: func
+warnings: 1
+std.code.complexity.cyclomatic: 1
+
+./simple.cpp region: embeded
+warnings: 2
+std.code.complexity.cyclomatic: 1
+
+./simple.cpp region: func_to_be_removed_in_new_sources
+warnings: 1
+std.code.complexity.cyclomatic: 2
+
+./simple.cpp region: never
+warnings: 1
+std.code.complexity.cyclomatic: 1
+
+Warnings for ./simple.cpp:
+Metric 'std.code.complexity:cyclomatic' for region A exceeds the limit. (value: 3 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region func exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region embeded exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region func_to_be_removed_in_new_sources exceeds the limit. (value: 2 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region embeded exceeds the limit. (value: 1 > limit: 0.0)
+Metric 'std.code.complexity:cyclomatic' for region never exceeds the limit. (value: 1 > limit: 0.0)
+

+ 1 - 0
requirements.txt

@@ -0,0 +1 @@
+pytablewriter