Skip to content
This repository was archived by the owner on Jan 1, 2026. It is now read-only.

Commit b4ba836

Browse files
committed
Fix handling Cppcheck errors that don't have a location. Release 1.2.0. Fixes #2.
1 parent b089154 commit b4ba836

File tree

5 files changed

+68
-2
lines changed

5 files changed

+68
-2
lines changed

README.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ output so that CI tools like Bamboo will not fail on the JUnit task.
6060
Releases
6161
--------
6262

63+
1.2.0 - 2016-04-13
64+
^^^^^^^^^^^^^^^^^^
65+
66+
Actually handle ``cppcheck`` errors that don't have a ``<location>`` tag.
67+
Update test suite to use ``tox``.
68+
6369
1.1.2 - 2016-04-13
6470
^^^^^^^^^^^^^^^^^^
6571

cppcheck_junit.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
"""Converts Cppcheck XML version 2 output to JUnit XML format."""
44

5+
from __future__ import absolute_import, division, print_function, unicode_literals
6+
57
import argparse
68
import collections
79
from typing import Dict, List # noqa

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name='cppcheck-junit',
6-
version='1.1.2',
6+
version='1.2.0',
77

88
description='Converts Cppcheck XML output to JUnit format.',
99
long_description=open('README.rst').read(),

test.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
"""cppcheck-junit tests."""
44

5+
from __future__ import absolute_import, division, print_function, unicode_literals
6+
57
import sys
68
import unittest
79
from xml.etree import ElementTree
@@ -29,7 +31,7 @@ def test_bad(self): # type: () -> None
2931
self.assertEqual(errors[file1][1].message,
3032
"Array 'a[10]' accessed at index 10, which is out of bounds.")
3133

32-
def test_no_location_element(self): # type: () -> None
34+
def test_no_location_element(self): # type: () -> None
3335
file = ''
3436
errors = parse_cppcheck('tests/cppcheck-out-no-location-element.xml')
3537

@@ -44,6 +46,19 @@ def test_no_location_element(self): # type: () -> None
4446
'--enable=information.')
4547
self.assertEqual(error.severity, 'information')
4648

49+
def test_missing_include_no_location_element(self): # type: () -> None
50+
file = ''
51+
errors = parse_cppcheck('tests/cppcheck-out-missing-include-no-location-element.xml')
52+
53+
self.assertEqual(len(errors), 1)
54+
error = errors[file][0]
55+
self.assertEqual(error.file, file)
56+
self.assertEqual(error.line, 0)
57+
self.assertEqual(
58+
error.message,
59+
'Cppcheck cannot find all the include files (use --check-config for details)')
60+
self.assertEqual(error.severity, 'information')
61+
4762
def test_bad_large(self): # type: () -> None
4863
errors = parse_cppcheck('tests/cppcheck-out-bad-large.xml')
4964
self.assertEqual(len(errors), 43)
@@ -109,6 +124,40 @@ def test_single(self): # type: () -> None
109124
self.assertEqual(error_element.get('line'), str(4))
110125
self.assertEqual(error_element.get('message'), '4: (severity) error message')
111126

127+
def test_missing_file(self): # type: () -> None
128+
errors = {'':
129+
[CppcheckError(file='',
130+
line=0,
131+
message='Too many #ifdef configurations - cppcheck only checks '
132+
'12 configurations. Use --force to check all '
133+
'configurations. For more details, use '
134+
'--enable=information.',
135+
severity='information',
136+
error_id='toomanyconfigs',
137+
verbose='The checking of the file will be interrupted because '
138+
'there are too many #ifdef configurations. Checking of '
139+
'all #ifdef configurations can be forced by --force '
140+
'command line option or from GUI preferences. However '
141+
'that may increase the checking time. For more details, '
142+
'use --enable=information.')]}
143+
tree = generate_test_suite(errors)
144+
root = tree.getroot()
145+
self.assertEqual(root.get('errors'), str(1))
146+
self.assertEqual(root.get('failures'), str(0))
147+
self.assertEqual(root.get('tests'), str(1))
148+
149+
test_case_element = root.find('testcase')
150+
self.assertEqual(test_case_element.get('name'), '')
151+
152+
error_element = test_case_element.find('error')
153+
self.assertEqual(error_element.get('file'), '')
154+
self.assertEqual(error_element.get('line'), str(0))
155+
self.assertEqual(error_element.get('message'),
156+
'0: (information) Too many #ifdef configurations - cppcheck only checks '
157+
'12 configurations. Use --force to check all '
158+
'configurations. For more details, use '
159+
'--enable=information.')
160+
112161

113162
class GenerateSingleSuccessTestSuite(unittest.TestCase):
114163
def test(self): # type: () -> None
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<results version="2">
3+
<cppcheck version="1.61"/>
4+
<errors>
5+
<error id="missingInclude" severity="information"
6+
msg="Cppcheck cannot find all the include files (use --check-config for details)"
7+
verbose="Cppcheck cannot find all the include files. Cppcheck can check the code without t he include files found. But the results will probably be more accurate if all the include files are found. Please check your project's include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config."></error>
8+
</errors>
9+
</results>

0 commit comments

Comments
 (0)