Skip to content

Commit

Permalink
[fix] Cppcheck premium version check
Browse files Browse the repository at this point in the history
Cppcheck Premium version dumps the version number in the following
format:

Cppcheck Premium 1.2.3

CodeChecker couldn't handle the "Premium" word in the middle.

Fixes Ericsson#4133
  • Loading branch information
bruntib committed Jan 16, 2024
1 parent 168abd8 commit e987011
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def parse_version(cppcheck_output):
"""
Parse cppcheck version output and return the version number.
"""
version_re = re.compile(r'^Cppcheck (?P<version>[\d\.]+)')
version_re = re.compile(r'^Cppcheck(.*?)(?P<version>[\d\.]+)')
match = version_re.match(cppcheck_output)
if match:
return match.group('version')
Expand Down
25 changes: 25 additions & 0 deletions analyzer/tests/unit/test_cppcheck_version_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -------------------------------------------------------------------------
#
# Part of the CodeChecker project, under the Apache License v2.0 with
# LLVM Exceptions. See LICENSE for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
# -------------------------------------------------------------------------

""" Test Cppcheck version parsing. """


import unittest

from codechecker_analyzer.analyzers.cppcheck.analyzer import parse_version


class CppcheckVersionTest(unittest.TestCase):
"""
Test the parsing of various possible version strings, which cppcheck
binaries can produce.
"""

def test_cppcheck_version(self):
self.assertEqual(parse_version('Cppcheck 1.2.3'), '1.2.3')
self.assertEqual(parse_version('Cppcheck Premium 1.2.3'), '1.2.3')

0 comments on commit e987011

Please sign in to comment.