|
15 | 15 | #ifndef THIRD_PARTY_CEL_CPP_TOOLS_TESTRUNNER_CEL_TEST_CONTEXT_H_ |
16 | 16 | #define THIRD_PARTY_CEL_CPP_TOOLS_TESTRUNNER_CEL_TEST_CONTEXT_H_ |
17 | 17 |
|
| 18 | +#include <functional> |
18 | 19 | #include <memory> |
19 | 20 | #include <string> |
20 | 21 | #include <utility> |
|
24 | 25 | #include "absl/base/nullability.h" |
25 | 26 | #include "absl/container/flat_hash_map.h" |
26 | 27 | #include "absl/memory/memory.h" |
| 28 | +#include "absl/status/statusor.h" |
27 | 29 | #include "compiler/compiler.h" |
28 | 30 | #include "eval/public/cel_expression.h" |
| 31 | +#include "runtime/activation.h" |
29 | 32 | #include "runtime/runtime.h" |
30 | 33 | #include "testing/testrunner/cel_expression_source.h" |
| 34 | +#include "cel/expr/conformance/test/suite.pb.h" |
| 35 | +#include "google/protobuf/arena.h" |
31 | 36 | namespace cel::test { |
32 | 37 |
|
33 | 38 | // The context class for a CEL test, holding configurations needed to evaluate |
34 | 39 | // compiled CEL expressions. |
35 | 40 | class CelTestContext { |
36 | 41 | public: |
| 42 | + using CelActivationFactoryFn = std::function<absl::StatusOr<cel::Activation>( |
| 43 | + const cel::expr::conformance::test::TestCase& test_case, |
| 44 | + google::protobuf::Arena* arena)>; |
| 45 | + |
37 | 46 | // Creates a CelTestContext using a `CelExpressionBuilder`. |
38 | 47 | // |
39 | 48 | // The `CelExpressionBuilder` helps in setting up the environment for |
@@ -107,6 +116,17 @@ class CelTestContext { |
107 | 116 | custom_bindings_ = std::move(custom_bindings); |
108 | 117 | } |
109 | 118 |
|
| 119 | + // Allows the runner to inject a custom activation factory. If not set, an |
| 120 | + // empty activation will be used. Custom bindings and test case inputs will |
| 121 | + // be added to the activation returned by the factory. |
| 122 | + void SetActivationFactory(CelActivationFactoryFn activation_factory) { |
| 123 | + activation_factory_ = std::move(activation_factory); |
| 124 | + } |
| 125 | + |
| 126 | + const CelActivationFactoryFn& activation_factory() const { |
| 127 | + return activation_factory_; |
| 128 | + } |
| 129 | + |
110 | 130 | private: |
111 | 131 | // Delete copy and move constructors. |
112 | 132 | CelTestContext(const CelTestContext&) = delete; |
@@ -151,6 +171,8 @@ class CelTestContext { |
151 | 171 | // needed to generate Program. Users should either provide a runtime, or the |
152 | 172 | // CelExpressionBuilder. |
153 | 173 | std::unique_ptr<const cel::Runtime> runtime_; |
| 174 | + |
| 175 | + CelActivationFactoryFn activation_factory_; |
154 | 176 | }; |
155 | 177 |
|
156 | 178 | } // namespace cel::test |
|
0 commit comments