MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / TEST_P

Function TEST_P

env/env_runtime_test.cc:59–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57class EnvRuntimeTest : public testing::TestWithParam<TestCase> {};
58
59TEST_P(EnvRuntimeTest, EndToEnd) {
60 const TestCase& param = GetParam();
61 auto descriptor_pool = cel::internal::GetSharedTestingDescriptorPool();
62 ASSERT_OK_AND_ASSIGN(Config config, EnvConfigFromYaml(param.config_yaml));
63
64 Env env;
65 env.SetDescriptorPool(descriptor_pool);
66 RegisterStandardExtensions(env);
67 env.SetConfig(config);
68
69 EnvRuntime env_runtime;
70 env_runtime.SetDescriptorPool(descriptor_pool);
71 RegisterStandardExtensions(env_runtime);
72 env_runtime.SetConfig(config);
73
74 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Compiler> compiler, env.NewCompiler());
75 std::unique_ptr<Ast> ast;
76 if (!param.expected_to_fail) {
77 ASSERT_OK_AND_ASSIGN(ValidationResult result,
78 compiler->Compile(param.expr));
79 EXPECT_THAT(result.GetIssues(), IsEmpty()) << result.FormatError();
80 ASSERT_OK_AND_ASSIGN(ast, result.ReleaseAst());
81 } else {
82 // Bypass type checking to allow compilation to succeed since we expect the
83 // runtime to fail.
84 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Source> source,
85 NewSource(param.expr, ""));
86 ASSERT_OK_AND_ASSIGN(ast, compiler->GetParser().Parse(*source));
87 }
88 ASSERT_OK_AND_ASSIGN(std::unique_ptr<Runtime> runtime,
89 env_runtime.NewRuntime());
90
91 absl::StatusOr<std::unique_ptr<Program>> program_or =
92 runtime->CreateProgram(std::move(ast));
93 if (param.expected_to_fail) {
94 EXPECT_THAT(program_or, StatusIs(absl::StatusCode::kInvalidArgument))
95 << " expr: " << param.expr;
96 return;
97 }
98
99 ASSERT_THAT(program_or, IsOk()) << " expr: " << param.expr;
100
101 std::unique_ptr<Program> program = *std::move(program_or);
102 ASSERT_NE(program, nullptr);
103
104 google::protobuf::Arena arena;
105 Activation activation;
106 ASSERT_OK_AND_ASSIGN(Value value, program->Evaluate(&arena, activation));
107 EXPECT_TRUE(value.GetBool()) << " expr: " << param.expr;
108}
109
110std::vector<TestCase> GetEnvRuntimeTestCases() {
111 return {

Callers

nothing calls this directly

Calls 12

NewCompilerMethod · 0.80
GetIssuesMethod · 0.80
FormatErrorMethod · 0.80
ReleaseAstMethod · 0.80
NewRuntimeMethod · 0.80
ASSERT_OK_AND_ASSIGNFunction · 0.70
SetDescriptorPoolMethod · 0.45
SetConfigMethod · 0.45
ParseMethod · 0.45
CreateProgramMethod · 0.45
GetBoolMethod · 0.45

Tested by

no test coverage detected