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

Commit c07e8e9

Browse files
committed
If no cppcheck errors are parsed, output a single success test case to satisfy Bamboo.
1 parent de5546a commit c07e8e9

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,17 @@ Convert it to JUnit XML format:
5454
5555
$ cppcheck_junit cppcheck-result.xml cppcheck-junit.xml
5656
57+
If no ``cppcheck`` errors are generated, a single ``"Cppcheck success"`` test case is
58+
output so that CI tools like Bamboo will not fail on the JUnit task.
59+
5760
Releases
5861
--------
5962

63+
1.1.0 - 2016-04-11
64+
^^^^^^^^^^^^^^^^^^
65+
66+
If no ``cppcheck`` errors are parsed, output a single success test case to satisfy Bamboo.
67+
6068
1.0.0 - 2016-02-15
6169
^^^^^^^^^^^^^^^^^^
6270

cppcheck_junit.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import sys
1010
from xml.etree import ElementTree
1111

12-
__version__ = '1.0.0'
13-
1412
EXIT_SUCCESS = 0
1513
EXIT_FAILURE = -1
1614

@@ -126,6 +124,18 @@ def generate_test_suite(errors):
126124
return ElementTree.ElementTree(test_suite)
127125

128126

127+
def generate_single_success_test_suite():
128+
# type: () -> ElementTree.ElementTree
129+
"""Generates a single successful JUnit XML testcase."""
130+
test_suite = ElementTree.Element('testsuite')
131+
test_suite.attrib['name'] = 'Cppcheck errors'
132+
test_suite.attrib['tests'] = str(1)
133+
ElementTree.SubElement(test_suite,
134+
'testcase',
135+
name='Cppcheck success')
136+
return ElementTree.ElementTree(test_suite)
137+
138+
129139
def main(): # pragma: no cover
130140
# type: () -> int
131141
"""Main function.
@@ -150,7 +160,9 @@ def main(): # pragma: no cover
150160

151161
if len(errors) > 0:
152162
tree = generate_test_suite(errors)
153-
tree.write(args.output_file, encoding='utf-8', xml_declaration=True)
163+
else:
164+
tree = generate_single_success_test_suite()
165+
tree.write(args.output_file, encoding='utf-8', xml_declaration=True)
154166

155167
return EXIT_SUCCESS
156168

setup.py

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

66
setup(
77
name='cppcheck-junit',
8-
version=cppcheck_junit.__version__,
8+
version='1.1.0',
99

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

test.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import sys
77
from xml.etree import ElementTree
88

9-
from cppcheck_junit import CppcheckError, generate_test_suite, parse_arguments, parse_cppcheck
9+
from cppcheck_junit import (CppcheckError, generate_single_success_test_suite,
10+
generate_test_suite, parse_arguments, parse_cppcheck)
1011

1112

1213
class ParseCppcheckTestCase(unittest.TestCase):
@@ -90,6 +91,16 @@ def test_single(self):
9091
self.assertEqual(error_element.get('message'), '4: (severity) error message')
9192

9293

94+
class GenerateSingleSuccessTestSuite(unittest.TestCase):
95+
def test(self):
96+
tree = generate_single_success_test_suite()
97+
root = tree.getroot()
98+
self.assertEqual(root.get('tests'), str(1))
99+
100+
test_case_element = root.find('testcase')
101+
self.assertEqual(test_case_element.get('name'), 'Cppcheck success')
102+
103+
93104
class ParseArgumentsTestCase(unittest.TestCase):
94105
def test_no_arguments(self):
95106
with self.assertRaises(SystemExit):

0 commit comments

Comments
 (0)