Skip to content

Commit

Permalink
Parse all digits of a counter before and after the slash.
Browse files Browse the repository at this point in the history
Erroneously, only the last digit has been counted in previous versions.
Fixes jenkinsci/code-coverage-api-plugin#625.
  • Loading branch information
uhafner committed Apr 13, 2023
1 parent 6150a05 commit ec858a8
Show file tree
Hide file tree
Showing 4 changed files with 412 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

<properties>
<scmTag>HEAD</scmTag>
<revision>0.23.0</revision>
<revision>0.22.2</revision>
<changelist>-SNAPSHOT</changelist>

<module.name>edu.hm.hafner.coverage</module.name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class CoberturaParser extends CoverageParser {
private static final QName METHOD = new QName("method");
private static final QName LINE = new QName("line");

private static final Pattern BRANCH_PATTERN = Pattern.compile(".*(?<covered>\\d+)/(?<total>\\d+)\\)");
private static final Pattern BRANCH_PATTERN = Pattern.compile(".*\\((?<covered>\\d+)/(?<total>\\d+)\\)");

/** Required attributes of the XML elements. */
private static final QName NAME = new QName("name");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ CoberturaParser createParser() {
return new CoberturaParser();
}

@Test
void shouldCountCorrectly625() {
Node tree = readReport("cobertura-counter-aggregation.xml");

var expectedValue = new CoverageBuilder().setCovered(31).setMissed(1).setMetric(BRANCH).build();
assertThat(tree.getValue(BRANCH)).isPresent().contains(expectedValue);
}

@Test
void shouldReadCoberturaIssue610() {
Node tree = readReport("coverage-missing-sources.xml");
Expand Down
Loading

0 comments on commit ec858a8

Please sign in to comment.