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
```

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=h1) Report
> Merging [#6](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=desc) into [master](https://codecov.io/gh/johnthagen/cppcheck-junit/commit/62cf03e4eee1ce80cccc1a9557417fb4b7f436f2?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6/graphs/tree.svg?height=150&token=IW4AuhadSQ&width=650&src=pr)](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=tree)

```diff
@@          Coverage Diff          @@
##           master     #6   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         195    197    +2     
  Branches       13     13           
=====================================
+ Hits          195    197    +2
```


| [Impacted Files](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [cppcheck\_junit.py](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=tree#diff-Y3BwY2hlY2tfanVuaXQucHk=) | `100% <ø> (ø)` | :arrow_up: |
| [test.py](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=tree#diff-dGVzdC5weQ==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=footer). Last update [62cf03e...057f760](https://codecov.io/gh/johnthagen/cppcheck-junit/pull/6?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

bjornpiltz: This fixes #5 for me.

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())