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

Edit tasklist title
Beta Give feedback Tasklist Submitter checklist, more options

Delete tasklist

Delete tasklist block?
Are you sure? All relationships in this tasklist will be removed.
  1. Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
    Options
  2. Ensure that the pull request title represents the desired changelog entry
    Options
  3. Please describe what you did
    Options
  4. Link to relevant issues in GitHub or Jira
    Options
  5. Link to relevant pull requests, esp. upstream and downstream changes
    Options
  6. Ensure you have provided tests - that demonstrates feature works or fixes the issue
    Options

@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
@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.

@uhafner
Copy link
Member

uhafner commented Jun 4, 2024

Do you need some help with this parser?

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
2 participants