-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathrun.bzl
More file actions
127 lines (118 loc) · 4.68 KB
/
run.bzl
File metadata and controls
127 lines (118 loc) · 4.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
This module contains build rules for generating the conformance test targets.
"""
load("@rules_cc//cc:cc_test.bzl", "cc_test")
_TESTS_TO_SKIP_WINDOWS = [
# These tests depend on configuring a timezone database which isn't available in our windows
# test environment.
"timestamps/timestamp_selectors_tz/getDate",
"timestamps/timestamp_selectors_tz/getDayOfMonth_name_pos",
"timestamps/timestamp_selectors_tz/getDayOfMonth_name_neg",
"timestamps/timestamp_selectors_tz/getDayOfYear",
"timestamps/timestamp_selectors_tz/getMinutes",
]
# Converts the list of tests to skip from the format used by the original Go test runner to a single
# flag value where each test is separated by a comma. It also performs expansion, for example
# `foo/bar,baz` becomes two entries which are `foo/bar` and `foo/baz`.
def _expand_tests_to_skip(tests_to_skip):
result = []
for test_to_skip in tests_to_skip:
comma = test_to_skip.find(",")
if comma == -1:
result.append(test_to_skip)
continue
slash = test_to_skip.rfind("/", 0, comma)
if slash == -1:
slash = 0
else:
slash = slash + 1
for part in test_to_skip[slash:].split(","):
result.append(test_to_skip[0:slash] + part)
return result
def _conformance_test_name(name, optimize, recursive):
return "_".join(
[
name,
"optimized" if optimize else "unoptimized",
"recursive" if recursive else "iterative",
],
)
def _conformance_test_args(modern, optimize, recursive, select_opt, skip_check, skip_tests, dashboard):
args = []
if modern:
args.append("--modern")
if optimize:
args.append("--opt")
if select_opt:
args.append("--select_optimization")
if recursive:
args.append("--recursive")
if skip_check:
args.append("--skip_check")
else:
args.append("--noskip_check")
args.append("--skip_tests={}".format(",".join(_expand_tests_to_skip(skip_tests))))
if dashboard:
args.append("--dashboard")
return args
def _conformance_test(name, data, modern, optimize, recursive, select_opt, skip_check, skip_tests, tags, dashboard):
cc_test(
name = _conformance_test_name(name, optimize, recursive),
args = _conformance_test_args(modern, optimize, recursive, select_opt, skip_check, skip_tests, dashboard) + ["$(location " + test + ")" for test in data] + select(
{
"@platforms//os:windows": ["--skip_tests={}".format(",".join(skip_tests + _TESTS_TO_SKIP_WINDOWS))],
"//conditions:default": ["--skip_tests={}".format(",".join(skip_tests))],
},
),
data = data,
deps = ["//conformance:run"],
tags = tags,
)
def gen_conformance_tests(name, data, modern = False, checked = False, select_opt = False, dashboard = False, skip_tests = [], tags = []):
"""Generates conformance tests.
Args:
name: prefix for all tests
modern: run using modern APIs
checked: whether to apply type checking
data: textproto targets describing conformance tests
skip_tests: tests to skip in the format of the cel-spec test runner. See documentation
in github.com/google/cel-spec/tests/simple/simple_test.go
tags: tags added to the generated targets
dashboard: enable dashboard mode
"""
skip_check = not checked
tests = []
for optimize in (True, False):
for recursive in (True, False):
test_name = _conformance_test_name(name, optimize, recursive)
tests.append(test_name)
_conformance_test(
name,
data,
modern = modern,
optimize = optimize,
recursive = recursive,
select_opt = select_opt,
skip_check = skip_check,
skip_tests = _expand_tests_to_skip(skip_tests),
tags = tags,
dashboard = dashboard,
)
native.test_suite(
name = name,
tests = tests,
tags = tags,
)