Skip to content

Commit 45e6aa1

Browse files
l46kokcopybara-github
authored andcommitted
Open source Java conformance tests
PiperOrigin-RevId: 660137130
1 parent 06dec78 commit 45e6aa1

13 files changed

Lines changed: 814 additions & 16 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,7 @@ jobs:
3232
- name: Bazel Output Version
3333
run: bazelisk --version
3434
- name: Bazel Test
35-
run: bazelisk test ... --deleted_packages=codelab/src/test/codelab --test_output=errors # Exclude codelab exercises as they are intentionally made to fail
35+
# Exclude codelab exercises as they are intentionally made to fail
36+
# Exclude conformance tests for time being until TextFormat.Parser fix is in upstream
37+
run: bazelisk test ... --deleted_packages=//codelab/src/test/codelab,//conformance/src/test/java/dev/cel/conformance --test_output=errors
3638
- run: echo "🍏 This job's status is ${{ job.status }}."

WORKSPACE

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ http_archive(
149149
# cel-spec api/expr canonical protos
150150
http_archive(
151151
name = "cel_spec",
152-
sha256 = "3ee09eb69dbe77722e9dee23dc48dc2cd9f765869fcf5ffb1226587c81791a0b",
153-
strip_prefix = "cel-spec-0.15.0",
152+
sha256 = "65a153c1c4d73a135c364a4955e6aabd1093f0ed291774d3637f350504505085",
153+
strip_prefix = "cel-spec-0789389e13a0626ec3521e4f109acce360565ce6",
154154
urls = [
155-
"https://github.com/google/cel-spec/archive/refs/tags/v0.15.0.tar.gz",
155+
"https://github.com/google/cel-spec/archive/0789389e13a0626ec3521e4f109acce360565ce6.tar.gz",
156156
],
157157
)
158158

checker/src/main/java/dev/cel/checker/CelProtoExprVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import dev.cel.common.CelProtoAbstractSyntaxTree;
1919

2020
/**
21-
* CEL expression visitor implementation based on the {@link com.google.api.expr.Expr} proto.
21+
* CEL expression visitor implementation based on the {@link dev.cel.expr.Expr} proto.
2222
*
2323
* <p>Note: Prefer using {@link dev.cel.common.ast.CelExprVisitor} if protobuf support is not
2424
* needed.

common/src/main/java/dev/cel/common/CelProtoAbstractSyntaxTree.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ private CelProtoAbstractSyntaxTree(CelAbstractSyntaxTree ast) {
104104
this.checkedExpr = checkedExprBuilder.build();
105105
}
106106

107-
/** Construct an abstract syntax tree from a {@link com.google.api.expr.CheckedExpr}. */
107+
/** Construct an abstract syntax tree from a {@link dev.cel.expr.CheckedExpr}. */
108108
public static CelProtoAbstractSyntaxTree fromCheckedExpr(CheckedExpr checkedExpr) {
109109
return new CelProtoAbstractSyntaxTree(checkedExpr);
110110
}
111111

112-
/** Construct an abstract syntax tree from a {@link com.google.api.expr.ParsedExpr}. */
112+
/** Construct an abstract syntax tree from a {@link dev.cel.expr.ParsedExpr}. */
113113
public static CelProtoAbstractSyntaxTree fromParsedExpr(ParsedExpr parsedExpr) {
114114
return new CelProtoAbstractSyntaxTree(
115115
CheckedExpr.newBuilder()
@@ -137,7 +137,7 @@ public CelAbstractSyntaxTree getAst() {
137137
}
138138

139139
/**
140-
* Returns the underlying {@link com.google.api.expr.Expr} representation of the abstract syntax
140+
* Returns the underlying {@link dev.cel.expr.Expr} representation of the abstract syntax
141141
* tree.
142142
*/
143143
@CheckReturnValue
@@ -146,7 +146,7 @@ public Expr getExpr() {
146146
}
147147

148148
/**
149-
* Returns the underlying {@link com.google.api.expr.CheckedExpr} representation of the abstract
149+
* Returns the underlying {@link dev.cel.expr.CheckedExpr} representation of the abstract
150150
* syntax tree. Throws {@link java.lang.IllegalStateException} if {@link
151151
* CelAbstractSyntaxTree#isChecked} is false.
152152
*/
@@ -159,7 +159,7 @@ public CheckedExpr toCheckedExpr() {
159159
}
160160

161161
/**
162-
* Returns the underlying {@link com.google.api.expr.SourceInfo} representation of the abstract
162+
* Returns the underlying {@link dev.cel.expr.SourceInfo} representation of the abstract
163163
* syntax tree.
164164
*/
165165
@CheckReturnValue
@@ -168,7 +168,7 @@ public SourceInfo getSourceInfo() {
168168
}
169169

170170
/**
171-
* Returns the underlying {@link com.google.api.expr.ParsedExpr} representation of the abstract
171+
* Returns the underlying {@link dev.cel.expr.ParsedExpr} representation of the abstract
172172
* syntax tree.
173173
*/
174174
@CheckReturnValue

common/src/main/java/dev/cel/common/internal/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.PrimitiveIterator;
2727

2828
/**
29-
* Internal utility class for working with {@link com.google.api.expr.Constant}.
29+
* Internal utility class for working with {@link dev.cel.expr.Constant}.
3030
*
3131
* <p>CEL Library Internals. Do Not Use.
3232
*/

common/src/main/java/dev/cel/common/internal/DefaultInstanceMessageFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* <p>CEL Library Internals. Do Not Use.
3939
*/
4040
@Internal
41-
final class DefaultInstanceMessageFactory {
41+
public final class DefaultInstanceMessageFactory {
4242

4343
// Controls how many times we should recursively inspect a nested message for building fully
4444
// qualified java class name before aborting.
@@ -87,7 +87,7 @@ public Optional<Message> getPrototype(Descriptor descriptor) {
8787
* Retrieves the full Java class name from the given descriptor
8888
*
8989
* @return fully qualified class name.
90-
* <p>Example 1: com.google.api.expr.Value
90+
* <p>Example 1: dev.cel.expr.Value
9191
* <p>Example 2: com.google.rpc.context.AttributeContext$Resource (Nested classes)
9292
* <p>Example 3: com.google.api.expr.cel.internal.testdata$SingleFileProto$SingleFile$Path
9393
* (Nested class with java multiple files disabled)
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
load("//conformance/src/test/java/dev/cel/conformance:conformance_test.bzl", "conformance_test")
2+
3+
package(default_applicable_licenses = [
4+
"//:license",
5+
])
6+
7+
exports_files([
8+
"conformance_test.bzl",
9+
"conformance_test.sh",
10+
])
11+
12+
java_library(
13+
name = "run",
14+
testonly = True,
15+
srcs = glob(["*.java"]),
16+
deps = [
17+
"//:java_truth",
18+
"//checker:checker_builder",
19+
"//common",
20+
"//common:compiler_common",
21+
"//common:options",
22+
"//common/internal:default_instance_message_factory",
23+
"//common/types",
24+
"//common/types:type_providers",
25+
"//compiler",
26+
"//extensions",
27+
"//extensions:optional_library",
28+
"//parser",
29+
"//parser:macro",
30+
"//parser:parser_builder",
31+
"//runtime",
32+
"@@protobuf~//java/core",
33+
"@cel_spec//proto/cel/expr:expr_java_proto",
34+
"@cel_spec//proto/test/v1:simple_java_proto",
35+
"@cel_spec//proto/test/v1/proto2:test_all_types_java_proto",
36+
"@cel_spec//proto/test/v1/proto3:test_all_types_java_proto",
37+
"@com_google_googleapis//google/api/expr/v1alpha1:expr_java_proto",
38+
"@maven//:com_google_guava_guava",
39+
"@maven//:com_google_truth_extensions_truth_proto_extension",
40+
"@maven//:junit_junit",
41+
],
42+
)
43+
44+
_ALL_TESTS = [
45+
"@cel_spec//tests/simple:testdata/basic.textproto",
46+
"@cel_spec//tests/simple:testdata/bindings_ext.textproto",
47+
"@cel_spec//tests/simple:testdata/comparisons.textproto",
48+
"@cel_spec//tests/simple:testdata/conversions.textproto",
49+
"@cel_spec//tests/simple:testdata/dynamic.textproto",
50+
"@cel_spec//tests/simple:testdata/encoders_ext.textproto",
51+
"@cel_spec//tests/simple:testdata/enums.textproto",
52+
"@cel_spec//tests/simple:testdata/fields.textproto",
53+
"@cel_spec//tests/simple:testdata/fp_math.textproto",
54+
"@cel_spec//tests/simple:testdata/integer_math.textproto",
55+
"@cel_spec//tests/simple:testdata/lists.textproto",
56+
"@cel_spec//tests/simple:testdata/logic.textproto",
57+
"@cel_spec//tests/simple:testdata/macros.textproto",
58+
"@cel_spec//tests/simple:testdata/math_ext.textproto",
59+
"@cel_spec//tests/simple:testdata/namespace.textproto",
60+
"@cel_spec//tests/simple:testdata/optionals.textproto",
61+
"@cel_spec//tests/simple:testdata/parse.textproto",
62+
"@cel_spec//tests/simple:testdata/plumbing.textproto",
63+
"@cel_spec//tests/simple:testdata/proto2.textproto",
64+
"@cel_spec//tests/simple:testdata/proto3.textproto",
65+
"@cel_spec//tests/simple:testdata/proto2_ext.textproto",
66+
"@cel_spec//tests/simple:testdata/string.textproto",
67+
"@cel_spec//tests/simple:testdata/string_ext.textproto",
68+
"@cel_spec//tests/simple:testdata/timestamps.textproto",
69+
"@cel_spec//tests/simple:testdata/unknowns.textproto",
70+
"@cel_spec//tests/simple:testdata/wrappers.textproto",
71+
]
72+
73+
_TESTS_TO_SKIP = [
74+
# Tests which require spec changes.
75+
# TODO: Deprecate Duration.get_milliseconds
76+
"timestamps/duration_converters/get_milliseconds",
77+
78+
# Broken test cases which should be supported.
79+
# TODO: Invalid bytes to string conversion should error.
80+
"conversions/string/bytes_invalid",
81+
# TODO: Support setting / getting enum values out of the defined enum value range.
82+
"enums/legacy_proto2/select_big,select_neg",
83+
"enums/legacy_proto2/assign_standalone_int_big,assign_standalone_int_neg",
84+
# TODO: Generate errors on enum value assignment overflows for proto3.
85+
"enums/legacy_proto3/assign_standalone_int_too_big,assign_standalone_int_too_neg",
86+
# TODO: Ensure overflow occurs on conversions of double values which might not work properly on all platforms.
87+
"conversions/int/double_int_min_range",
88+
# TODO: Duration and timestamp operations should error on overflow.
89+
"timestamps/duration_range/from_string_under,from_string_over",
90+
"timestamps/timestamp_range/sub_time_duration_over,sub_time_duration_under",
91+
# TODO: Ensure adding negative duration values is appropriately supported.
92+
"timestamps/timestamp_arithmetic/add_time_to_duration_nanos_negative",
93+
94+
# Skip until fixed.
95+
"wrappers/field_mask/to_json",
96+
"wrappers/empty/to_json",
97+
"wrappers/duration/to_json",
98+
"wrappers/timestamp/to_json",
99+
"fields/qualified_identifier_resolution/map_value_repeat_key_heterogeneous",
100+
# TODO: Add strings.quote.
101+
"string_ext/quote",
102+
103+
# TODO: Fix null assignment to a field
104+
"proto2/set_null/single_message",
105+
"proto2/set_null/single_duration",
106+
"proto2/set_null/single_timestamp",
107+
"proto3/set_null/single_message",
108+
"proto3/set_null/single_duration",
109+
"proto3/set_null/single_timestamp",
110+
111+
# Future features for CEL 1.0
112+
# TODO: Strong typing support for enums, specified but not implemented.
113+
"enums/strong_proto2",
114+
"enums/strong_proto3",
115+
116+
# com.google.protobuf.TextFormat does not conform to the spec. Unknown enum values are supposed
117+
# to be allowed in proto3. Currently they are rejected.
118+
# "enums/legacy_proto3/select_big",
119+
# "enums/legacy_proto3/select_neg",
120+
# "enums/legacy_proto3/assign_standalone_int_big",
121+
# "enums/legacy_proto3/assign_standalone_int_neg",
122+
123+
# Not yet implemented.
124+
"math_ext/ceil",
125+
"math_ext/floor",
126+
"math_ext/round",
127+
"math_ext/trunc",
128+
"math_ext/abs",
129+
"math_ext/sign",
130+
"math_ext/isNaN",
131+
"math_ext/isInf",
132+
"math_ext/isFinite",
133+
"math_ext/bit_and",
134+
"math_ext/bit_or",
135+
"math_ext/bit_xor",
136+
"math_ext/bit_not",
137+
"math_ext/bit_shift_left",
138+
"math_ext/bit_shift_right",
139+
]
140+
141+
conformance_test(
142+
name = "conformance",
143+
dashboard = False,
144+
data = _ALL_TESTS,
145+
skip_tests = _TESTS_TO_SKIP,
146+
)
147+
148+
conformance_test(
149+
name = "conformance_dashboard",
150+
dashboard = True,
151+
data = _ALL_TESTS,
152+
)

0 commit comments

Comments
 (0)