Skip to content

Commit 5bbde51

Browse files
authored
fixed #13391 - fixed missing file0 in cached XML results (danmar#7141)
1 parent 0736f0a commit 5bbde51

File tree

3 files changed

+26
-28
lines changed

3 files changed

+26
-28
lines changed

lib/errorlogger.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
170170
const char *attr = errmsg->Attribute("id");
171171
id = attr ? attr : unknown;
172172

173+
attr = errmsg->Attribute("file0");
174+
file0 = attr ? attr : "";
175+
173176
attr = errmsg->Attribute("severity");
174177
severity = attr ? severityFromString(attr) : Severity::none;
175178

test/cli/other_test.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2675,11 +2675,7 @@ def test_duplicate_suppressions_mixed(tmp_path):
26752675
assert stderr == ''
26762676

26772677

2678-
@pytest.mark.xfail(strict=True)
2679-
def test_xml_builddir(tmp_path): # #13391 / #13485
2680-
build_dir = tmp_path / 'b1'
2681-
os.mkdir(build_dir)
2682-
2678+
def test_xml_output(tmp_path): # #13391 / #13485
26832679
test_file = tmp_path / 'test.cpp'
26842680
with open(test_file, 'wt') as f:
26852681
f.write("""
@@ -2690,35 +2686,31 @@ def test_xml_builddir(tmp_path): # #13391 / #13485
26902686
}
26912687
""")
26922688

2689+
_, version_str, _ = cppcheck(['--version'])
2690+
version_str = version_str.replace('Cppcheck ', '').strip()
2691+
26932692
args = [
26942693
'-q',
26952694
'--enable=style',
2696-
'--cppcheck-build-dir={}'.format(build_dir),
26972695
'--xml',
26982696
str(test_file)
26992697
]
27002698
exitcode_1, stdout_1, stderr_1 = cppcheck(args)
27012699
assert exitcode_1 == 0, stdout_1
27022700
assert stdout_1 == ''
2703-
# TODO: handle version
27042701
assert (stderr_1 ==
2705-
'''<?xml version="1.0" encoding="UTF-8"?>
2706-
<results version="2">
2707-
<cppcheck version="2.17 dev"/>
2708-
<errors>
2709-
<error id="nullPointerRedundantCheck" severity="warning" msg="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." verbose="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." cwe="476" file0="{}" remark="boom">
2710-
<location file="{}" line="5" column="12" info="Null pointer dereference"/>
2711-
<location file="{}" line="4" column="8" info="Assuming that condition &apos;p&apos; is not redundant"/>
2712-
<symbol>p</symbol>
2713-
</error>
2714-
</errors>
2715-
</results>
2716-
'''.format(test_file, test_file, test_file))
2717-
2718-
exitcode_2, stdout_2, stderr_2 = cppcheck(args)
2719-
assert exitcode_1 == exitcode_2, stdout_2
2720-
assert stdout_1 == stdout_2
2721-
assert stderr_1 == stderr_2
2702+
'''<?xml version="1.0" encoding="UTF-8"?>
2703+
<results version="2">
2704+
<cppcheck version="{}"/>
2705+
<errors>
2706+
<error id="nullPointerRedundantCheck" severity="warning" msg="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." verbose="Either the condition &apos;p&apos; is redundant or there is possible null pointer dereference: p." cwe="476" file0="{}" remark="boom">
2707+
<location file="{}" line="5" column="12" info="Null pointer dereference"/>
2708+
<location file="{}" line="4" column="8" info="Assuming that condition &apos;p&apos; is not redundant"/>
2709+
<symbol>p</symbol>
2710+
</error>
2711+
</errors>
2712+
</results>
2713+
'''.format(version_str, str(test_file).replace('\\', '/'), test_file, test_file)) # TODO: the slashes are inconsistent
27222714

27232715

27242716
def test_internal_error_loc_int(tmp_path):

test/cli/testutils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
152152
exe = cppcheck_exe if cppcheck_exe else __lookup_cppcheck_exe()
153153
assert exe is not None, 'no cppcheck binary found'
154154

155-
if 'TEST_CPPCHECK_INJECT_J' in os.environ:
155+
# do not inject arguments for calls with exclusive options
156+
has_exclusive = bool({'--doc', '--errorlist', '-h', '--help', '--version'} & set(args))
157+
158+
if not has_exclusive and ('TEST_CPPCHECK_INJECT_J' in os.environ):
156159
found_j = False
157160
for arg in args:
158161
if arg.startswith('-j'):
@@ -162,7 +165,7 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
162165
arg_j = '-j' + str(os.environ['TEST_CPPCHECK_INJECT_J'])
163166
args.append(arg_j)
164167

165-
if 'TEST_CPPCHECK_INJECT_CLANG' in os.environ:
168+
if not has_exclusive and ('TEST_CPPCHECK_INJECT_CLANG' in os.environ):
166169
found_clang = False
167170
for arg in args:
168171
if arg.startswith('--clang'):
@@ -172,7 +175,7 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
172175
arg_clang = '--clang=' + str(os.environ['TEST_CPPCHECK_INJECT_CLANG'])
173176
args.append(arg_clang)
174177

175-
if 'TEST_CPPCHECK_INJECT_EXECUTOR' in os.environ:
178+
if not has_exclusive and ('TEST_CPPCHECK_INJECT_EXECUTOR' in os.environ):
176179
found_jn = False
177180
found_executor = False
178181
for arg in args:
@@ -189,7 +192,7 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
189192

190193
builddir_tmp = None
191194

192-
if 'TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ:
195+
if not has_exclusive and ('TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ):
193196
found_builddir = False
194197
for arg in args:
195198
if arg.startswith('--cppcheck-build-dir=') or arg == '--no-cppcheck-build-dir':

0 commit comments

Comments
 (0)