Skip to content

Commit

Permalink
fixed #13391 - fixed missing file0 in cached XML results (#7141)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave authored Jan 2, 2025
1 parent 0736f0a commit 5bbde51
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
3 changes: 3 additions & 0 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
const char *attr = errmsg->Attribute("id");
id = attr ? attr : unknown;

attr = errmsg->Attribute("file0");
file0 = attr ? attr : "";

attr = errmsg->Attribute("severity");
severity = attr ? severityFromString(attr) : Severity::none;

Expand Down
40 changes: 16 additions & 24 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2675,11 +2675,7 @@ def test_duplicate_suppressions_mixed(tmp_path):
assert stderr == ''


@pytest.mark.xfail(strict=True)
def test_xml_builddir(tmp_path): # #13391 / #13485
build_dir = tmp_path / 'b1'
os.mkdir(build_dir)

def test_xml_output(tmp_path): # #13391 / #13485
test_file = tmp_path / 'test.cpp'
with open(test_file, 'wt') as f:
f.write("""
Expand All @@ -2690,35 +2686,31 @@ def test_xml_builddir(tmp_path): # #13391 / #13485
}
""")

_, version_str, _ = cppcheck(['--version'])
version_str = version_str.replace('Cppcheck ', '').strip()

args = [
'-q',
'--enable=style',
'--cppcheck-build-dir={}'.format(build_dir),
'--xml',
str(test_file)
]
exitcode_1, stdout_1, stderr_1 = cppcheck(args)
assert exitcode_1 == 0, stdout_1
assert stdout_1 == ''
# TODO: handle version
assert (stderr_1 ==
'''<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="2.17 dev"/>
<errors>
<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">
<location file="{}" line="5" column="12" info="Null pointer dereference"/>
<location file="{}" line="4" column="8" info="Assuming that condition &apos;p&apos; is not redundant"/>
<symbol>p</symbol>
</error>
</errors>
</results>
'''.format(test_file, test_file, test_file))

exitcode_2, stdout_2, stderr_2 = cppcheck(args)
assert exitcode_1 == exitcode_2, stdout_2
assert stdout_1 == stdout_2
assert stderr_1 == stderr_2
'''<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="{}"/>
<errors>
<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">
<location file="{}" line="5" column="12" info="Null pointer dereference"/>
<location file="{}" line="4" column="8" info="Assuming that condition &apos;p&apos; is not redundant"/>
<symbol>p</symbol>
</error>
</errors>
</results>
'''.format(version_str, str(test_file).replace('\\', '/'), test_file, test_file)) # TODO: the slashes are inconsistent


def test_internal_error_loc_int(tmp_path):
Expand Down
11 changes: 7 additions & 4 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,10 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
exe = cppcheck_exe if cppcheck_exe else __lookup_cppcheck_exe()
assert exe is not None, 'no cppcheck binary found'

if 'TEST_CPPCHECK_INJECT_J' in os.environ:
# do not inject arguments for calls with exclusive options
has_exclusive = bool({'--doc', '--errorlist', '-h', '--help', '--version'} & set(args))

if not has_exclusive and ('TEST_CPPCHECK_INJECT_J' in os.environ):
found_j = False
for arg in args:
if arg.startswith('-j'):
Expand All @@ -162,7 +165,7 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
arg_j = '-j' + str(os.environ['TEST_CPPCHECK_INJECT_J'])
args.append(arg_j)

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

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

builddir_tmp = None

if 'TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ:
if not has_exclusive and ('TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ):
found_builddir = False
for arg in args:
if arg.startswith('--cppcheck-build-dir=') or arg == '--no-cppcheck-build-dir':
Expand Down

0 comments on commit 5bbde51

Please sign in to comment.