-
Notifications
You must be signed in to change notification settings - Fork 39
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
base: main
Are you sure you want to change the base?
Conversation
src/test/java/edu/hm/hafner/coverage/parser/CloverParserTest.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"/> |
There was a problem hiding this comment.
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"
There was a problem hiding this comment.
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>
src/test/java/edu/hm/hafner/coverage/parser/CloverParserTest.java
Outdated
Show resolved
Hide resolved
@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(".")); |
There was a problem hiding this comment.
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())) { |
There was a problem hiding this comment.
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?
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
throw new SecureXmlParserFactory.ParsingException(exception); | |
throw new ParsingException(exception); |
Then I can simpler move the exception in a followup PR.
} | ||
} | ||
else { | ||
new ParsingException( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new ParsingException( | |
throw new ParsingException( |
} | ||
} | ||
|
||
private void addBranchCoverage(final Node node, final StartElement e) {// final int covered, final int total) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
case CLOVER: | ||
return new CloverParser(processingMode); |
There was a problem hiding this comment.
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"/> |
There was a problem hiding this comment.
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"/> |
There was a problem hiding this comment.
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>
Do you need some help with this parser? |
@uhafner Sorry, been pulled into other priorities, but will get to this soon! |
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