Repository: johnthagen/cppcheck-junit

Issue:
Failing tests not showing up on bamboo.
I have added the following steps to my bamboo plan

- `cppcheck ... 2> cppcheck-result.xml`
- `cppcheck_junit cppcheck-result.xml cppcheck-junit.xml`
- JUnit Parser

I can see a passing test on the dashboard if cppcheck reports no errrors. If there are errors, however, I can only see that JUnit parser failed. No further information is available. 

Here are my logs:

```bash
build	16-Oct-2017 10:21:36	Running cppcheck:
cppcheck --xml --xml-version=2 --enable=all --
project=compile_commands.json 2> cppcheck-result.xml
```
### cppcheck-result.xml:
```xml
<?xml version="1.0" encoding="UTF-8"?>
	<results version="2">
		<cppcheck version="1.80"/>
		<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 the include files found. But the results will probably be more accurate if all the include files are found. Please check your project&apos;s include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config."/>
		</errors>
	</results>
```

```
build	16-Oct-2017 10:21:36	Running cppcheck_junit:
cppcheck_junit cppcheck-result.xml cppcheck-junit.xml
```
### cppcheck-junit.xml:
```xml
<?xml version='1.0' encoding='utf-8'?>
	<testsuite errors="1" failures="0" hostname="XXX" name="Cppcheck errors" tests="1" time="1" timestamp="2017-10-16T10:21:36.514058">
		<testcase classname="" name="" time="1">
			<error file="" line="0" message="0: (information) Cppcheck cannot find all the include files (use --check-config for details)" type="" />
	</testcase>
</testsuite>
```

```
simple	16-Oct-2017 10:21:36	Finished task 'cppcheck' with result: Success
simple	16-Oct-2017 10:21:36	Starting task 'JUnit Parser' of type 'com.atlassian.bamboo.plugins.testresultparser:task.testresultparser.junit'
simple	16-Oct-2017 10:21:36	Parsing test results under <path>
simple	16-Oct-2017 10:21:36	Failing task since 1 failing test cases were found.
simple	16-Oct-2017 10:21:36	Finished task 'JUnit Parser' with result: Failed
```

Comments:

Patch:
diff --git a/cppcheck_junit.py b/cppcheck_junit.py
index 87be9a5..9adfd7e 100755
--- a/cppcheck_junit.py
+++ b/cppcheck_junit.py
@@ -123,8 +123,9 @@ def generate_test_suite(errors):
     for file_name, errors in errors.items():
         test_case = ElementTree.SubElement(test_suite,
                                            'testcase',
-                                           name=os.path.relpath(file_name) if file_name else '',
-                                           classname='',
+                                           name=os.path.relpath(
+                                               file_name) if file_name else 'Cppcheck error',
+                                           classname='Cppcheck error',
                                            time=str(1))
         for error in errors:
             ElementTree.SubElement(test_case,
@@ -153,7 +154,7 @@ def generate_single_success_test_suite():
     ElementTree.SubElement(test_suite,
                            'testcase',
                            name='Cppcheck success',
-                           classname='',
+                           classname='Cppcheck success',
                            time=str(1))
     return ElementTree.ElementTree(test_suite)
 


Test patch:
diff --git a/test.py b/test.py
index e873733..18c3907 100644
--- a/test.py
+++ b/test.py
@@ -168,7 +168,8 @@ class GenerateTestSuiteTestCase(unittest.TestCase):
             self.assertTrue(required_attribute in testsuite_element.attrib.keys())
 
         testcase_element = testsuite_element.find('testcase')
-        self.assertEqual(testcase_element.get('name'), '')
+        self.assertEqual(testcase_element.get('name'), 'Cppcheck error')
+        self.assertEqual(testcase_element.get('classname'), 'Cppcheck error')
         # Check that test_case is compliant with the spec
         for required_attribute in self.junit_testcase_attributes:
             self.assertTrue(required_attribute in testcase_element.attrib.keys())
@@ -207,6 +208,7 @@ class GenerateSingleSuccessTestSuite(unittest.TestCase):
 
         testcase_element = testsuite_element.find('testcase')
         self.assertEqual(testcase_element.get('name'), 'Cppcheck success')
+        self.assertEqual(testcase_element.get('classname'), 'Cppcheck success')
         # Check that test_case is compliant with the spec
         for required_attribute in self.junit_testcase_attributes:
             self.assertTrue(required_attribute in testcase_element.attrib.keys())