@@ -154,4 +154,28 @@ public void getCoverageReport_fullCoverage_writesToUndeclaredOutputs() throws Ex
154
154
String fileContent = Files .asCharSource (outputFile , UTF_8 ).read ();
155
155
assertThat (fileContent ).isEqualTo (report .dotGraph ());
156
156
}
157
+
158
+ @ Test
159
+ public void getCoverageReport_fullCoverage_multipleEvaluations () throws Exception {
160
+ Cel cel = CelFactory .standardCelBuilder ().addVar ("x" , SimpleType .INT ).build ();
161
+ CelAbstractSyntaxTree ast = cel .compile ("x > 1" ).getAst ();
162
+ CelRuntime .Program program = cel .createProgram (ast );
163
+ CelCoverageIndex coverageIndex = new CelCoverageIndex ();
164
+ coverageIndex .init (ast );
165
+ CelEvaluationListener listener = coverageIndex .newEvaluationListener ();
166
+
167
+ program .trace (ImmutableMap .of ("x" , 2L ), listener );
168
+ coverageIndex .init (ast ); // Re-initialize the coverage index.
169
+ program .trace (ImmutableMap .of ("x" , 0L ), listener );
170
+
171
+ CoverageReport report = coverageIndex .generateCoverageReport ();
172
+ assertThat (report .nodes ()).isGreaterThan (0 );
173
+ assertThat (report .coveredNodes ()).isEqualTo (report .nodes ());
174
+ assertThat (report .branches ()).isEqualTo (2 );
175
+ // Despite re-initializing the coverage index now, the report should still
176
+ // be fully covered. Else, only the second evaluation would've been covered.
177
+ assertThat (report .coveredBooleanOutcomes ()).isEqualTo (2 );
178
+ assertThat (report .unencounteredNodes ()).isEmpty ();
179
+ assertThat (report .unencounteredBranches ()).isEmpty ();
180
+ }
157
181
}
0 commit comments