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

Add parser for Clover coverage #104

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft

Add parser for Clover coverage #104

wants to merge 13 commits into from

Conversation

pyieh
Copy link

@pyieh pyieh commented May 7, 2024

Adding a parser for Python coverage files.

Testing done

Yesting was done in both with unit tests and a test coverage file (based on real coverage files). As well as on a local Jenkins, where a local version of the Jenkins coverage-plugin was installed to use this coverage model. Ran a simple Python pipeline and validated the coverage output was available in the UI.

Submitter checklist

Preview Give feedback

@uhafner uhafner added the feature New features label May 8, 2024
src/main/java/edu/hm/hafner/coverage/Metric.java Outdated Show resolved Hide resolved
<package name="components">
<metrics statements="46" coveredstatements="35" conditionals="12" coveredconditionals="8" methods="17" coveredmethods="7"/>
<file name="File3.jsx" path="/home/jenkins/agent/workspace/dir/src/js/components/File3.jsx">
<metrics statements="17" coveredstatements="11" conditionals="2" coveredconditionals="2" methods="8" coveredmethods="3"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is there conditionals="2" coveredconditionals="2" but in line 61 we have no coverage of the false branch:

truecount="2" falsecount="0"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branches are currently not used so far (only the branch coverage). That means in the file rendering you see only green and red lines. If you want to support a visualization of the branches then you need to evaluate these values as well. Then it makes sense to see what truecount="2" falsecount="0" actually means.

@uhafner uhafner marked this pull request as draft May 13, 2024 20:07
Pierson Yieh and others added 2 commits May 13, 2024 15:58
@CanIgnoreReturnValue
private FileNode readFile(final XMLEventReader reader, final PackageNode packageNode, final StartElement fileElement) throws XMLStreamException {
String fileName = getValueOf(fileElement, NAME);
String className = fileName.substring(0, fileName.lastIndexOf("."));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to implement that in a safe way as the index might be -1.

classNode.addValue(createValue("CONDITIONAL", condCovered, condTotal - condCovered));
classNode.addValue(createValue("INSTRUCTION", stmntsCovered, stmntsTotal - stmntsCovered));

} else if (LINE.equals(e.getName())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you omit the branch coverage on purpose?

Copy link
Member

@uhafner uhafner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are almost there! Please check the remaining comments and either mark them as resolved or update the sources.

It seems that you do not use my style guide settings so I auto-formatted the parser in IntelliJ and pushed the commit...

return new ModuleNode("empty");
}
catch (XMLStreamException exception) {
throw new SecureXmlParserFactory.ParsingException(exception);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
throw new SecureXmlParserFactory.ParsingException(exception);
throw new ParsingException(exception);

Then I can simpler move the exception in a followup PR.

}
}
else {
new ParsingException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
new ParsingException(
throw new ParsingException(

}
}

private void addBranchCoverage(final Node node, final StartElement e) {// final int covered, final int total) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void addBranchCoverage(final Node node, final StartElement e) {// final int covered, final int total) {
private void addBranchCoverage(final Node node, final StartElement e) {

addCoverage(node, "BRANCH", condCovered, condTotal);
}

private void addInstructionCoverage(final Node node, final StartElement e) { //final int covered, final int total) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void addInstructionCoverage(final Node node, final StartElement e) { //final int covered, final int total) {
private void addInstructionCoverage(final Node node, final StartElement e) {

private void addInstructionCoverage(final Node node, final StartElement e) { //final int covered, final int total) {
int stmntsTotal = getIntegerValueOf(e, STATEMENTS);
int stmntsCovered = getIntegerValueOf(e, COVERED_STATEMENTS);
addCoverage(node, "INSTRUCTION", stmntsCovered, stmntsTotal);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the enum

}

private void addInstructionCoverage(final Node node, final StartElement e) { //final int covered, final int total) {
int stmntsTotal = getIntegerValueOf(e, STATEMENTS);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Java we typically do not use shortened variable names, use statementsTotal and so on.

Comment on lines +72 to +73
case CLOVER:
return new CloverParser(processingMode);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add Clover to the README as well?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<coverage generated="1695944532781" clover="3.2.0">
<project timestamp="1695944532781" name="All files">
<metrics statements="3057" coveredstatements="2578" conditionals="1444" coveredconditionals="1068" methods="1003" coveredmethods="736" elements="5504" coveredelements="4382" complexity="0" loc="3057" ncloc="3057" packages="68" files="170" classes="170"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to see the correct LOC you can set the LOC value on the project level (otherwise it is computed from the line values).

<package name="components">
<metrics statements="46" coveredstatements="35" conditionals="12" coveredconditionals="8" methods="17" coveredmethods="7"/>
<file name="File3.jsx" path="/home/jenkins/agent/workspace/dir/src/js/components/File3.jsx">
<metrics statements="17" coveredstatements="11" conditionals="2" coveredconditionals="2" methods="8" coveredmethods="3"/>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branches are currently not used so far (only the branch coverage). That means in the file rendering you see only green and red lines. If you want to support a visualization of the branches then you need to evaluate these values as well. Then it makes sense to see what truecount="2" falsecount="0" actually means.

Co-authored-by: Ullrich Hafner <ullrich.hafner@gmail.com>
@uhafner
Copy link
Member

uhafner commented Jun 4, 2024

Do you need some help with this parser?

@pyieh
Copy link
Author

pyieh commented Jun 13, 2024

@uhafner Sorry, been pulled into other priorities, but will get to this soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants