Skip to content

Commit

Permalink
Verify that --coverage_report_generator points to an executable target.
Browse files Browse the repository at this point in the history
Prevents an unsightly NPE later on.

Fixes #6450

PiperOrigin-RevId: 490885958
Change-Id: I7444adb3cb816e98e03e4680a68eddd322170021
  • Loading branch information
c-mita authored and copybara-github committed Nov 25, 2022
1 parent cc712ee commit 3c1b115
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ private TestParams createTestAction(int shards)
TransitiveInfoCollection reportGeneratorTarget =
ruleContext.getPrerequisite(":coverage_report_generator");
reportGenerator = reportGeneratorTarget.getProvider(FilesToRunProvider.class);
if (reportGenerator.getExecutable() == null) {
ruleContext.ruleError("--coverage_report_generator does not refer to an executable target");
}
}

return new TestParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,15 @@ private ImmutableList<Artifact.DerivedArtifact> getTestStatusArtifacts(String la
return target.getProvider(TestProvider.class).getTestParams().getTestStatusArtifacts();
}

@Test
public void testNonExecutableCoverageReportGenerator() throws Exception {
useConfiguration(
"--coverage_report_generator=//bad_gen:bad_cov_gen", "--collect_code_coverage");
checkError(
"bad_gen",
"some_test",
"--coverage_report_generator does not refer to an executable target",
"sh_library(name = 'bad_cov_gen')",
"cc_test(name = 'some_test')");
}
}

0 comments on commit 3c1b115

Please sign in to comment.