Skip to content

Commit

Permalink
Fixes #2. Handle Cppcheck errors that don't have a location tag.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthagen committed Apr 14, 2016
1 parent f3e19d7 commit e190306
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 3 deletions.
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ output so that CI tools like Bamboo will not fail on the JUnit task.
Releases
--------

1.1.2 - 2016-04-13
^^^^^^^^^^^^^^^^^^

Handle ``cppcheck`` errors that don't have a ``<location>`` tag.

1.1.1 - 2016-04-11
^^^^^^^^^^^^^^^^^^

Expand Down
11 changes: 9 additions & 2 deletions cppcheck_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,15 @@ def parse_cppcheck(file_name):
errors = collections.defaultdict(list)
for error_element in error_root:
location_element = error_element.find('location') # type: ElementTree.Element
error = CppcheckError(file=location_element.get('file'),
line=int(location_element.get('line')),
if location_element is not None:
file = location_element.get('file')
line = int(location_element.get('line'))
else:
file = ''
line = 0

error = CppcheckError(file=file,
line=line,
message=error_element.get('msg'),
severity=error_element.get('severity'),
error_id=error_element.get('id'),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='cppcheck-junit',
version='1.1.1',
version='1.1.2',

description='Converts Cppcheck XML output to JUnit format.',
long_description=open('README.rst').read(),
Expand Down
20 changes: 20 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ def test_bad(self):
self.assertEqual(errors[file1][1].message,
"Array 'a[10]' accessed at index 10, which is out of bounds.")

def test_no_location_element(self):
file = ''
errors = parse_cppcheck('tests/cppcheck-out-no-location-element.xml')

self.assertEqual(len(errors), 1)
error = errors[file][0]
self.assertEqual(error.file, file)
self.assertEqual(error.line, 0)
self.assertEqual(
error.message,
'Too many #ifdef configurations - cppcheck only checks 12 configurations. '
'Use --force to check all configurations. For more details, use '
'--enable=information.')
self.assertEqual(error.severity, 'information')

def test_bad_large(self):
errors = parse_cppcheck('tests/cppcheck-out-bad-large.xml')
self.assertEqual(len(errors), 43)


def test_all(self):
file1 = 'bad.cpp'
file2 = 'bad2.cpp'
Expand Down
Loading

0 comments on commit e190306

Please sign in to comment.