Skip to content

Commit 5bfa721

Browse files
author
Blaze Rules Copybara
committed
Merge pull request #69 from fmeum:tuple
PiperOrigin-RevId: 570652899
2 parents f906325 + 4025bcd commit 5bfa721

File tree

10 files changed

+47
-13
lines changed

10 files changed

+47
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
([#52](https://github.com/bazelbuild/rules_testing/issues/52))
1212
* StructSubject for asserting arbitrary structs.
1313
([#53](https://github.com/bazelbuild/rules_testing/issues/53))
14+
* CollectionSubject now supports tuples.
15+
([#69](https://github.com/bazelbuild/rules_testing/pull/69))
1416
* (docs) Created human-friendly changelog
1517

1618
## [0.3.0] - 2023-07-06

docgen/docgen.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

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

17-
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
1817
load("@bazel_skylib//rules:build_test.bzl", "build_test")
18+
load("@io_bazel_stardoc//stardoc:stardoc.bzl", "stardoc")
1919

2020
def sphinx_stardocs(name, bzl_libraries, **kwargs):
2121
"""Generate Sphinx-friendly markdown docs using Stardoc for bzl libraries.

lib/private/default_info_subject.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
"""# DefaultInfoSubject"""
1616

17-
load(":runfiles_subject.bzl", "RunfilesSubject")
1817
load(":depset_file_subject.bzl", "DepsetFileSubject")
1918
load(":file_subject.bzl", "FileSubject")
19+
load(":runfiles_subject.bzl", "RunfilesSubject")
2020

2121
def _default_info_subject_new(info, *, meta):
2222
"""Creates a `DefaultInfoSubject`

lib/private/truth_common.bzl

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,12 @@ def to_list(obj):
126126
"""Attempt to convert the object to a list, else error.
127127
128128
NOTE: This only supports objects that are typically understood as
129-
lists, not any iterable. Types like `dict` and `str` are iterable,
130-
but will be rejected.
129+
lists, not any iterable. Types like `dict` are iterable, but will
130+
be rejected.
131131
132132
Args:
133-
obj: ([`list`] | [`depset`]) The object to convert to a list.
133+
obj: ([`list`] | [`depset`] | [`tuple`]) The object to convert to a
134+
list.
134135
135136
Returns:
136137
[`list`] of the object
@@ -141,5 +142,7 @@ def to_list(obj):
141142
return obj
142143
elif types.is_depset(obj):
143144
return obj.to_list()
145+
elif types.is_tuple(obj):
146+
return list(obj)
144147
else:
145148
fail("Unable to convert to list: {}".format(repr_with_type(obj)))

lib/test_suite.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
Aggregates multiple Starlark tests in a single test_suite.
44
"""
55

6-
load("//lib/private:util.bzl", "get_test_name_from_function")
76
load("//lib:unit_test.bzl", "unit_test")
7+
load("//lib/private:util.bzl", "get_test_name_from_function")
88

99
def test_suite(name, *, tests = [], basic_tests = [], test_kwargs = {}):
1010
"""Instantiates given test macros/implementations and gathers their main targets into a `test_suite`.

lib/truth.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ load("//lib/private:expect.bzl", "Expect")
5151
load("//lib/private:file_subject.bzl", "FileSubject")
5252
load("//lib/private:int_subject.bzl", "IntSubject")
5353
load("//lib/private:label_subject.bzl", "LabelSubject")
54+
load("//lib/private:matching.bzl", _matching = "matching")
5455
load("//lib/private:runfiles_subject.bzl", "RunfilesSubject")
5556
load("//lib/private:str_subject.bzl", "StrSubject")
56-
load("//lib/private:target_subject.bzl", "TargetSubject")
57-
load("//lib/private:matching.bzl", _matching = "matching")
5857
load("//lib/private:struct_subject.bzl", "StructSubject")
58+
load("//lib/private:target_subject.bzl", "TargetSubject")
5959

6060
# Rather than load many symbols, just load this symbol, and then all the
6161
# asserts will be available.

tests/struct_subject/struct_subject_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
"""Tests for StructSubject"""
1616

17-
load("//lib:truth.bzl", "subjects")
1817
load("//lib:test_suite.bzl", "test_suite")
18+
load("//lib:truth.bzl", "subjects")
1919
load("//tests:test_util.bzl", "test_util")
2020

2121
_tests = []

tests/test_util.bzl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414

1515
"""Utilities for testing rules_testing code."""
1616

17+
load("//lib:truth.bzl", "matching")
18+
1719
# buildifier: disable=bzl-visibility
1820
load("//lib/private:expect_meta.bzl", "ExpectMeta")
19-
load("//lib:truth.bzl", "matching")
2021

2122
def _fake_meta(real_env):
2223
"""Create a fake ExpectMeta object for testing.

tests/truth_tests.bzl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
"""Tests for truth.bzl."""
1616

17-
load("@bazel_skylib//lib:unittest.bzl", ut_asserts = "asserts")
18-
load("//lib:truth.bzl", "matching", "subjects", "truth")
1917
load("//lib:analysis_test.bzl", "analysis_test", "test_suite")
18+
load("//lib:truth.bzl", "matching", "subjects", "truth")
19+
load("@bazel_skylib//lib:unittest.bzl", ut_asserts = "asserts")
2020

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

541+
subject = truth.expect(fake_env).that_collection(("one", "four", "three", "two", "five"))
542+
order = subject.contains_exactly(("one", "two", "three", "four", "five"))
543+
_assert_no_failures(
544+
fake_env,
545+
env = env,
546+
msg = "check same elements with expected in different order",
547+
)
548+
order.in_order()
549+
_assert_failure(
550+
fake_env,
551+
[
552+
"expected values all found, but with incorrect order:",
553+
"0: one found at offset 0",
554+
"1: two found at offset 3",
555+
"2: three found at offset 2",
556+
"3: four found at offset 1",
557+
"4: five found at offset 4",
558+
"actual values:",
559+
"0: one",
560+
"1: four",
561+
"2: three",
562+
"3: two",
563+
"4: five",
564+
],
565+
env = env,
566+
msg = "check same elements out of order",
567+
)
568+
541569
_end(env, fake_env)
542570

543571
_suite.append(collection_contains_exactly_test)

tests/unit_test_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Tests for unit_test."""
22

3-
load("//lib:unit_test.bzl", "unit_test")
43
load("//lib:test_suite.bzl", "test_suite")
4+
load("//lib:unit_test.bzl", "unit_test")
55

66
def _test_basic(env):
77
_ = env # @unused

0 commit comments

Comments
 (0)