Skip to content

Commit

Permalink
Merge branch 'logging' of github.com:melexis/warnings-plugin into log…
Browse files Browse the repository at this point in the history
…ging
  • Loading branch information
JokeWaumans committed Dec 5, 2024
2 parents 7e91146 + 2299240 commit 5237cec
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 107 deletions.
52 changes: 52 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# .gitattributes snippet to force users to use same line endings for project.
#
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto

#
# The above will handle all files NOT found below
# https://help.github.com/articles/dealing-with-line-endings/
# https://github.com/Danimoth/gitattributes/blob/master/Web.gitattributes



# These files are text and should be normalized (Convert crlf => lf)
*.php text
*.css text
*.js text
*.json text
*.htm text
*.html text
*.xml text
*.txt text
*.ini text
*.inc text
*.pl text
*.rb text
*.py text
*.scm text
*.sql text
.htaccess text
*.sh text
*.rst text
*.md text

# These files are binary and should be left untouched
# (binary is a macro for -text -diff)
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.7z binary
*.ttf binary
*.pyc binary
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
pip install 'twine>=6.0.1'
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ Polyspace
Coverity
Named groups of the regular expression can be used as variables.
Useful names are: `checker` and `classification`.
The default template is ``Coverity: $checker``.
The default template is ``Coverity: CID $cid: $checker``.

Other
The template should contain ``$description``, which is the default.
Expand Down
4 changes: 2 additions & 2 deletions src/mlx/warnings/regex_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
PYTHON_XMLRUNNER_REGEX = r"(\s*(?P<severity1>ERROR|FAILED) (\[\d+\.\d{3}s\]: \s*(?P<description1>.+)))\n?"
xmlrunner_pattern = re.compile(PYTHON_XMLRUNNER_REGEX)

COVERITY_WARNING_REGEX = r"(?P<path>[\d\w/\\/-_]+\.\w+)(:(?P<line>\d+)(:(?P<column>\d+))?)?: ?CID \d+ \(#(?P<curr>\d+) of (?P<max>\d+)\): (?P<checker>.+): (?P<classification>[\w ]+),.+"
COVERITY_WARNING_REGEX = r"(?P<path>[\w\.\\/\- ]+)(:(?P<line>\d+)(:(?P<column>\d+))?)?: ?CID (?P<cid>\d+) \(#(?P<curr>\d+) of (?P<max>\d+)\): (?P<checker>.+): (?P<classification>[\w ]+),.+"
coverity_pattern = re.compile(COVERITY_WARNING_REGEX)


Expand Down Expand Up @@ -78,7 +78,7 @@ class CoverityChecker(RegexChecker):

def __init__(self, verbose=False):
super().__init__(verbose)
self._cq_description_template = Template('Coverity: $checker')
self._cq_description_template = Template('Coverity: CID $cid: $checker')
self.checkers = {
"unclassified": CoverityClassificationChecker("unclassified", verbose=self.verbose),
"pending": CoverityClassificationChecker("pending", verbose=self.verbose),
Expand Down
32 changes: 26 additions & 6 deletions tests/test_coverity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ def ordered(obj):
return obj


@mock.patch.dict(os.environ, {"MIN_COV_WARNINGS": "1", "MAX_COV_WARNINGS": "2"})
@mock.patch.dict(os.environ, {
"MIN_UNCLASSIFIED": "8", "MAX_UNCLASSIFIED": "8",
"MIN_INTENTIONAL": "1", "MAX_INTENTIONAL": "1",
"MIN_FALSE_POSITIVE": "2", "MAX_FALSE_POSITIVE": "2",
})
class TestCoverityWarnings(TestCase):
def setUp(self):
Finding.fingerprints = {}
Expand Down Expand Up @@ -69,19 +73,35 @@ def test_code_quality_without_config(self):
retval = warnings_wrapper([
'--coverity',
'--code-quality', out_file,
str(TEST_IN_DIR / 'defects.txt'),
str(TEST_IN_DIR / 'coverity_full.txt'),
])
self.assertEqual(8, retval)
self.assertEqual(11, retval)
self.assertTrue(filecmp.cmp(out_file, ref_file))

def test_code_quality_with_config(self):
def test_code_quality_with_config_pass(self):
filename = 'coverity_cq.json'
out_file = str(TEST_OUT_DIR / filename)
ref_file = str(TEST_IN_DIR / filename)
retval = warnings_wrapper([
'--code-quality', out_file,
'--config', str(TEST_IN_DIR / 'config_example_coverity.yml'),
str(TEST_IN_DIR / 'defects.txt'),
str(TEST_IN_DIR / 'coverity_full.txt'),
])
self.assertEqual(3, retval)
self.assertEqual(0, retval)
self.assertTrue(filecmp.cmp(out_file, ref_file))

@mock.patch.dict(os.environ, {
"MIN_UNCLASSIFIED": "11", "MAX_UNCLASSIFIED": "-1",
"MIN_FALSE_POSITIVE": "0", "MAX_FALSE_POSITIVE": "1",
})
def test_code_quality_with_config_fail(self):
filename = 'coverity_cq.json'
out_file = str(TEST_OUT_DIR / filename)
ref_file = str(TEST_IN_DIR / filename)
retval = warnings_wrapper([
'--code-quality', out_file,
'--config', str(TEST_IN_DIR / 'config_example_coverity.yml'),
str(TEST_IN_DIR / 'coverity_full.txt'),
])
self.assertEqual(10, retval) # 8 + 2 not within range 6 and 7
self.assertTrue(filecmp.cmp(out_file, ref_file))
18 changes: 2 additions & 16 deletions tests/test_in/code_quality.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
},
{
"severity": "major",
"description": "Coverity: Coding standard violation (MISRA C-2012 Rule 10.1)",
"description": "Coverity: CID 113396: Coding standard violation (MISRA C-2012 Rule 10.1)",
"location": {
"path": "src/somefile.c",
"positions": {
Expand All @@ -109,20 +109,6 @@
}
}
},
"fingerprint": "bec264a0725556cfe0514b3aa168715c"
},
{
"severity": "major",
"description": "Coverity: Coding standard violation (MISRA C-2012 Rule 10.1)",
"location": {
"path": "src/somefile.c",
"positions": {
"begin": {
"line": 82,
"column": 1
}
}
},
"fingerprint": "37dd4fe77518650ac6d416ea8e2e617f"
"fingerprint": "ed5c5078286a009f221b523e57546983"
}
]
14 changes: 0 additions & 14 deletions tests/test_in/code_quality_format.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,5 @@
}
},
"fingerprint": "bec264a0725556cfe0514b3aa168715c"
},
{
"severity": "major",
"description": "Coverity: Coding standard violation (MISRA C-2012 Rule 10.1)",
"location": {
"path": "src/somefile.c",
"positions": {
"begin": {
"line": 82,
"column": 1
}
}
},
"fingerprint": "37dd4fe77518650ac6d416ea8e2e617f"
}
]
2 changes: 2 additions & 0 deletions tests/test_in/config_cq_description_format.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
},
"coverity": {
"enabled": true,
"cq_default_path": "src/main.c",
"cq_description_template": "Coverity: $checker",
"min": 0,
"max": 0
},
Expand Down
15 changes: 6 additions & 9 deletions tests/test_in/config_example_coverity.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
coverity:
enabled: true
unclassified:
min: $MIN_COV_WARNINGS
max: '$MAX_COV_WARNINGS'
min: $MIN_UNCLASSIFIED
max: '$MAX_UNCLASSIFIED'
intentional:
min: 0
max: -1
bug:
min: 0
max: 0
min: $MIN_INTENTIONAL
max: $MAX_INTENTIONAL
pending:
min: 0
max: 0
false_positive:
min: 0
max: -1
min: $MIN_FALSE_POSITIVE
max: $MAX_FALSE_POSITIVE
sphinx:
enabled: false
doxygen:
Expand Down
Loading

0 comments on commit 5237cec

Please sign in to comment.