|
| 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