Skip to content

Commit 02b521f

Browse files
authored
cleanup(tests): Use new APIs in rules_testing 0.4.0 (bazel-contrib#1307)
* Use public APIs for DictSubject and StrSubject. * Use rules_testing's StructSubject instead of our own. Work towards 1297
1 parent 95ad6cc commit 02b521f

File tree

3 files changed

+13
-70
lines changed

3 files changed

+13
-70
lines changed

tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,10 @@ def _py_cc_toolchain_test_impl(env, target):
4444
)
4545
toolchain.python_version().equals("3.999")
4646

47-
toolchain_headers = toolchain.headers()
48-
toolchain_headers.providers_map().keys().contains_exactly(["CcInfo", "DefaultInfo"])
47+
headers_providers = toolchain.headers().providers_map()
48+
headers_providers.keys().contains_exactly(["CcInfo", "DefaultInfo"])
4949

50-
cc_info = cc_info_subject(
51-
# TODO: Use DictSubject.get once available,
52-
# https://github.com/bazelbuild/rules_testing/issues/51
53-
toolchain_headers.actual.providers_map["CcInfo"],
54-
meta = env.expect.meta.derive(expr = "cc_info"),
55-
)
50+
cc_info = headers_providers.get("CcInfo", factory = cc_info_subject)
5651

5752
compilation_context = cc_info.compilation_context()
5853
compilation_context.direct_headers().contains_exactly([
@@ -68,8 +63,11 @@ def _py_cc_toolchain_test_impl(env, target):
6863
matching.str_matches("*/fake_include"),
6964
])
7065

66+
# TODO: Once subjects.default_info is available, do
67+
# default_info = headers_providers.get("DefaultInfo", factory=subjects.default_info)
68+
# https://github.com/bazelbuild/rules_python/issues/1297
7169
default_info = default_info_subject(
72-
toolchain_headers.actual.providers_map["DefaultInfo"],
70+
headers_providers.get("DefaultInfo", factory = lambda v, meta: v),
7371
meta = env.expect.meta.derive(expr = "default_info"),
7472
)
7573
default_info.runfiles().contains_predicate(

tests/py_cc_toolchain_info_subject.bzl

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@
1313
# limitations under the License.
1414
"""PyCcToolchainInfo testing subject."""
1515

16-
# TODO: Load this through truth.bzl#subjects when made available
17-
# https://github.com/bazelbuild/rules_testing/issues/54
18-
load("@rules_testing//lib/private:dict_subject.bzl", "DictSubject") # buildifier: disable=bzl-visibility
19-
20-
# TODO: Load this through truth.bzl#subjects when made available
21-
# https://github.com/bazelbuild/rules_testing/issues/54
22-
load("@rules_testing//lib/private:str_subject.bzl", "StrSubject") # buildifier: disable=bzl-visibility
23-
load(":struct_subject.bzl", "struct_subject")
16+
load("@rules_testing//lib:truth.bzl", "subjects")
2417

2518
def _py_cc_toolchain_info_subject_new(info, *, meta):
2619
# buildifier: disable=uninitialized
@@ -33,14 +26,16 @@ def _py_cc_toolchain_info_subject_new(info, *, meta):
3326
return public
3427

3528
def _py_cc_toolchain_info_subject_headers(self):
36-
return struct_subject(
29+
return subjects.struct(
3730
self.actual.headers,
3831
meta = self.meta.derive("headers()"),
39-
providers_map = DictSubject.new,
32+
attrs = dict(
33+
providers_map = subjects.dict,
34+
),
4035
)
4136

4237
def _py_cc_toolchain_info_subject_python_version(self):
43-
return StrSubject.new(
38+
return subjects.str(
4439
self.actual.python_version,
4540
meta = self.meta.derive("python_version()"),
4641
)

tests/struct_subject.bzl

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy