Skip to content

Commit 9251255

Browse files
committed
Fix clang-apply-replacements flag detection
1 parent 861b247 commit 9251255

2 files changed

Lines changed: 61 additions & 2 deletions

File tree

analyzer/codechecker_analyzer/analyzers/analyzer_types.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ def is_ignore_conflict_supported():
9393
.get_env_for_bin(
9494
context.replacer_binary),
9595
encoding="utf-8", errors="ignore")
96-
out, _ = proc.communicate()
97-
return '--ignore-insert-conflict' in out
96+
out, err = proc.communicate()
97+
help_output = out + err
98+
return '--ignore-insert-conflict' in help_output
9899

99100

100101
def print_unsupported_analyzers(errored):
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# coding=utf-8
2+
"""
3+
Unit tests for analyzer type helper functions.
4+
"""
5+
6+
from unittest import mock
7+
8+
from codechecker_analyzer.analyzers import analyzer_types
9+
10+
11+
class FakeProcess:
12+
"""Fake subprocess object for clang-apply-replacements --help."""
13+
14+
def __init__(self, stdout_text, stderr_text):
15+
self._stdout_text = stdout_text
16+
self._stderr_text = stderr_text
17+
18+
def communicate(self):
19+
return self._stdout_text, self._stderr_text
20+
21+
22+
class FakeContext:
23+
"""Fake analyzer context with a configured replacer binary."""
24+
25+
replacer_binary = "clang-apply-replacements"
26+
27+
def get_env_for_bin(self, _binary):
28+
return {}
29+
30+
31+
def test_ignore_insert_conflict_detected_from_stderr():
32+
"""The flag should be detected even if help text is printed to stderr."""
33+
34+
with mock.patch.object(
35+
analyzer_types.analyzer_context,
36+
"get_context",
37+
return_value=FakeContext()
38+
), mock.patch.object(
39+
analyzer_types.subprocess,
40+
"Popen",
41+
return_value=FakeProcess("", "--ignore-insert-conflict")
42+
):
43+
assert analyzer_types.is_ignore_conflict_supported()
44+
45+
46+
def test_ignore_insert_conflict_detected_from_stdout():
47+
"""The flag should still be detected from stdout."""
48+
49+
with mock.patch.object(
50+
analyzer_types.analyzer_context,
51+
"get_context",
52+
return_value=FakeContext()
53+
), mock.patch.object(
54+
analyzer_types.subprocess,
55+
"Popen",
56+
return_value=FakeProcess("--ignore-insert-conflict", "")
57+
):
58+
assert analyzer_types.is_ignore_conflict_supported()

0 commit comments

Comments
 (0)