Skip to content

Commit caf3ccf

Browse files
ChinmayMadeshicopybara-github
authored andcommitted
Internal Changes
PiperOrigin-RevId: 808012281
1 parent b202efc commit caf3ccf

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

testing/src/main/java/dev/cel/testing/testrunner/CelCoverageIndex.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import com.google.auto.value.AutoValue;
2020
import com.google.common.collect.ImmutableList;
21+
import com.google.common.io.Files;
2122
import com.google.errorprone.annotations.CanIgnoreReturnValue;
2223
import javax.annotation.concurrent.ThreadSafe;
2324
import dev.cel.common.CelAbstractSyntaxTree;
@@ -28,6 +29,8 @@
2829
import dev.cel.common.types.CelKind;
2930
import dev.cel.parser.CelUnparserVisitor;
3031
import dev.cel.runtime.CelEvaluationListener;
32+
import java.io.File;
33+
import java.io.IOException;
3134
import java.io.UnsupportedEncodingException;
3235
import java.net.URLEncoder;
3336
import java.util.Map;
@@ -392,4 +395,21 @@ private String escapeSpecialCharacters(String exprText) {
392395
.replace("{", "\\{")
393396
.replace("}", "\\}");
394397
}
398+
399+
private void writeDotGraphToArtifact(String dotGraph) {
400+
String testOutputsDir = System.getenv("TEST_UNDECLARED_OUTPUTS_DIR");
401+
if (testOutputsDir == null) {
402+
// Only for OSS users, we write to a subdirectory under the cwd.
403+
testOutputsDir = "cel_artifacts";
404+
}
405+
File outputDir = new File(testOutputsDir, "cel_test_coverage");
406+
if (!outputDir.exists()) {
407+
outputDir.mkdirs();
408+
}
409+
try {
410+
Files.asCharSink(new File(outputDir, "coverage_graph.txt"), UTF_8).write(dotGraph);
411+
} catch (IOException e) {
412+
throw new IllegalStateException(e);
413+
}
414+
}
395415
}

testing/src/test/java/dev/cel/testing/testrunner/CelCoverageIndexTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
package dev.cel.testing.testrunner;
1515

1616
import static com.google.common.truth.Truth.assertThat;
17+
import static java.nio.charset.StandardCharsets.UTF_8;
1718

1819
import com.google.common.collect.ImmutableMap;
20+
import com.google.common.io.Files;
1921
import dev.cel.bundle.Cel;
2022
import dev.cel.bundle.CelFactory;
2123
import dev.cel.common.CelAbstractSyntaxTree;
@@ -27,6 +29,7 @@
2729
import dev.cel.runtime.CelEvaluationListener;
2830
import dev.cel.runtime.CelRuntime;
2931
import dev.cel.testing.testrunner.CelCoverageIndex.CoverageReport;
32+
import java.io.File;
3033
import org.junit.Before;
3134
import org.junit.Test;
3235
import org.junit.runner.RunWith;

0 commit comments

Comments
 (0)