Skip to content

Commit ed19ca7

Browse files
committed
tests added
1 parent 0406363 commit ed19ca7

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

analyzer/codechecker_analyzer/analyzers/clangsa/analyzer.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,14 @@ def __add_plugin_load_flags(cls, analyzer_cmd: List[str]):
186186
for plugin in ClangSA.analyzer_plugins():
187187
analyzer_cmd.extend(["-load", plugin])
188188

189+
@staticmethod
190+
def parse_version(version_txt) -> Optional[Version]:
191+
"""
192+
Parse the version string of the analyzer.
193+
"""
194+
version_txt = version_txt.strip().removesuffix("git")
195+
return Version.parse(version_txt)
196+
189197
@classmethod
190198
def get_binary_version(cls) -> Optional[Version]:
191199
# No need to LOG here, we will emit a warning later anyway.
@@ -203,8 +211,7 @@ def get_binary_version(cls) -> Optional[Version]:
203211
universal_newlines=True,
204212
encoding="utf-8",
205213
errors="ignore")
206-
version_txt=output.strip().removesuffix("git")
207-
return Version.parse(version_txt)
214+
return ClangSA.parse_version(output)
208215
except (subprocess.CalledProcessError, OSError) as oerr:
209216
LOG.warning("Failed to get analyzer version: %s",
210217
' '.join(version))
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# -------------------------------------------------------------------------
2+
#
3+
# Part of the CodeChecker project, under the Apache License v2.0 with
4+
# LLVM Exceptions. See LICENSE for license information.
5+
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
#
7+
# -------------------------------------------------------------------------
8+
9+
""" Test Clang version parsing. """
10+
11+
12+
from semver.version import Version
13+
import unittest
14+
15+
from codechecker_analyzer.analyzers.clangsa.analyzer import ClangSA
16+
17+
18+
class ClangsaVersionTest(unittest.TestCase):
19+
"""
20+
Test the parsing of various possible version strings, which clang
21+
binaries can produce.
22+
"""
23+
24+
def test_clangsa_version(self):
25+
self.assertEqual(
26+
ClangSA.parse_version('18.1.3'),
27+
Version(18, 1, 3))
28+
self.assertEqual(
29+
ClangSA.parse_version('22.0.0git'),
30+
Version(22, 0, 0))

0 commit comments

Comments
 (0)