Skip to content

Commit 9ee6f69

Browse files
jnthntatumcopybara-github
authored andcommitted
Add end-to-end sets extension unit tests for the cel::Runtime API.
PiperOrigin-RevId: 1004291402
1 parent a943249 commit 9ee6f69

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

‎extensions/BUILD‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,8 @@ cc_test(
526526
"//checker:validation_result",
527527
"//common:ast_proto",
528528
"//common:minimal_descriptor_pool",
529+
"//common:value",
530+
"//compiler",
529531
"//compiler:compiler_factory",
530532
"//eval/public:activation",
531533
"//eval/public:builtin_func_registrar",
@@ -535,7 +537,11 @@ cc_test(
535537
"//eval/public:cel_options",
536538
"//eval/public:cel_value",
537539
"//internal:testing",
540+
"//runtime",
541+
"//runtime:activation",
542+
"//runtime:runtime_builder",
538543
"//runtime:runtime_options",
544+
"//runtime:standard_runtime_builder_factory",
539545
"@com_google_absl//absl/status:status_matchers",
540546
"@com_google_cel_spec//proto/cel/expr:syntax_cc_proto",
541547
"@com_google_protobuf//:protobuf",

‎extensions/sets_functions_test.cc‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
#include <memory>
1818
#include <string>
19+
#include <utility>
1920

2021
#include "cel/expr/syntax.pb.h"
2122
#include "absl/status/status_matchers.h"
2223
#include "checker/standard_library.h"
2324
#include "checker/validation_result.h"
2425
#include "common/ast_proto.h"
2526
#include "common/minimal_descriptor_pool.h"
27+
#include "common/value.h"
28+
#include "compiler/compiler.h"
2629
#include "compiler/compiler_factory.h"
2730
#include "eval/public/activation.h"
2831
#include "eval/public/builtin_func_registrar.h"
@@ -32,7 +35,11 @@
3235
#include "eval/public/cel_options.h"
3336
#include "eval/public/cel_value.h"
3437
#include "internal/testing.h"
38+
#include "runtime/activation.h"
39+
#include "runtime/runtime.h"
40+
#include "runtime/runtime_builder.h"
3541
#include "runtime/runtime_options.h"
42+
#include "runtime/standard_runtime_builder_factory.h"
3643
#include "google/protobuf/arena.h"
3744

3845
namespace cel::extensions {
@@ -93,6 +100,44 @@ TEST_P(CelSetsFunctionsTest, EndToEnd) {
93100
EXPECT_TRUE(out.BoolOrDie()) << test_info.expr << " -> " << out.DebugString();
94101
}
95102

103+
TEST_P(CelSetsFunctionsTest, RuntimeEndToEnd) {
104+
const TestInfo& test_info = GetParam();
105+
ASSERT_OK_AND_ASSIGN(std::unique_ptr<CompilerBuilder> compiler_builder,
106+
NewCompilerBuilder(cel::GetMinimalDescriptorPool()));
107+
108+
ASSERT_THAT(compiler_builder->AddLibrary(StandardCheckerLibrary()), IsOk());
109+
ASSERT_THAT(compiler_builder->AddLibrary(SetsCompilerLibrary()), IsOk());
110+
ASSERT_OK_AND_ASSIGN(std::unique_ptr<const Compiler> compiler,
111+
compiler_builder->Build());
112+
113+
ASSERT_OK_AND_ASSIGN(ValidationResult compiled,
114+
compiler->Compile(test_info.expr));
115+
116+
ASSERT_TRUE(compiled.IsValid()) << compiled.FormatError();
117+
118+
RuntimeOptions options;
119+
options.enable_heterogeneous_equality = true;
120+
options.enable_empty_wrapper_null_unboxing = true;
121+
options.enable_qualified_type_identifiers = true;
122+
ASSERT_OK_AND_ASSIGN(
123+
RuntimeBuilder runtime_builder,
124+
CreateStandardRuntimeBuilder(cel::GetMinimalDescriptorPool(), options));
125+
ASSERT_THAT(
126+
RegisterSetsFunctions(runtime_builder.function_registry(), options),
127+
IsOk());
128+
ASSERT_OK_AND_ASSIGN(std::unique_ptr<const Runtime> runtime,
129+
std::move(runtime_builder).Build());
130+
131+
ASSERT_OK_AND_ASSIGN(std::unique_ptr<Program> program,
132+
runtime->CreateProgram(*compiled.ReleaseAst()));
133+
Arena arena;
134+
cel::Activation activation;
135+
ASSERT_OK_AND_ASSIGN(Value out, program->Evaluate(&arena, activation));
136+
ASSERT_TRUE(out.IsBool()) << test_info.expr << " -> " << out.DebugString();
137+
EXPECT_TRUE(out.GetBool().NativeValue())
138+
<< test_info.expr << " -> " << out.DebugString();
139+
}
140+
96141
INSTANTIATE_TEST_SUITE_P(
97142
CelSetsFunctionsTest, CelSetsFunctionsTest,
98143
testing::ValuesIn<TestInfo>({

0 commit comments

Comments
 (0)