Skip to content

Commit

Permalink
cleanup(tests): Use new APIs in rules_testing 0.4.0 (#1307)
Browse files Browse the repository at this point in the history
* Use public APIs for DictSubject and StrSubject.
* Use rules_testing's StructSubject instead of our own.

Work towards 1297
  • Loading branch information
rickeylev authored Jul 11, 2023
1 parent 95ad6cc commit 02b521f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 70 deletions.
16 changes: 7 additions & 9 deletions tests/cc/py_cc_toolchain/py_cc_toolchain_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,10 @@ def _py_cc_toolchain_test_impl(env, target):
)
toolchain.python_version().equals("3.999")

toolchain_headers = toolchain.headers()
toolchain_headers.providers_map().keys().contains_exactly(["CcInfo", "DefaultInfo"])
headers_providers = toolchain.headers().providers_map()
headers_providers.keys().contains_exactly(["CcInfo", "DefaultInfo"])

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

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

# TODO: Once subjects.default_info is available, do
# default_info = headers_providers.get("DefaultInfo", factory=subjects.default_info)
# https://github.com/bazelbuild/rules_python/issues/1297
default_info = default_info_subject(
toolchain_headers.actual.providers_map["DefaultInfo"],
headers_providers.get("DefaultInfo", factory = lambda v, meta: v),
meta = env.expect.meta.derive(expr = "default_info"),
)
default_info.runfiles().contains_predicate(
Expand Down
17 changes: 6 additions & 11 deletions tests/py_cc_toolchain_info_subject.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@
# limitations under the License.
"""PyCcToolchainInfo testing subject."""

# TODO: Load this through truth.bzl#subjects when made available
# https://github.com/bazelbuild/rules_testing/issues/54
load("@rules_testing//lib/private:dict_subject.bzl", "DictSubject") # buildifier: disable=bzl-visibility

# TODO: Load this through truth.bzl#subjects when made available
# https://github.com/bazelbuild/rules_testing/issues/54
load("@rules_testing//lib/private:str_subject.bzl", "StrSubject") # buildifier: disable=bzl-visibility
load(":struct_subject.bzl", "struct_subject")
load("@rules_testing//lib:truth.bzl", "subjects")

def _py_cc_toolchain_info_subject_new(info, *, meta):
# buildifier: disable=uninitialized
Expand All @@ -33,14 +26,16 @@ def _py_cc_toolchain_info_subject_new(info, *, meta):
return public

def _py_cc_toolchain_info_subject_headers(self):
return struct_subject(
return subjects.struct(
self.actual.headers,
meta = self.meta.derive("headers()"),
providers_map = DictSubject.new,
attrs = dict(
providers_map = subjects.dict,
),
)

def _py_cc_toolchain_info_subject_python_version(self):
return StrSubject.new(
return subjects.str(
self.actual.python_version,
meta = self.meta.derive("python_version()"),
)
Expand Down
50 changes: 0 additions & 50 deletions tests/struct_subject.bzl

This file was deleted.

0 comments on commit 02b521f

Please sign in to comment.