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
47 changes: 1 addition & 46 deletions compiler/src/test/java/dev/cel/compiler/tools/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,73 +1,28 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//:testing.bzl", "junit4_test_suites")
load("//compiler/tools:compile_cel.bzl", "compile_cel")

package(
default_applicable_licenses = ["//:license"],
default_testonly = True,
)

compile_cel(
name = "compiled_hello_world",
expression = "'hello world'",
)

compile_cel(
name = "compiled_comprehension",
expression = "[1,2,3].map(x, x + 1)",
)

compile_cel(
name = "compiled_proto_message",
expression = "cel.expr.conformance.proto3.TestAllTypes{single_int32: 1}",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

compile_cel(
name = "compiled_extensions",
environment = "//testing/environment:all_extensions",
expression = "cel.bind(x, 10, math.greatest([1,x])) < int(' 11 '.trim()) && optional.none().orValue(true) && [].flatten() == []",
)

compile_cel(
name = "compiled_extended_env",
environment = "//testing/environment:extended_env",
expression = "msg.single_string_wrapper.isEmpty() == false",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

filegroup(
name = "compiled_exprs",
# keep sorted
srcs = [
":compiled_comprehension",
":compiled_extended_env",
":compiled_extensions",
":compiled_hello_world",
":compiled_proto_message",
],
)

java_library(
name = "tests",
testonly = True,
srcs = glob(["*Test.java"]),
resources = [":compiled_exprs"],
deps = [
"//:java_truth",
"//common:cel_ast",
"//common:options",
"//common:proto_ast",
"//extensions",
"//extensions:optional_library",
"//runtime",
"//runtime:function_binding",
"@cel_spec//proto/cel/expr:checked_java_proto",
"//testing/compiled:compiled_expr_utils",
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
"@maven//:com_google_guava_guava",
"@maven//:com_google_protobuf_protobuf_java",
"@maven//:junit_junit",
"@maven_android//:com_google_protobuf_protobuf_javalite",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
package dev.cel.compiler.tools;

import static com.google.common.truth.Truth.assertThat;
import static dev.cel.testing.compiled.CompiledExprUtils.readCheckedExpr;

import dev.cel.expr.CheckedExpr;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.google.protobuf.ExtensionRegistryLite;
import com.google.protobuf.StringValue;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelOptions;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.expr.conformance.proto3.TestAllTypes;
import dev.cel.extensions.CelExtensions;
import dev.cel.extensions.CelOptionalLibrary;
import dev.cel.runtime.CelRuntime;
import dev.cel.runtime.CelFunctionBinding;
import dev.cel.runtime.CelRuntimeFactory;
import java.net.URL;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down Expand Up @@ -100,12 +96,4 @@ public void compiledCheckedExpr_extended_env() throws Exception {

assertThat(result).isTrue();
}

private static CelAbstractSyntaxTree readCheckedExpr(String compiledCelTarget) throws Exception {
URL url = Resources.getResource(CelCompilerToolTest.class, compiledCelTarget + ".binarypb");
byte[] checkedExprBytes = Resources.toByteArray(url);
CheckedExpr checkedExpr =
CheckedExpr.parseFrom(checkedExprBytes, ExtensionRegistryLite.getEmptyRegistry());
return CelProtoAbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst();
}
}
170 changes: 1 addition & 169 deletions runtime/src/test/java/dev/cel/runtime/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,178 +1,12 @@
load("@rules_java//java:defs.bzl", "java_library")
load("//:cel_android_rules.bzl", "cel_android_local_test")
load("//:testing.bzl", "junit4_test_suites")
load("//compiler/tools:compile_cel.bzl", "compile_cel")

package(
default_applicable_licenses = ["//:license"],
default_testonly = True,
)

compile_cel(
name = "compiled_hello_world",
expression = "'hello world'",
)

compile_cel(
name = "compiled_one_plus_two",
expression = "1 + 2",
)

compile_cel(
name = "compiled_list_literal",
expression = "['a', 1, 2u, 3.5]",
)

compile_cel(
name = "compiled_comprehension_exists",
expression = "[1,2,3].exists(x, x == 3)",
)

compile_cel(
name = "compiled_primitive_variables",
environment = "//testing/environment:primitive_variables",
expression = "bool_var && bytes_var == b'abc' && double_var == 1.0 && int_var == 42 && uint_var == 42u && str_var == 'foo'",
)

compile_cel(
name = "compiled_custom_functions",
environment = "//testing/environment:custom_functions",
expression = "''.isEmpty() && [].isEmpty()",
)

compile_cel(
name = "compiled_proto2_select_primitives_all_ored",
environment = "//testing/environment:proto2_message_variables",
expression = "proto2.single_int32 == 1 || proto2.single_int64 == 2 || proto2.single_uint32 == 3u || proto2.single_uint64 == 4u ||" +
"proto2.single_sint32 == 5 || proto2.single_sint64 == 6 || proto2.single_fixed32 == 7u || proto2.single_fixed64 == 8u ||" +
"proto2.single_sfixed32 == 9 || proto2.single_sfixed64 == 10 || proto2.single_float == 1.5 || proto2.single_double == 2.5 ||" +
"proto2.single_bool || proto2.single_string == 'hello world' || proto2.single_bytes == b\'abc\'",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto2_select_primitives",
environment = "//testing/environment:proto2_message_variables",
expression = "proto2.single_int32 == 1 && proto2.single_int64 == 2 && proto2.single_uint32 == 3u && proto2.single_uint64 == 4u &&" +
"proto2.single_sint32 == 5 && proto2.single_sint64 == 6 && proto2.single_fixed32 == 7u && proto2.single_fixed64 == 8u &&" +
"proto2.single_sfixed32 == 9 && proto2.single_sfixed64 == 10 && proto2.single_float == 1.5 && proto2.single_double == 2.5 &&" +
"proto2.single_bool && proto2.single_string == 'hello world' && proto2.single_bytes == b\'abc\'",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto2_select_wrappers",
environment = "//testing/environment:proto2_message_variables",
expression = "proto2.single_int32_wrapper == 1 && proto2.single_int64_wrapper == 2 && proto2.single_float_wrapper == 1.5 &&" +
"proto2.single_double_wrapper == 2.5 && proto2.single_uint32_wrapper == 3u && proto2.single_uint64_wrapper == 4u &&" +
"proto2.single_string_wrapper == 'hello world' && proto2.single_bool_wrapper && proto2.single_bytes_wrapper == b\'abc\'",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto3_select_primitives_all_ored",
environment = "//testing/environment:proto3_message_variables",
expression = "proto3.single_int32 == 1 || proto3.single_int64 == 2 || proto3.single_uint32 == 3u || proto3.single_uint64 == 4u ||" +
"proto3.single_sint32 == 5 || proto3.single_sint64 == 6 || proto3.single_fixed32 == 7u || proto3.single_fixed64 == 8u ||" +
"proto3.single_sfixed32 == 9 || proto3.single_sfixed64 == 10 || proto3.single_float == 1.5 || proto3.single_double == 2.5 ||" +
"proto3.single_bool || proto3.single_string == 'hello world' || proto3.single_bytes == b\'abc\'",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto3_select_primitives",
environment = "//testing/environment:proto3_message_variables",
expression = "proto3.single_int32 == 1 && proto3.single_int64 == 2 && proto3.single_uint32 == 3u && proto3.single_uint64 == 4u &&" +
"proto3.single_sint32 == 5 && proto3.single_sint64 == 6 && proto3.single_fixed32 == 7u && proto3.single_fixed64 == 8u &&" +
"proto3.single_sfixed32 == 9 && proto3.single_sfixed64 == 10 && proto3.single_float == 1.5 && proto3.single_double == 2.5 &&" +
"proto3.single_bool && proto3.single_string == 'hello world' && proto3.single_bytes == b\'abc\'",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto3_select_wrappers",
environment = "//testing/environment:proto3_message_variables",
expression = "proto3.single_int32_wrapper == 1 && proto3.single_int64_wrapper == 2 && proto3.single_float_wrapper == 1.5 &&" +
"proto3.single_double_wrapper == 2.5 && proto3.single_uint32_wrapper == 3u && proto3.single_uint64_wrapper == 4u &&" +
"proto3.single_string_wrapper == 'hello world' && proto3.single_bool_wrapper && proto3.single_bytes_wrapper == b\'abc\'",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto2_deep_traversal",
environment = "//testing/environment:proto2_message_variables",
expression = "proto2.oneof_type.payload.repeated_string",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto3_deep_traversal",
environment = "//testing/environment:proto3_message_variables",
expression = "proto3.oneof_type.payload.repeated_string",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto2_select_repeated_fields",
environment = "//testing/environment:proto2_message_variables",
expression = "[proto2.repeated_int32, proto2.repeated_int64, proto2.repeated_uint32, proto2.repeated_uint64, proto2.repeated_sint32, proto2.repeated_sint64, " +
"proto2.repeated_fixed32, proto2.repeated_fixed64, proto2.repeated_sfixed32, proto2.repeated_sfixed64, proto2.repeated_float, proto2.repeated_double, " +
"proto2.repeated_bool, proto2.repeated_string, proto2.repeated_bytes]",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto3_select_repeated_fields",
environment = "//testing/environment:proto3_message_variables",
expression = "[proto3.repeated_int32, proto3.repeated_int64, proto3.repeated_uint32, proto3.repeated_uint64, proto3.repeated_sint32, proto3.repeated_sint64, " +
"proto3.repeated_fixed32, proto3.repeated_fixed64, proto3.repeated_sfixed32, proto3.repeated_sfixed64, proto3.repeated_float, proto3.repeated_double, " +
"proto3.repeated_bool, proto3.repeated_string, proto3.repeated_bytes]",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto2_select_map_fields",
environment = "//testing/environment:proto2_message_variables",
expression = "[proto2.map_bool_bool, proto2.map_bool_string, proto2.map_bool_bytes, proto2.map_bool_int32, proto2.map_bool_int64, " +
"proto2.map_bool_uint32, proto2.map_bool_uint64, proto2.map_bool_float, proto2.map_bool_double, proto2.map_bool_enum, " +
"proto2.map_bool_duration, proto2.map_bool_timestamp]",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
)

compile_cel(
name = "compiled_proto3_select_map_fields",
environment = "//testing/environment:proto3_message_variables",
expression = "[proto3.map_bool_bool, proto3.map_bool_string, proto3.map_bool_bytes, proto3.map_bool_int32, proto3.map_bool_int64, " +
"proto3.map_bool_uint32, proto3.map_bool_uint64, proto3.map_bool_float, proto3.map_bool_double, proto3.map_bool_enum, " +
"proto3.map_bool_duration, proto3.map_bool_timestamp]",
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
)

filegroup(
name = "compiled_exprs",
# keep sorted
srcs = [
":compiled_comprehension_exists",
":compiled_custom_functions",
":compiled_hello_world",
":compiled_list_literal",
":compiled_one_plus_two",
":compiled_primitive_variables",
":compiled_proto2_deep_traversal",
":compiled_proto2_select_map_fields",
":compiled_proto2_select_primitives",
":compiled_proto2_select_primitives_all_ored",
":compiled_proto2_select_repeated_fields",
":compiled_proto2_select_wrappers",
":compiled_proto3_deep_traversal",
":compiled_proto3_select_map_fields",
":compiled_proto3_select_primitives",
":compiled_proto3_select_primitives_all_ored",
":compiled_proto3_select_repeated_fields",
":compiled_proto3_select_wrappers",
],
)

ANDROID_TESTS = [
"CelLiteRuntimeAndroidTest.java",
]
Expand All @@ -189,7 +23,6 @@ java_library(
"InterpreterTest.java",
] + ANDROID_TESTS,
),
resources = [":compiled_exprs"],
deps = [
"//:auto_value",
"//:java_truth",
Expand Down Expand Up @@ -296,13 +129,11 @@ java_library(
cel_android_local_test(
name = "android_tests",
srcs = ANDROID_TESTS,
resources = [":compiled_exprs"],
test_class = "dev.cel.runtime.CelLiteRuntimeAndroidTest",
deps = [
"//:java_truth",
"//common:cel_ast_android",
"//common:options",
"//common:proto_ast_android",
"//common/internal:proto_time_utils_android",
"//common/values:cel_value_provider_android",
"//common/values:proto_message_lite_value_provider_android",
Expand All @@ -320,6 +151,7 @@ cel_android_local_test(
"//runtime/standard:int_android",
"//testing/protos:test_all_types_cel_java_proto2_lite",
"//testing/protos:test_all_types_cel_java_proto3_lite",
"//testing/src/main/java/dev/cel/testing/compiled:compiled_expr_utils_android",
"@cel_spec//proto/cel/expr:checked_java_proto_lite",
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto_lite",
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto_lite",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,17 @@
package dev.cel.runtime;

import static com.google.common.truth.Truth.assertThat;
import static dev.cel.testing.compiled.CompiledExprUtils.readCheckedExpr;
import static org.junit.Assert.assertThrows;

import dev.cel.expr.CheckedExpr;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.io.Resources;
import com.google.common.primitives.UnsignedLong;
import com.google.common.truth.Correspondence;
import com.google.protobuf.BoolValue;
import com.google.protobuf.ByteString;
import com.google.protobuf.BytesValue;
import com.google.protobuf.DoubleValue;
import com.google.protobuf.ExtensionRegistryLite;
import com.google.protobuf.FloatValue;
import com.google.protobuf.Int32Value;
import com.google.protobuf.Int64Value;
Expand All @@ -39,7 +37,6 @@
import com.google.testing.junit.testparameterinjector.TestParameters;
import dev.cel.common.CelAbstractSyntaxTree;
import dev.cel.common.CelOptions;
import dev.cel.common.CelProtoAbstractSyntaxTree;
import dev.cel.common.internal.ProtoTimeUtils;
import dev.cel.common.values.CelValueProvider;
import dev.cel.common.values.ProtoMessageLiteValueProvider;
Expand All @@ -53,7 +50,6 @@
import dev.cel.runtime.standard.EqualsOperator;
import dev.cel.runtime.standard.IntFunction;
import dev.cel.runtime.standard.IntFunction.IntOverload;
import java.net.URL;
import java.util.List;
import java.util.Map;
import org.junit.Test;
Expand Down Expand Up @@ -720,15 +716,6 @@ public void eval_protoMessage_mapFields(String checkedExpr) throws Exception {
.inOrder();
}

private static CelAbstractSyntaxTree readCheckedExpr(String compiledCelTarget) throws Exception {
URL url =
Resources.getResource(CelLiteRuntimeAndroidTest.class, compiledCelTarget + ".binarypb");
byte[] checkedExprBytes = Resources.toByteArray(url);
CheckedExpr checkedExpr =
CheckedExpr.parseFrom(checkedExprBytes, ExtensionRegistryLite.getEmptyRegistry());
return CelProtoAbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst();
}

private enum CelOptionsTestCase {
CEL_VALUE_DISABLED(newBaseTestOptions().enableCelValue(false).build()),
UNSIGNED_LONG_DISABLED(newBaseTestOptions().enableUnsignedLongs(false).build()),
Expand Down
15 changes: 15 additions & 0 deletions testing/compiled/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package(
default_applicable_licenses = ["//:license"],
default_testonly = True,
default_visibility = ["//:internal"],
)

alias(
name = "compiled_expr_utils",
actual = "//testing/src/main/java/dev/cel/testing/compiled:compiled_expr_utils",
)

alias(
name = "compiled_expr_utils_android",
actual = "//testing/src/main/java/dev/cel/testing/compiled:compiled_expr_utils_android",
)
Loading
Loading