Skip to content

Commit 6ba18a0

Browse files
l46kokcopybara-github
authored andcommitted
Internal Changes
PiperOrigin-RevId: 775386543
1 parent cc2961f commit 6ba18a0

File tree

7 files changed

+296
-242
lines changed

7 files changed

+296
-242
lines changed

compiler/src/test/java/dev/cel/compiler/tools/BUILD.bazel

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,28 @@
11
load("@rules_java//java:defs.bzl", "java_library")
22
load("//:testing.bzl", "junit4_test_suites")
3-
load("//compiler/tools:compile_cel.bzl", "compile_cel")
43

54
package(
65
default_applicable_licenses = ["//:license"],
76
default_testonly = True,
87
)
98

10-
compile_cel(
11-
name = "compiled_hello_world",
12-
expression = "'hello world'",
13-
)
14-
15-
compile_cel(
16-
name = "compiled_comprehension",
17-
expression = "[1,2,3].map(x, x + 1)",
18-
)
19-
20-
compile_cel(
21-
name = "compiled_proto_message",
22-
expression = "cel.expr.conformance.proto3.TestAllTypes{single_int32: 1}",
23-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
24-
)
25-
26-
compile_cel(
27-
name = "compiled_extensions",
28-
environment = "//testing/environment:all_extensions",
29-
expression = "cel.bind(x, 10, math.greatest([1,x])) < int(' 11 '.trim()) && optional.none().orValue(true) && [].flatten() == []",
30-
)
31-
32-
compile_cel(
33-
name = "compiled_extended_env",
34-
environment = "//testing/environment:extended_env",
35-
expression = "msg.single_string_wrapper.isEmpty() == false",
36-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
37-
)
38-
39-
filegroup(
40-
name = "compiled_exprs",
41-
# keep sorted
42-
srcs = [
43-
":compiled_comprehension",
44-
":compiled_extended_env",
45-
":compiled_extensions",
46-
":compiled_hello_world",
47-
":compiled_proto_message",
48-
],
49-
)
50-
519
java_library(
5210
name = "tests",
5311
testonly = True,
5412
srcs = glob(["*Test.java"]),
55-
resources = [":compiled_exprs"],
5613
deps = [
5714
"//:java_truth",
5815
"//common:cel_ast",
5916
"//common:options",
60-
"//common:proto_ast",
6117
"//extensions",
6218
"//extensions:optional_library",
6319
"//runtime",
6420
"//runtime:function_binding",
65-
"@cel_spec//proto/cel/expr:checked_java_proto",
21+
"//testing/compiled:compiled_expr_utils",
6622
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
6723
"@maven//:com_google_guava_guava",
6824
"@maven//:com_google_protobuf_protobuf_java",
6925
"@maven//:junit_junit",
70-
"@maven_android//:com_google_protobuf_protobuf_javalite",
7126
],
7227
)
7328

compiler/src/test/java/dev/cel/compiler/tools/CelCompilerToolTest.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,18 @@
1515
package dev.cel.compiler.tools;
1616

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

19-
import dev.cel.expr.CheckedExpr;
2020
import com.google.common.collect.ImmutableMap;
21-
import com.google.common.io.Resources;
22-
import com.google.protobuf.ExtensionRegistryLite;
2321
import com.google.protobuf.StringValue;
2422
import dev.cel.common.CelAbstractSyntaxTree;
2523
import dev.cel.common.CelOptions;
26-
import dev.cel.common.CelProtoAbstractSyntaxTree;
2724
import dev.cel.expr.conformance.proto3.TestAllTypes;
2825
import dev.cel.extensions.CelExtensions;
2926
import dev.cel.extensions.CelOptionalLibrary;
3027
import dev.cel.runtime.CelRuntime;
3128
import dev.cel.runtime.CelFunctionBinding;
3229
import dev.cel.runtime.CelRuntimeFactory;
33-
import java.net.URL;
3430
import java.util.List;
3531
import org.junit.Test;
3632
import org.junit.runner.RunWith;
@@ -100,12 +96,4 @@ public void compiledCheckedExpr_extended_env() throws Exception {
10096

10197
assertThat(result).isTrue();
10298
}
103-
104-
private static CelAbstractSyntaxTree readCheckedExpr(String compiledCelTarget) throws Exception {
105-
URL url = Resources.getResource(CelCompilerToolTest.class, compiledCelTarget + ".binarypb");
106-
byte[] checkedExprBytes = Resources.toByteArray(url);
107-
CheckedExpr checkedExpr =
108-
CheckedExpr.parseFrom(checkedExprBytes, ExtensionRegistryLite.getEmptyRegistry());
109-
return CelProtoAbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst();
110-
}
11199
}

runtime/src/test/java/dev/cel/runtime/BUILD.bazel

Lines changed: 1 addition & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,178 +1,12 @@
11
load("@rules_java//java:defs.bzl", "java_library")
22
load("//:cel_android_rules.bzl", "cel_android_local_test")
33
load("//:testing.bzl", "junit4_test_suites")
4-
load("//compiler/tools:compile_cel.bzl", "compile_cel")
54

65
package(
76
default_applicable_licenses = ["//:license"],
87
default_testonly = True,
98
)
109

11-
compile_cel(
12-
name = "compiled_hello_world",
13-
expression = "'hello world'",
14-
)
15-
16-
compile_cel(
17-
name = "compiled_one_plus_two",
18-
expression = "1 + 2",
19-
)
20-
21-
compile_cel(
22-
name = "compiled_list_literal",
23-
expression = "['a', 1, 2u, 3.5]",
24-
)
25-
26-
compile_cel(
27-
name = "compiled_comprehension_exists",
28-
expression = "[1,2,3].exists(x, x == 3)",
29-
)
30-
31-
compile_cel(
32-
name = "compiled_primitive_variables",
33-
environment = "//testing/environment:primitive_variables",
34-
expression = "bool_var && bytes_var == b'abc' && double_var == 1.0 && int_var == 42 && uint_var == 42u && str_var == 'foo'",
35-
)
36-
37-
compile_cel(
38-
name = "compiled_custom_functions",
39-
environment = "//testing/environment:custom_functions",
40-
expression = "''.isEmpty() && [].isEmpty()",
41-
)
42-
43-
compile_cel(
44-
name = "compiled_proto2_select_primitives_all_ored",
45-
environment = "//testing/environment:proto2_message_variables",
46-
expression = "proto2.single_int32 == 1 || proto2.single_int64 == 2 || proto2.single_uint32 == 3u || proto2.single_uint64 == 4u ||" +
47-
"proto2.single_sint32 == 5 || proto2.single_sint64 == 6 || proto2.single_fixed32 == 7u || proto2.single_fixed64 == 8u ||" +
48-
"proto2.single_sfixed32 == 9 || proto2.single_sfixed64 == 10 || proto2.single_float == 1.5 || proto2.single_double == 2.5 ||" +
49-
"proto2.single_bool || proto2.single_string == 'hello world' || proto2.single_bytes == b\'abc\'",
50-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
51-
)
52-
53-
compile_cel(
54-
name = "compiled_proto2_select_primitives",
55-
environment = "//testing/environment:proto2_message_variables",
56-
expression = "proto2.single_int32 == 1 && proto2.single_int64 == 2 && proto2.single_uint32 == 3u && proto2.single_uint64 == 4u &&" +
57-
"proto2.single_sint32 == 5 && proto2.single_sint64 == 6 && proto2.single_fixed32 == 7u && proto2.single_fixed64 == 8u &&" +
58-
"proto2.single_sfixed32 == 9 && proto2.single_sfixed64 == 10 && proto2.single_float == 1.5 && proto2.single_double == 2.5 &&" +
59-
"proto2.single_bool && proto2.single_string == 'hello world' && proto2.single_bytes == b\'abc\'",
60-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
61-
)
62-
63-
compile_cel(
64-
name = "compiled_proto2_select_wrappers",
65-
environment = "//testing/environment:proto2_message_variables",
66-
expression = "proto2.single_int32_wrapper == 1 && proto2.single_int64_wrapper == 2 && proto2.single_float_wrapper == 1.5 &&" +
67-
"proto2.single_double_wrapper == 2.5 && proto2.single_uint32_wrapper == 3u && proto2.single_uint64_wrapper == 4u &&" +
68-
"proto2.single_string_wrapper == 'hello world' && proto2.single_bool_wrapper && proto2.single_bytes_wrapper == b\'abc\'",
69-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
70-
)
71-
72-
compile_cel(
73-
name = "compiled_proto3_select_primitives_all_ored",
74-
environment = "//testing/environment:proto3_message_variables",
75-
expression = "proto3.single_int32 == 1 || proto3.single_int64 == 2 || proto3.single_uint32 == 3u || proto3.single_uint64 == 4u ||" +
76-
"proto3.single_sint32 == 5 || proto3.single_sint64 == 6 || proto3.single_fixed32 == 7u || proto3.single_fixed64 == 8u ||" +
77-
"proto3.single_sfixed32 == 9 || proto3.single_sfixed64 == 10 || proto3.single_float == 1.5 || proto3.single_double == 2.5 ||" +
78-
"proto3.single_bool || proto3.single_string == 'hello world' || proto3.single_bytes == b\'abc\'",
79-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
80-
)
81-
82-
compile_cel(
83-
name = "compiled_proto3_select_primitives",
84-
environment = "//testing/environment:proto3_message_variables",
85-
expression = "proto3.single_int32 == 1 && proto3.single_int64 == 2 && proto3.single_uint32 == 3u && proto3.single_uint64 == 4u &&" +
86-
"proto3.single_sint32 == 5 && proto3.single_sint64 == 6 && proto3.single_fixed32 == 7u && proto3.single_fixed64 == 8u &&" +
87-
"proto3.single_sfixed32 == 9 && proto3.single_sfixed64 == 10 && proto3.single_float == 1.5 && proto3.single_double == 2.5 &&" +
88-
"proto3.single_bool && proto3.single_string == 'hello world' && proto3.single_bytes == b\'abc\'",
89-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
90-
)
91-
92-
compile_cel(
93-
name = "compiled_proto3_select_wrappers",
94-
environment = "//testing/environment:proto3_message_variables",
95-
expression = "proto3.single_int32_wrapper == 1 && proto3.single_int64_wrapper == 2 && proto3.single_float_wrapper == 1.5 &&" +
96-
"proto3.single_double_wrapper == 2.5 && proto3.single_uint32_wrapper == 3u && proto3.single_uint64_wrapper == 4u &&" +
97-
"proto3.single_string_wrapper == 'hello world' && proto3.single_bool_wrapper && proto3.single_bytes_wrapper == b\'abc\'",
98-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
99-
)
100-
101-
compile_cel(
102-
name = "compiled_proto2_deep_traversal",
103-
environment = "//testing/environment:proto2_message_variables",
104-
expression = "proto2.oneof_type.payload.repeated_string",
105-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
106-
)
107-
108-
compile_cel(
109-
name = "compiled_proto3_deep_traversal",
110-
environment = "//testing/environment:proto3_message_variables",
111-
expression = "proto3.oneof_type.payload.repeated_string",
112-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
113-
)
114-
115-
compile_cel(
116-
name = "compiled_proto2_select_repeated_fields",
117-
environment = "//testing/environment:proto2_message_variables",
118-
expression = "[proto2.repeated_int32, proto2.repeated_int64, proto2.repeated_uint32, proto2.repeated_uint64, proto2.repeated_sint32, proto2.repeated_sint64, " +
119-
"proto2.repeated_fixed32, proto2.repeated_fixed64, proto2.repeated_sfixed32, proto2.repeated_sfixed64, proto2.repeated_float, proto2.repeated_double, " +
120-
"proto2.repeated_bool, proto2.repeated_string, proto2.repeated_bytes]",
121-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
122-
)
123-
124-
compile_cel(
125-
name = "compiled_proto3_select_repeated_fields",
126-
environment = "//testing/environment:proto3_message_variables",
127-
expression = "[proto3.repeated_int32, proto3.repeated_int64, proto3.repeated_uint32, proto3.repeated_uint64, proto3.repeated_sint32, proto3.repeated_sint64, " +
128-
"proto3.repeated_fixed32, proto3.repeated_fixed64, proto3.repeated_sfixed32, proto3.repeated_sfixed64, proto3.repeated_float, proto3.repeated_double, " +
129-
"proto3.repeated_bool, proto3.repeated_string, proto3.repeated_bytes]",
130-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
131-
)
132-
133-
compile_cel(
134-
name = "compiled_proto2_select_map_fields",
135-
environment = "//testing/environment:proto2_message_variables",
136-
expression = "[proto2.map_bool_bool, proto2.map_bool_string, proto2.map_bool_bytes, proto2.map_bool_int32, proto2.map_bool_int64, " +
137-
"proto2.map_bool_uint32, proto2.map_bool_uint64, proto2.map_bool_float, proto2.map_bool_double, proto2.map_bool_enum, " +
138-
"proto2.map_bool_duration, proto2.map_bool_timestamp]",
139-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_proto"],
140-
)
141-
142-
compile_cel(
143-
name = "compiled_proto3_select_map_fields",
144-
environment = "//testing/environment:proto3_message_variables",
145-
expression = "[proto3.map_bool_bool, proto3.map_bool_string, proto3.map_bool_bytes, proto3.map_bool_int32, proto3.map_bool_int64, " +
146-
"proto3.map_bool_uint32, proto3.map_bool_uint64, proto3.map_bool_float, proto3.map_bool_double, proto3.map_bool_enum, " +
147-
"proto3.map_bool_duration, proto3.map_bool_timestamp]",
148-
proto_srcs = ["@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_proto"],
149-
)
150-
151-
filegroup(
152-
name = "compiled_exprs",
153-
# keep sorted
154-
srcs = [
155-
":compiled_comprehension_exists",
156-
":compiled_custom_functions",
157-
":compiled_hello_world",
158-
":compiled_list_literal",
159-
":compiled_one_plus_two",
160-
":compiled_primitive_variables",
161-
":compiled_proto2_deep_traversal",
162-
":compiled_proto2_select_map_fields",
163-
":compiled_proto2_select_primitives",
164-
":compiled_proto2_select_primitives_all_ored",
165-
":compiled_proto2_select_repeated_fields",
166-
":compiled_proto2_select_wrappers",
167-
":compiled_proto3_deep_traversal",
168-
":compiled_proto3_select_map_fields",
169-
":compiled_proto3_select_primitives",
170-
":compiled_proto3_select_primitives_all_ored",
171-
":compiled_proto3_select_repeated_fields",
172-
":compiled_proto3_select_wrappers",
173-
],
174-
)
175-
17610
ANDROID_TESTS = [
17711
"CelLiteRuntimeAndroidTest.java",
17812
]
@@ -189,7 +23,6 @@ java_library(
18923
"InterpreterTest.java",
19024
] + ANDROID_TESTS,
19125
),
192-
resources = [":compiled_exprs"],
19326
deps = [
19427
"//:auto_value",
19528
"//:java_truth",
@@ -296,13 +129,11 @@ java_library(
296129
cel_android_local_test(
297130
name = "android_tests",
298131
srcs = ANDROID_TESTS,
299-
resources = [":compiled_exprs"],
300132
test_class = "dev.cel.runtime.CelLiteRuntimeAndroidTest",
301133
deps = [
302134
"//:java_truth",
303135
"//common:cel_ast_android",
304136
"//common:options",
305-
"//common:proto_ast_android",
306137
"//common/internal:proto_time_utils_android",
307138
"//common/values:cel_value_provider_android",
308139
"//common/values:proto_message_lite_value_provider_android",
@@ -320,6 +151,7 @@ cel_android_local_test(
320151
"//runtime/standard:int_android",
321152
"//testing/protos:test_all_types_cel_java_proto2_lite",
322153
"//testing/protos:test_all_types_cel_java_proto3_lite",
154+
"//testing/src/main/java/dev/cel/testing/compiled:compiled_expr_utils_android",
323155
"@cel_spec//proto/cel/expr:checked_java_proto_lite",
324156
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto_lite",
325157
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto_lite",

runtime/src/test/java/dev/cel/runtime/CelLiteRuntimeAndroidTest.java

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515
package dev.cel.runtime;
1616

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

20-
import dev.cel.expr.CheckedExpr;
2121
import com.google.common.collect.ImmutableList;
2222
import com.google.common.collect.ImmutableMap;
23-
import com.google.common.io.Resources;
2423
import com.google.common.primitives.UnsignedLong;
2524
import com.google.common.truth.Correspondence;
2625
import com.google.protobuf.BoolValue;
2726
import com.google.protobuf.ByteString;
2827
import com.google.protobuf.BytesValue;
2928
import com.google.protobuf.DoubleValue;
30-
import com.google.protobuf.ExtensionRegistryLite;
3129
import com.google.protobuf.FloatValue;
3230
import com.google.protobuf.Int32Value;
3331
import com.google.protobuf.Int64Value;
@@ -39,7 +37,6 @@
3937
import com.google.testing.junit.testparameterinjector.TestParameters;
4038
import dev.cel.common.CelAbstractSyntaxTree;
4139
import dev.cel.common.CelOptions;
42-
import dev.cel.common.CelProtoAbstractSyntaxTree;
4340
import dev.cel.common.internal.ProtoTimeUtils;
4441
import dev.cel.common.values.CelValueProvider;
4542
import dev.cel.common.values.ProtoMessageLiteValueProvider;
@@ -53,7 +50,6 @@
5350
import dev.cel.runtime.standard.EqualsOperator;
5451
import dev.cel.runtime.standard.IntFunction;
5552
import dev.cel.runtime.standard.IntFunction.IntOverload;
56-
import java.net.URL;
5753
import java.util.List;
5854
import java.util.Map;
5955
import org.junit.Test;
@@ -720,15 +716,6 @@ public void eval_protoMessage_mapFields(String checkedExpr) throws Exception {
720716
.inOrder();
721717
}
722718

723-
private static CelAbstractSyntaxTree readCheckedExpr(String compiledCelTarget) throws Exception {
724-
URL url =
725-
Resources.getResource(CelLiteRuntimeAndroidTest.class, compiledCelTarget + ".binarypb");
726-
byte[] checkedExprBytes = Resources.toByteArray(url);
727-
CheckedExpr checkedExpr =
728-
CheckedExpr.parseFrom(checkedExprBytes, ExtensionRegistryLite.getEmptyRegistry());
729-
return CelProtoAbstractSyntaxTree.fromCheckedExpr(checkedExpr).getAst();
730-
}
731-
732719
private enum CelOptionsTestCase {
733720
CEL_VALUE_DISABLED(newBaseTestOptions().enableCelValue(false).build()),
734721
UNSIGNED_LONG_DISABLED(newBaseTestOptions().enableUnsignedLongs(false).build()),

testing/compiled/BUILD.bazel

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package(
2+
default_applicable_licenses = ["//:license"],
3+
default_testonly = True,
4+
default_visibility = ["//:internal"],
5+
)
6+
7+
alias(
8+
name = "compiled_expr_utils",
9+
actual = "//testing/src/main/java/dev/cel/testing/compiled:compiled_expr_utils",
10+
)
11+
12+
alias(
13+
name = "compiled_expr_utils_android",
14+
actual = "//testing/src/main/java/dev/cel/testing/compiled:compiled_expr_utils_android",
15+
)

0 commit comments

Comments
 (0)