Skip to content

Commit

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

1.2.0 - 2016-04-13
^^^^^^^^^^^^^^^^^^

Actually handle ``cppcheck`` errors that don't have a ``<location>`` tag.
Update test suite to use ``tox``.

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

Expand Down
2 changes: 2 additions & 0 deletions cppcheck_junit.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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

from __future__ import absolute_import, division, print_function, unicode_literals

import argparse
import collections
from typing import Dict, List # noqa
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.2',
version='1.2.0',

description='Converts Cppcheck XML output to JUnit format.',
long_description=open('README.rst').read(),
Expand Down
51 changes: 50 additions & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

"""cppcheck-junit tests."""

from __future__ import absolute_import, division, print_function, unicode_literals

import sys
import unittest
from xml.etree import ElementTree
Expand Down Expand Up @@ -29,7 +31,7 @@ def test_bad(self): # type: () -> None
self.assertEqual(errors[file1][1].message,
"Array 'a[10]' accessed at index 10, which is out of bounds.")

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

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

def test_missing_include_no_location_element(self): # type: () -> None
file = ''
errors = parse_cppcheck('tests/cppcheck-out-missing-include-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,
'Cppcheck cannot find all the include files (use --check-config for details)')
self.assertEqual(error.severity, 'information')

def test_bad_large(self): # type: () -> None
errors = parse_cppcheck('tests/cppcheck-out-bad-large.xml')
self.assertEqual(len(errors), 43)
Expand Down Expand Up @@ -109,6 +124,40 @@ def test_single(self): # type: () -> None
self.assertEqual(error_element.get('line'), str(4))
self.assertEqual(error_element.get('message'), '4: (severity) error message')

def test_missing_file(self): # type: () -> None
errors = {'':
[CppcheckError(file='',
line=0,
message='Too many #ifdef configurations - cppcheck only checks '
'12 configurations. Use --force to check all '
'configurations. For more details, use '
'--enable=information.',
severity='information',
error_id='toomanyconfigs',
verbose='The checking of the file will be interrupted because '
'there are too many #ifdef configurations. Checking of '
'all #ifdef configurations can be forced by --force '
'command line option or from GUI preferences. However '
'that may increase the checking time. For more details, '
'use --enable=information.')]}
tree = generate_test_suite(errors)
root = tree.getroot()
self.assertEqual(root.get('errors'), str(1))
self.assertEqual(root.get('failures'), str(0))
self.assertEqual(root.get('tests'), str(1))

test_case_element = root.find('testcase')
self.assertEqual(test_case_element.get('name'), '')

error_element = test_case_element.find('error')
self.assertEqual(error_element.get('file'), '')
self.assertEqual(error_element.get('line'), str(0))
self.assertEqual(error_element.get('message'),
'0: (information) Too many #ifdef configurations - cppcheck only checks '
'12 configurations. Use --force to check all '
'configurations. For more details, use '
'--enable=information.')


class GenerateSingleSuccessTestSuite(unittest.TestCase):
def test(self): # type: () -> None
Expand Down
9 changes: 9 additions & 0 deletions tests/cppcheck-out-missing-include-no-location-element.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<results version="2">
<cppcheck version="1.61"/>
<errors>
<error id="missingInclude" severity="information"
msg="Cppcheck cannot find all the include files (use --check-config for details)"
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>
</errors>
</results>

0 comments on commit b4ba836

Please sign in to comment.