Skip to content

Commit e004c38

Browse files
l46kokcopybara-github
authored andcommitted
Add protolite tests for Android
PiperOrigin-RevId: 749966327
1 parent 5499b4b commit e004c38

File tree

12 files changed

+670
-43
lines changed

12 files changed

+670
-43
lines changed

compiler/src/main/java/dev/cel/compiler/tools/CelCompilerTool.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ public Integer call() {
143143
} catch (Exception e) {
144144
String errorMessage =
145145
String.format(
146-
"Expression [%s] failed to compile. Reason: %s", celExpression, e.getMessage());
146+
"\nFailed to compile CEL Expression: [%s].\nReason: %s\n\n",
147+
celExpression, e.getMessage());
147148
System.err.print(errorMessage);
148149
return -1;
149150
}

protobuf/src/test/java/dev/cel/protobuf/CelLiteDescriptorTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818

1919
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
20-
import dev.cel.expr.conformance.proto3.TestAllTypesLiteCelDescriptor;
20+
import dev.cel.expr.conformance.proto3.TestAllTypesProto3LiteCelDescriptor;
2121
import dev.cel.protobuf.CelLiteDescriptor.FieldLiteDescriptor;
2222
import dev.cel.protobuf.CelLiteDescriptor.FieldLiteDescriptor.CelFieldValueType;
2323
import dev.cel.protobuf.CelLiteDescriptor.FieldLiteDescriptor.JavaType;
@@ -29,8 +29,8 @@
2929
@RunWith(TestParameterInjector.class)
3030
public class CelLiteDescriptorTest {
3131

32-
private static final TestAllTypesLiteCelDescriptor TEST_ALL_TYPES_CEL_LITE_DESCRIPTOR =
33-
TestAllTypesLiteCelDescriptor.getDescriptor();
32+
private static final TestAllTypesProto3LiteCelDescriptor TEST_ALL_TYPES_CEL_LITE_DESCRIPTOR =
33+
TestAllTypesProto3LiteCelDescriptor.getDescriptor();
3434

3535
@Test
3636
public void getProtoTypeNamesToDescriptors_containsAllMessages() {

runtime/BUILD.bazel

+5
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ java_library(
145145
exports = ["//runtime/src/main/java/dev/cel/runtime:unknown_attributes"],
146146
)
147147

148+
cel_android_library(
149+
name = "unknown_attributes_android",
150+
exports = ["//runtime/src/main/java/dev/cel/runtime:unknown_attributes_android"],
151+
)
152+
148153
java_library(
149154
name = "unknown_options",
150155
exports = ["//runtime/src/main/java/dev/cel/runtime:unknown_options"],

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,8 @@ java_library(
837837
cel_android_library(
838838
name = "unknown_attributes_android",
839839
srcs = UNKNOWN_ATTRIBUTE_SOURCES,
840-
visibility = ["//visibility:private"],
840+
tags = [
841+
],
841842
deps = [
842843
"//:auto_value",
843844
"@maven//:com_google_errorprone_error_prone_annotations",

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

+133-8
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,114 @@ compile_cel(
4040
expression = "''.isEmpty() && [].isEmpty()",
4141
)
4242

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+
43151
filegroup(
44152
name = "compiled_exprs",
45153
# keep sorted
@@ -50,9 +158,25 @@ filegroup(
50158
":compiled_list_literal",
51159
":compiled_one_plus_two",
52160
":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",
53173
],
54174
)
55175

176+
ANDROID_TESTS = [
177+
"CelLiteRuntimeAndroidTest.java",
178+
]
179+
56180
java_library(
57181
name = "tests",
58182
testonly = 1,
@@ -62,7 +186,7 @@ java_library(
62186
exclude = [
63187
"CelValueInterpreterTest.java",
64188
"InterpreterTest.java",
65-
],
189+
] + ANDROID_TESTS,
66190
),
67191
resources = [":compiled_exprs"],
68192
deps = [
@@ -76,7 +200,6 @@ java_library(
76200
"//common:compiler_common",
77201
"//common:error_codes",
78202
"//common:options",
79-
"//common:proto_ast",
80203
"//common:proto_v1alpha1_ast",
81204
"//common:runtime_exception",
82205
"//common/ast",
@@ -108,7 +231,6 @@ java_library(
108231
"//runtime:interpreter_util",
109232
"//runtime:lite_runtime",
110233
"//runtime:lite_runtime_factory",
111-
"//runtime:lite_runtime_impl",
112234
"//runtime:proto_message_activation_factory",
113235
"//runtime:proto_message_runtime_equality",
114236
"//runtime:proto_message_runtime_helpers",
@@ -120,7 +242,6 @@ java_library(
120242
"//runtime:unknown_options",
121243
"//testing:test_all_types_cel_java_proto2",
122244
"//testing:test_all_types_cel_java_proto3",
123-
"@cel_spec//proto/cel/expr:checked_java_proto",
124245
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto",
125246
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto",
126247
"@com_google_googleapis//google/api/expr/v1alpha1:expr_java_proto",
@@ -166,24 +287,28 @@ java_library(
166287

167288
cel_android_local_test(
168289
name = "android_tests",
169-
srcs = ["CelLiteRuntimeAndroidTest.java"],
290+
srcs = ANDROID_TESTS,
170291
resources = [":compiled_exprs"],
171292
test_class = "dev.cel.runtime.CelLiteRuntimeAndroidTest",
172293
deps = [
173294
"//:java_truth",
174295
"//common:cel_ast_android",
175-
"//common:cel_source_android",
176296
"//common:options",
177297
"//common:proto_ast_android",
178-
"//common/ast:ast_android",
179-
"//common/types:types_android",
298+
"//common/values:proto_message_lite_value_provider_android",
180299
"//runtime:evaluation_exception",
181300
"//runtime:function_binding_android",
182301
"//runtime:lite_runtime_android",
183302
"//runtime:lite_runtime_factory_android",
184303
"//runtime:lite_runtime_impl_android",
185304
"//runtime:standard_functions_android",
305+
"//runtime:unknown_attributes_android",
306+
"//testing:test_all_types_cel_java_proto2_lite",
307+
"//testing:test_all_types_cel_java_proto3_lite",
186308
"@cel_spec//proto/cel/expr:checked_java_proto_lite",
309+
"@cel_spec//proto/cel/expr/conformance/proto2:test_all_types_java_proto_lite",
310+
"@cel_spec//proto/cel/expr/conformance/proto3:test_all_types_java_proto_lite",
311+
"@maven//:com_google_protobuf_protobuf_java_util",
187312
"@maven//:com_google_testparameterinjector_test_parameter_injector",
188313
"@maven_android//:com_google_guava_guava",
189314
"@maven_android//:com_google_protobuf_protobuf_javalite",

0 commit comments

Comments
 (0)