Skip to content

Commit

Permalink
Handle exact execPath matches in JacocoLCOVFormatter
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 523963590
Change-Id: I1495b2dfa5423a17414f0d951385b418fb319f65
  • Loading branch information
c-mita authored and copybara-github committed Apr 13, 2023
1 parent 11dc7de commit 928b102
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private String getExecPathForEntryName(String classPath) {
if (parts[1].equals(matchingFileName)) {
return parts[0];
}
} else if (execPath.endsWith(matchingFileName)) {
} else if (execPath.endsWith(matchingFileName) || execPath.equals(classPath)) {
return execPath;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,21 @@ public void testVisitBundleWithoutExecPathsDoesNotPruneOutput() throws IOExcepti
String coverageOutput = writer.toString();
assertThat(coverageOutput).isNotEmpty();
}

@Test
public void testVisitBundleWithExactMatch() throws IOException {
// It's possible, albeit unlikely, that the execPath and the package based path match exactly
String srcPath = "com/example/Foo.java";
ImmutableSet<String> execPaths = ImmutableSet.of(srcPath);
JacocoLCOVFormatter formatter = new JacocoLCOVFormatter(execPaths);
IReportVisitor visitor =
formatter.createVisitor(
new PrintWriter(writer), new TreeMap<String, BranchCoverageDetail>());

visitor.visitBundle(mockBundle, mock(ISourceFileLocator.class));
visitor.visitEnd();

String coverageOutput = writer.toString();
assertThat(coverageOutput).contains(srcPath);
}
}

0 comments on commit 928b102

Please sign in to comment.