Skip to content

Commit

Permalink
Merge pull request #69 from fmeum:tuple
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 570652899
  • Loading branch information
Blaze Rules Copybara committed Oct 4, 2023
2 parents f906325 + 4025bcd commit 5bfa721
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
([#52](https://github.com/bazelbuild/rules_testing/issues/52))
* StructSubject for asserting arbitrary structs.
([#53](https://github.com/bazelbuild/rules_testing/issues/53))
* CollectionSubject now supports tuples.
([#69](https://github.com/bazelbuild/rules_testing/pull/69))
* (docs) Created human-friendly changelog

## [0.3.0] - 2023-07-06
Expand Down
2 changes: 1 addition & 1 deletion docgen/docgen.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

"""Rules to help generate rules_testing docs."""

load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")

def sphinx_stardocs(name, bzl_libraries, **kwargs):
"""Generate Sphinx-friendly markdown docs using Stardoc for bzl libraries.
Expand Down
2 changes: 1 addition & 1 deletion lib/private/default_info_subject.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""# DefaultInfoSubject"""

load(":runfiles_subject.bzl", "RunfilesSubject")
load(":depset_file_subject.bzl", "DepsetFileSubject")
load(":file_subject.bzl", "FileSubject")
load(":runfiles_subject.bzl", "RunfilesSubject")

def _default_info_subject_new(info, *, meta):
"""Creates a `DefaultInfoSubject`
Expand Down
9 changes: 6 additions & 3 deletions lib/private/truth_common.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,12 @@ def to_list(obj):
"""Attempt to convert the object to a list, else error.
NOTE: This only supports objects that are typically understood as
lists, not any iterable. Types like `dict` and `str` are iterable,
but will be rejected.
lists, not any iterable. Types like `dict` are iterable, but will
be rejected.
Args:
obj: ([`list`] | [`depset`]) The object to convert to a list.
obj: ([`list`] | [`depset`] | [`tuple`]) The object to convert to a
list.
Returns:
[`list`] of the object
Expand All @@ -141,5 +142,7 @@ def to_list(obj):
return obj
elif types.is_depset(obj):
return obj.to_list()
elif types.is_tuple(obj):
return list(obj)
else:
fail("Unable to convert to list: {}".format(repr_with_type(obj)))
2 changes: 1 addition & 1 deletion lib/test_suite.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
Aggregates multiple Starlark tests in a single test_suite.
"""

load("//lib/private:util.bzl", "get_test_name_from_function")
load("//lib:unit_test.bzl", "unit_test")
load("//lib/private:util.bzl", "get_test_name_from_function")

def test_suite(name, *, tests = [], basic_tests = [], test_kwargs = {}):
"""Instantiates given test macros/implementations and gathers their main targets into a `test_suite`.
Expand Down
4 changes: 2 additions & 2 deletions lib/truth.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ load("//lib/private:expect.bzl", "Expect")
load("//lib/private:file_subject.bzl", "FileSubject")
load("//lib/private:int_subject.bzl", "IntSubject")
load("//lib/private:label_subject.bzl", "LabelSubject")
load("//lib/private:matching.bzl", _matching = "matching")
load("//lib/private:runfiles_subject.bzl", "RunfilesSubject")
load("//lib/private:str_subject.bzl", "StrSubject")
load("//lib/private:target_subject.bzl", "TargetSubject")
load("//lib/private:matching.bzl", _matching = "matching")
load("//lib/private:struct_subject.bzl", "StructSubject")
load("//lib/private:target_subject.bzl", "TargetSubject")

# Rather than load many symbols, just load this symbol, and then all the
# asserts will be available.
Expand Down
2 changes: 1 addition & 1 deletion tests/struct_subject/struct_subject_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

"""Tests for StructSubject"""

load("//lib:truth.bzl", "subjects")
load("//lib:test_suite.bzl", "test_suite")
load("//lib:truth.bzl", "subjects")
load("//tests:test_util.bzl", "test_util")

_tests = []
Expand Down
3 changes: 2 additions & 1 deletion tests/test_util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@

"""Utilities for testing rules_testing code."""

load("//lib:truth.bzl", "matching")

# buildifier: disable=bzl-visibility
load("//lib/private:expect_meta.bzl", "ExpectMeta")
load("//lib:truth.bzl", "matching")

def _fake_meta(real_env):
"""Create a fake ExpectMeta object for testing.
Expand Down
32 changes: 30 additions & 2 deletions tests/truth_tests.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

"""Tests for truth.bzl."""

load("@bazel_skylib//lib:unittest.bzl", ut_asserts = "asserts")
load("//lib:truth.bzl", "matching", "subjects", "truth")
load("//lib:analysis_test.bzl", "analysis_test", "test_suite")
load("//lib:truth.bzl", "matching", "subjects", "truth")
load("@bazel_skylib//lib:unittest.bzl", ut_asserts = "asserts")

# Bazel 5 has a bug where every access of testing.ExecutionInfo is a new
# object that isn't equal to itself. This is fixed in Bazel 6.
Expand Down Expand Up @@ -538,6 +538,34 @@ def _collection_contains_exactly_test(env, _target):
msg = "check same elements out of order",
)

subject = truth.expect(fake_env).that_collection(("one", "four", "three", "two", "five"))
order = subject.contains_exactly(("one", "two", "three", "four", "five"))
_assert_no_failures(
fake_env,
env = env,
msg = "check same elements with expected in different order",
)
order.in_order()
_assert_failure(
fake_env,
[
"expected values all found, but with incorrect order:",
"0: one found at offset 0",
"1: two found at offset 3",
"2: three found at offset 2",
"3: four found at offset 1",
"4: five found at offset 4",
"actual values:",
"0: one",
"1: four",
"2: three",
"3: two",
"4: five",
],
env = env,
msg = "check same elements out of order",
)

_end(env, fake_env)

_suite.append(collection_contains_exactly_test)
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_test_tests.bzl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Tests for unit_test."""

load("//lib:unit_test.bzl", "unit_test")
load("//lib:test_suite.bzl", "test_suite")
load("//lib:unit_test.bzl", "unit_test")

def _test_basic(env):
_ = env # @unused
Expand Down

0 comments on commit 5bfa721

Please sign in to comment.