Skip to content

Commit 5d442a8

Browse files
Merge pull request #306 from google:mangled_macros
PiperOrigin-RevId: 566231920
2 parents 8545024 + c56164a commit 5d442a8

13 files changed

+70
-44
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ version 1.66 for the best developer experience.
3030

3131
> :warning: The API is not fully stable and may still be changed until we
3232
> publish version 1.0.
33+
>
34+
> Moreover, any items or modules starting with `__` (double underscores) must
35+
> not be used directly. Those items or modules are only for internal uses and
36+
> their API may change without a major version update.
3337
3438
## Assertions and matchers
3539

googletest/crate_docs.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,38 +153,48 @@ The following matchers are provided in GoogleTest Rust:
153153
| [`superset_of`] | A container containing all elements of the argument. |
154154
| [`unordered_elements_are!`] | A container whose elements the arguments match, in any order. |
155155

156+
[`all!`]: matchers::all
157+
[`any!`]: matchers::any
156158
[`anything`]: matchers::anything
157159
[`approx_eq`]: matchers::approx_eq
158160
[`char_count`]: matchers::char_count
159161
[`container_eq`]: matchers::container_eq
160162
[`contains`]: matchers::contains
163+
[`contains_each!`]: matchers::contains_each
161164
[`contains_regex`]: matchers::contains_regex
162165
[`contains_substring`]: matchers::contains_substring
163166
[`displays_as`]: matchers::displays_as
164167
[`each`]: matchers::each
168+
[`elements_are!`]: matchers::elements_are
165169
[`empty`]: matchers::empty
166170
[`ends_with`]: matchers::ends_with
167171
[`eq`]: matchers::eq
168172
[`eq_deref_of`]: matchers::eq_deref_of
169173
[`err`]: matchers::err
174+
[`field!`]: matchers::field
170175
[`ge`]: matchers::ge
171176
[`gt`]: matchers::gt
172177
[`has_entry`]: matchers::has_entry
178+
[`is_contained_in!`]: matchers::is_contained_in
173179
[`is_nan`]: matchers::is_nan
174180
[`le`]: matchers::le
175181
[`len`]: matchers::len
176182
[`lt`]: matchers::lt
177183
[`matches_regex`]: matchers::matches_regex
184+
[`matches_pattern!`]: matchers::matches_pattern
178185
[`near`]: matchers::near
179186
[`none`]: matchers::none
180187
[`not`]: matchers::not
188+
[`pat!`]: matchers::pat
181189
[`ok`]: matchers::ok
182190
[`points_to`]: matchers::points_to
191+
[`pointwise!`]: matchers::pointwise
183192
[`predicate`]: matchers::predicate
184193
[`some`]: matchers::some
185194
[`starts_with`]: matchers::starts_with
186195
[`subset_of`]: matchers::subset_of
187196
[`superset_of`]: matchers::superset_of
197+
[`unordered_elements_are!`]: matchers::unordered_elements_are
188198
[`Deref`]: std::ops::Deref
189199
[`Display`]: std::fmt::Display
190200
[`HashMap`]: std::collections::HashMap

googletest/src/assertions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,15 @@ macro_rules! verify_that {
123123
($actual:expr, [$($expecteds:expr),+ $(,)?]) => {
124124
$crate::assertions::internal::check_matcher(
125125
&$actual,
126-
$crate::elements_are![$($expecteds),+],
126+
$crate::matchers::elements_are![$($expecteds),+],
127127
stringify!($actual),
128128
$crate::internal::source_location::SourceLocation::new(file!(), line!(), column!()),
129129
)
130130
};
131131
($actual:expr, {$($expecteds:expr),+ $(,)?}) => {
132132
$crate::assertions::internal::check_matcher(
133133
&$actual,
134-
$crate::unordered_elements_are![$($expecteds),+],
134+
$crate::matchers::unordered_elements_are![$($expecteds),+],
135135
stringify!($actual),
136136
$crate::internal::source_location::SourceLocation::new(file!(), line!(), column!()),
137137
)

googletest/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ pub mod prelude {
4949
pub use super::Result;
5050
// Assert macros
5151
pub use super::{assert_that, expect_pred, expect_that, fail, verify_pred, verify_that};
52-
// Matcher macros
53-
pub use super::{
54-
all, any, contains_each, elements_are, field, is_contained_in, matches_pattern, pat,
55-
pointwise, property, unordered_elements_are,
56-
};
5752
}
5853

5954
pub use googletest_macro::test;

googletest/src/matchers/all_matcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matcher module.
1717
#![doc(hidden)]
1818

1919
/// Matches a value which all of the given matchers match.
@@ -51,7 +51,8 @@
5151
///
5252
/// Assertion failure messages are not guaranteed to be identical, however.
5353
#[macro_export]
54-
macro_rules! all {
54+
#[doc(hidden)]
55+
macro_rules! __all {
5556
($($matcher:expr),* $(,)?) => {{
5657
use $crate::matchers::__internal_unstable_do_not_depend_on_these::AllMatcher;
5758
AllMatcher::new([$(Box::new($matcher)),*])

googletest/src/matchers/any_matcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matchers module.
1717
#![doc(hidden)]
1818

1919
/// Matches a value which at least one of the given matchers match.
@@ -53,7 +53,8 @@
5353
///
5454
/// Assertion failure messages are not guaranteed to be identical, however.
5555
#[macro_export]
56-
macro_rules! any {
56+
#[doc(hidden)]
57+
macro_rules! __any {
5758
($($matcher:expr),* $(,)?) => {{
5859
use $crate::matchers::__internal_unstable_do_not_depend_on_these::AnyMatcher;
5960
AnyMatcher::new([$(Box::new($matcher)),*])

googletest/src/matchers/elements_are_matcher.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matchers module.
1717
#![doc(hidden)]
1818

1919
/// Matches a container's elements to each matcher in order.
@@ -50,7 +50,7 @@
5050
///
5151
/// Note: This behavior is only possible in [`verify_that!`] macros. In any
5252
/// other cases, it is still necessary to use the
53-
/// [`elements_are!`][crate::elements_are] macro.
53+
/// [`elements_are!`][crate::matchers::elements_are] macro.
5454
///
5555
/// ```compile_fail
5656
/// # use googletest::prelude::*;
@@ -69,15 +69,17 @@
6969
/// match against an iterator, use [`Iterator::collect`] to build a [`Vec`].
7070
///
7171
/// Do not use this with unordered containers, since that will lead to flaky
72-
/// tests. Use [`unordered_elements_are!`][crate::unordered_elements_are]
72+
/// tests. Use
73+
/// [`unordered_elements_are!`][crate::matchers::unordered_elements_are]
7374
/// instead.
7475
///
7576
/// [`IntoIterator`]: std::iter::IntoIterator
7677
/// [`Iterator`]: std::iter::Iterator
7778
/// [`Iterator::collect`]: std::iter::Iterator::collect
7879
/// [`Vec`]: std::vec::Vec
7980
#[macro_export]
80-
macro_rules! elements_are {
81+
#[doc(hidden)]
82+
macro_rules! __elements_are {
8183
($($matcher:expr),* $(,)?) => {{
8284
use $crate::matchers::__internal_unstable_do_not_depend_on_these::ElementsAre;
8385
ElementsAre::new(vec![$(Box::new($matcher)),*])

googletest/src/matchers/field_matcher.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matchers module.
1717
#![doc(hidden)]
1818

1919
/// Matches a structure or enum with a given field which is matched by a given
@@ -105,10 +105,11 @@
105105
/// # }
106106
/// ```
107107
///
108-
/// See also the macro [`property`][crate::property] for an analogous mechanism
109-
/// to extract a datum by invoking a method.
108+
/// See also the macro [`property`][crate::matchers::property] for an analogous
109+
/// mechanism to extract a datum by invoking a method.
110110
#[macro_export]
111-
macro_rules! field {
111+
#[doc(hidden)]
112+
macro_rules! __field {
112113
($($t:tt)*) => { $crate::field_internal!($($t)*) }
113114
}
114115

googletest/src/matchers/matches_pattern.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matchers module.
1717
#![doc(hidden)]
1818

1919
/// Matches a value according to a pattern of matchers.
@@ -91,7 +91,8 @@
9191
/// # .unwrap();
9292
/// ```
9393
///
94-
/// One can use the alias [`pat`][crate::pat] to make this less verbose:
94+
/// One can use the alias [`pat`][crate::matchers::pat] to make this less
95+
/// verbose:
9596
///
9697
/// ```
9798
/// # use googletest::prelude::*;
@@ -246,7 +247,8 @@
246247
/// # .unwrap();
247248
/// ```
248249
#[macro_export]
249-
macro_rules! matches_pattern {
250+
#[doc(hidden)]
251+
macro_rules! __matches_pattern {
250252
($($t:tt)*) => { $crate::matches_pattern_internal!($($t)*) }
251253
}
252254

@@ -587,13 +589,14 @@ macro_rules! matches_pattern_internal {
587589

588590
($first:tt $($rest:tt)*) => {{
589591
#[allow(unused)]
590-
use $crate::{all, field, property};
592+
use $crate::matchers::{all, field, property};
591593
$crate::matches_pattern_internal!([$first], $($rest)*)
592594
}};
593595
}
594596

595-
/// An alias for [`matches_pattern`].
597+
/// An alias for [`matches_pattern`][crate::matchers::matches_pattern!].
596598
#[macro_export]
597-
macro_rules! pat {
599+
#[doc(hidden)]
600+
macro_rules! __pat {
598601
($($t:tt)*) => { $crate::matches_pattern_internal!($($t)*) }
599602
}

googletest/src/matchers/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ pub use str_matcher::{
8888
pub use subset_of_matcher::subset_of;
8989
pub use superset_of_matcher::superset_of;
9090

91-
// Reexport of macros.
92-
// TODO Consider hiding the matchers macro from the top-level, by either
93-
// mangling or move them to the macro crate.
91+
// Reexport and unmangle the macros.
92+
#[doc(inline)]
9493
pub use crate::{
95-
all, any, contains_each, elements_are, field, is_contained_in, matches_pattern, pat, pointwise,
96-
property, unordered_elements_are,
94+
__all as all, __any as any, __contains_each as contains_each, __elements_are as elements_are,
95+
__field as field, __is_contained_in as is_contained_in, __matches_pattern as matches_pattern,
96+
__pat as pat, __pointwise as pointwise, __property as property,
97+
__unordered_elements_are as unordered_elements_are,
9798
};
9899

99100
// Types and functions used by macros matchers.

googletest/src/matchers/pointwise_matcher.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matcher module.
1717
#![doc(hidden)]
1818

1919
/// Generates a matcher which matches a container each of whose elements match
@@ -115,7 +115,8 @@
115115
/// [`Pointwise`]: https://google.github.io/googletest/reference/matchers.html#container-matchers
116116
/// [`Vec`]: std::vec::Vec
117117
#[macro_export]
118-
macro_rules! pointwise {
118+
#[doc(hidden)]
119+
macro_rules! __pointwise {
119120
($matcher:expr, $container:expr) => {{
120121
use $crate::matchers::__internal_unstable_do_not_depend_on_these::PointwiseMatcher;
121122
PointwiseMatcher::new($container.into_iter().map($matcher).collect())

googletest/src/matchers/property_matcher.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matcher module.
1717
#![doc(hidden)]
1818

1919
/// Matches an object which, upon calling the given method on it with the given
@@ -96,13 +96,14 @@
9696
/// # .unwrap();
9797
/// ```
9898
///
99-
/// This macro is analogous to [`field`][crate::field], except that it extracts
100-
/// the datum to be matched from the given object by invoking a method rather
101-
/// than accessing a field.
99+
/// This macro is analogous to [`field`][crate::matchers::field], except that it
100+
/// extracts the datum to be matched from the given object by invoking a method
101+
/// rather than accessing a field.
102102
///
103103
/// The list of arguments may optionally have a trailing comma.
104104
#[macro_export]
105-
macro_rules! property {
105+
#[doc(hidden)]
106+
macro_rules! __property {
106107
($($t:tt)*) => { $crate::property_internal!($($t)*) }
107108
}
108109

googletest/src/matchers/unordered_elements_are_matcher.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// limitations under the License.
1414

1515
// There are no visible documentation elements in this module; the declarative
16-
// macro is documented at the top level.
16+
// macro is documented in the matchers module.
1717
#![doc(hidden)]
1818

1919
/// Matches a container whose elements in any order have a 1:1 correspondence
@@ -73,7 +73,7 @@
7373
///
7474
/// Note: This behavior is only possible in [`verify_that!`] macros. In any
7575
/// other cases, it is still necessary to use the
76-
/// [`unordered_elements_are!`][crate::unordered_elements_are] macro.
76+
/// [`unordered_elements_are!`][crate::matchers::unordered_elements_are] macro.
7777
///
7878
/// ```compile_fail
7979
/// # use googletest::prelude::*;
@@ -115,7 +115,8 @@
115115
/// [`Iterator::collect`]: std::iter::Iterator::collect
116116
/// [`Vec`]: std::vec::Vec
117117
#[macro_export]
118-
macro_rules! unordered_elements_are {
118+
#[doc(hidden)]
119+
macro_rules! __unordered_elements_are {
119120
($(,)?) => {{
120121
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
121122
UnorderedElementsAreMatcher, Requirements
@@ -151,7 +152,9 @@ macro_rules! unordered_elements_are {
151152
/// additional elements that don't correspond to any matcher.
152153
///
153154
/// Put another way, `contains_each!` matches if there is a subset of the actual
154-
/// container which [`unordered_elements_are`] would match.
155+
/// container which
156+
/// [`unordered_elements_are`][crate::matchers::unordered_elements_are] would
157+
/// match.
155158
///
156159
/// ```
157160
/// # use googletest::prelude::*;
@@ -217,7 +220,8 @@ macro_rules! unordered_elements_are {
217220
/// [`Iterator::collect`]: std::iter::Iterator::collect
218221
/// [`Vec`]: std::vec::Vec
219222
#[macro_export]
220-
macro_rules! contains_each {
223+
#[doc(hidden)]
224+
macro_rules! __contains_each {
221225
($(,)?) => {{
222226
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
223227
UnorderedElementsAreMatcher, Requirements
@@ -255,7 +259,8 @@ macro_rules! contains_each {
255259
/// container.
256260
///
257261
/// Put another way, `is_contained_in!` matches if there is a subset of the
258-
/// matchers which would match with [`unordered_elements_are`].
262+
/// matchers which would match with
263+
/// [`unordered_elements_are`][crate::matchers::unordered_elements_are].
259264
///
260265
/// ```
261266
/// # use googletest::prelude::*;
@@ -323,7 +328,8 @@ macro_rules! contains_each {
323328
/// [`Iterator::collect`]: std::iter::Iterator::collect
324329
/// [`Vec`]: std::vec::Vec
325330
#[macro_export]
326-
macro_rules! is_contained_in {
331+
#[doc(hidden)]
332+
macro_rules! __is_contained_in {
327333
($(,)?) => {{
328334
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
329335
UnorderedElementsAreMatcher, Requirements

0 commit comments

Comments
 (0)