Search in sources :

Example 1 with BaselineCoverageAction

use of com.google.devtools.build.lib.rules.test.BaselineCoverageAction in project bazel by bazelbuild.

the class BuildViewTestCase method baselineCoverageArtifactBasenames.

protected Iterable<String> baselineCoverageArtifactBasenames(ConfiguredTarget target) throws Exception {
    ImmutableList.Builder<String> basenames = ImmutableList.builder();
    for (Artifact baselineCoverage : target.getProvider(InstrumentedFilesProvider.class).getBaselineCoverageArtifacts()) {
        BaselineCoverageAction baselineAction = (BaselineCoverageAction) getGeneratingAction(baselineCoverage);
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        baselineAction.newDeterministicWriter(ActionsTestUtil.createContext(reporter)).writeOutputFile(bytes);
        for (String line : new String(bytes.toByteArray(), StandardCharsets.UTF_8).split("\n")) {
            if (line.startsWith("SF:")) {
                String basename = line.substring(line.lastIndexOf('/') + 1);
                basenames.add(basename);
            }
        }
    }
    return basenames.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) InstrumentedFilesProvider(com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BaselineCoverageAction(com.google.devtools.build.lib.rules.test.BaselineCoverageAction) Artifact(com.google.devtools.build.lib.actions.Artifact)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 BaselineCoverageAction (com.google.devtools.build.lib.rules.test.BaselineCoverageAction)1 InstrumentedFilesProvider (com.google.devtools.build.lib.rules.test.InstrumentedFilesProvider)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1