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

fix(coverage): Account for SHA in lcov DA parsing #6463

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ private static TIntIntHashMap parseHits(BufferedReader reader) throws IOExceptio
return hits;
}
if (line.startsWith(DA)) {
// DA:line,hits
int comma = line.indexOf(',');
// DA:line,hits,sha
String[] segments = line.substring(DA.length()).split(",");
if (segments.length < 2) {
logger.warn(String.format("Cannot parse LCOV line: Expected entry to have format DA:<number>,<number>, was: %s", line));
continue;
}
try {
hits.put(
Integer.parseInt(line.substring(DA.length(), comma)),
Integer.parseInt(line.substring(comma + 1)));
Integer.parseInt(segments[0]),
Integer.parseInt(segments[1]));
} catch (NumberFormatException e) {
logger.warn("Cannot parse LCOV line: " + line, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,30 @@ public void testEmptyFilesIgnored() throws IOException {
assertThat(data.perFileData.keySet()).containsExactly("path/to/another/file.txt");
}

/**
* Some test runners, such as the one for `py_test` in rules_python, append extra data to DA entries.
* This test data is taken from a run of one such `py_test`.
* @throws IOException
*/
@Test
public void testDALinesWithShaCanBeParsed() throws IOException {
BlazeCoverageData data =
BlazeCoverageData.parse(
inputStream(
"SF:path/to/file.txt",
"DA:1,1,CjTuYq8+gnNfbQNgi09Ocg",
"DA:40,1,E/tvV9JPVDhEcTCkgrwOFw",
"DA:42,1,SZ/sLwIPxdnoU2xnoUB7pg",
"end_of_record"
));

assertThat(data.perFileData).hasSize(1);
FileData fileData = data.perFileData.get("path/to/file.txt");
assertThat(fileData).isNotNull();
assertThat(fileData.source).isEqualTo("path/to/file.txt");
assertThat(toMap(fileData.lineHits)).containsExactly(1, 1, 40, 1, 42, 1);
}

private static ImmutableMap<Integer, Integer> toMap(TIntIntHashMap troveMap) {
return Arrays.stream(troveMap.keys())
.boxed()
Expand Down
Loading