Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions runtime/src/main/java/dev/cel/runtime/CelRuntimeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public Object advanceEvaluation(UnknownContext context) throws CelEvaluationExce

static Builder newBuilder() {
return new AutoValue_CelRuntimeImpl.Builder()
.setFunctionBindings(ImmutableMap.of())
.setStandardFunctions(CelStandardFunctions.newBuilder().build())
.setContainer(CelContainer.newBuilder().build())
.setExtensionRegistry(ExtensionRegistry.getEmptyRegistry());
Expand Down Expand Up @@ -222,6 +223,8 @@ abstract static class Builder implements CelRuntimeBuilder {

abstract ExtensionRegistry extensionRegistry();

abstract ImmutableMap<String, CelFunctionBinding> functionBindings();

abstract ImmutableSet.Builder<Descriptors.FileDescriptor> fileDescriptorsBuilder();

abstract ImmutableSet.Builder<CelRuntimeLibrary> runtimeLibrariesBuilder();
Expand Down Expand Up @@ -442,6 +445,9 @@ public CelRuntime build() {
DescriptorTypeResolver descriptorTypeResolver =
DescriptorTypeResolver.create(combinedTypeProvider);
TypeFunction typeFunction = TypeFunction.create(descriptorTypeResolver);

mutableFunctionBindings.putAll(functionBindings());

for (CelFunctionBinding binding :
typeFunction.newFunctionBindings(options(), runtimeEquality)) {
mutableFunctionBindings.put(binding.getOverloadId(), binding);
Expand Down
4 changes: 4 additions & 0 deletions runtime/src/test/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ java_library(
"PlannerInterpreterTest.java",
],
deps = [
"//common:cel_ast",
"//common:compiler_common",
"//common:container",
"//common:options",
"//common/types:type_providers",
"//extensions",
"//runtime",
"//runtime:runtime_planner_impl",
Expand Down
58 changes: 58 additions & 0 deletions runtime/src/test/java/dev/cel/runtime/PlannerInterpreterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@

package dev.cel.runtime;

import com.google.testing.junit.testparameterinjector.TestParameter;
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelContainer;
import dev.cel.common.CelOptions;
import dev.cel.common.CelValidationException;
import dev.cel.common.types.CelTypeProvider;
import dev.cel.extensions.CelExtensions;
import dev.cel.testing.BaseInterpreterTest;
import org.junit.runner.RunWith;
Expand All @@ -24,6 +29,8 @@
@RunWith(TestParameterInjector.class)
public class PlannerInterpreterTest extends BaseInterpreterTest {

@TestParameter boolean isParseOnly;

@Override
protected CelRuntimeBuilder newBaseRuntimeBuilder(CelOptions celOptions) {
return CelRuntimeImpl.newBuilder()
Expand All @@ -34,6 +41,36 @@ protected CelRuntimeBuilder newBaseRuntimeBuilder(CelOptions celOptions) {
.addFileTypes(TEST_FILE_DESCRIPTORS);
}

@Override
protected void setContainer(CelContainer container) {
super.setContainer(container);
this.celRuntime = this.celRuntime.toRuntimeBuilder().setContainer(container).build();
}

@Override
protected CelAbstractSyntaxTree prepareTest(CelTypeProvider typeProvider) {
super.prepareCompiler(typeProvider);

CelAbstractSyntaxTree ast;
try {
ast = celCompiler.parse(source, testSourceDescription()).getAst();
} catch (CelValidationException e) {
printTestValidationError(e);
return null;
}

if (isParseOnly) {
return ast;
}

try {
return celCompiler.check(ast).getAst();
} catch (CelValidationException e) {
printTestValidationError(e);
return null;
}
}

@Override
public void unknownField() {
// TODO: Unknown support not implemented yet
Expand All @@ -45,4 +82,25 @@ public void unknownResultSet() {
// TODO: Unknown support not implemented yet
skipBaselineVerification();
}

@Override
public void optional() {
if (isParseOnly) {
// TODO: Fix for parsed-only mode.
skipBaselineVerification();
} else {
super.optional();
}
}

@Override
public void optional_errors() {
if (isParseOnly) {
// Parsed-only evaluation contains function name in the
// error message instead of the function overload.
skipBaselineVerification();
} else {
super.optional_errors();
}
}
}
1 change: 1 addition & 0 deletions testing/src/main/java/dev/cel/testing/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ java_library(
"//runtime:late_function_binding",
"//runtime:unknown_attributes",
"@cel_spec//proto/cel/expr:checked_java_proto",
"@cel_spec//proto/cel/expr:syntax_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
"@maven//:com_google_errorprone_error_prone_annotations",
Expand Down
Loading
Loading