Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cobertura: missing support for function coverage #843

Closed
RoadTrain opened this issue Nov 1, 2023 · 4 comments
Closed

Cobertura: missing support for function coverage #843

RoadTrain opened this issue Nov 1, 2023 · 4 comments
Labels
Format: Cobertura not possible for now This feature is not possible because of restrictions from other ones Type: Question

Comments

@RoadTrain
Copy link

RoadTrain commented Nov 1, 2023

Currently Cobertura reporter does not fill the <methods> element, leaving it blank. The reasoning for that is as folows:

# The Cobertura DTD requires a methods section, which isn't
# trivial to get from gcov (so we will leave it blank)
etree.SubElement(c, "methods")

I'm not sure if this rationale still holds? By looking at JSON output there seems to be a list of functions for each file, including their line numbers.

So probably the Cobertura reporter can be updated to support functions?
If so, then the correct output would be as follows:

		<methods>
			<method name="func1"  hits="7"  signature="(signature1)" >
				<lines><line number="40"  hits="7" /></lines>
			</method>
			<method name="func2"  hits="0"  signature="(signature2)" >
				<lines><line number="8"  hits="0" /></lines>
			</method>
		</methods>
@Spacetown
Copy link
Member

Currently Cobertura reporter does not fill the <methods> element, leaving it blank. The reasoning for that is as folows:

# The Cobertura DTD requires a methods section, which isn't
# trivial to get from gcov (so we will leave it blank)
etree.SubElement(c, "methods")

I'm not sure if this rationale still holds? By looking at JSON output there seems to be a list of functions for each file, including their line numbers.

It still true since we do not have full information needed for the report.

So probably the Cobertura reporter can be updated to support functions? If so, then the correct output would be as follows:

		<methods>
			<method name="func1"  hits="7"  signature="(signature1)" >
				<lines><line number="40"  hits="7" /></lines>
			</method>
			<method name="func2"  hits="0"  signature="(signature2)" >
				<lines><line number="8"  hits="0" /></lines>
			</method>
		</methods>

This example is invalid according to the DTD:

<!ELEMENT method (lines)>
<!ATTLIST method name CDATA #REQUIRED>
<!ATTLIST method signature CDATA #REQUIRED>
<!ATTLIST method line-rate CDATA #REQUIRED>
<!ATTLIST method branch-rate CDATA #REQUIRED>
<!ATTLIST method complexity CDATA #REQUIRED>

The hitsis not valid here but a line-rate, branch-rateand complexity is required. This information is completely missing, we only have a block-rate.

Related #654 .

@Spacetown Spacetown added not possible for now This feature is not possible because of restrictions from other ones Format: Cobertura labels Nov 1, 2023
@RoadTrain
Copy link
Author

For the record, my example was from the cobertura report generated by istanbuljs. It is indeed not compliant with the spec, but it's working with report parsers and visualizers that we have tried (namely, ReportGenerator).

Of course I would like for gcovr to be compliant with the spec, and I'm looking forward for this kind of support.
Thanks!

@Spacetown
Copy link
Member

There is already an issue since Apr 2021 related to the wrong report format, see istanbuljs/istanbuljs#603.

ReportGenerator doesn't validate input against the DTD. It only uses the expected arguments and ignores additional ones. The reports generated by the tool are DTD conform.

@RoadTrain
Copy link
Author

Well, apparently there's an alternative spec, which is less strict: https://github.com/cobertura/cobertura/blob/master/cobertura/src/site/htdocs/xml/coverage-loose.dtd
Anyway, I think it's better to conform to the stricter spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Format: Cobertura not possible for now This feature is not possible because of restrictions from other ones Type: Question
Projects
None yet
Development

No branches or pull requests

2 participants