Skip to content

Commit cc5d3e7

Browse files
bjacotgcopybara-github
authored andcommitted
Reexport macros-internal types in matchers::__internal_unstable_do_not_depend_on_these.
This simplifies the structure of the matchers module and centralize it in matchers/mod.rs. PiperOrigin-RevId: 563683578
1 parent 911fe63 commit cc5d3e7

10 files changed

+66
-38
lines changed

googletest/src/matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
1717
use crate::internal::source_location::SourceLocation;
1818
use crate::internal::test_outcome::TestAssertionFailure;
19-
use crate::matchers::conjunction_matcher::ConjunctionMatcher;
20-
use crate::matchers::disjunction_matcher::DisjunctionMatcher;
19+
use crate::matchers::__internal_unstable_do_not_depend_on_these::ConjunctionMatcher;
20+
use crate::matchers::__internal_unstable_do_not_depend_on_these::DisjunctionMatcher;
2121
use std::fmt::Debug;
2222

2323
/// An interface for checking an arbitrary condition on a datum.

googletest/src/matchers/all_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
#[macro_export]
5454
macro_rules! all {
5555
($($matcher:expr),* $(,)?) => {{
56-
use $crate::matchers::all_matcher::internal::AllMatcher;
56+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::AllMatcher;
5757
AllMatcher::new([$(Box::new($matcher)),*])
5858
}}
5959
}

googletest/src/matchers/any_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#[macro_export]
5656
macro_rules! any {
5757
($($matcher:expr),* $(,)?) => {{
58-
use $crate::matchers::any_matcher::internal::AnyMatcher;
58+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::AnyMatcher;
5959
AnyMatcher::new([$(Box::new($matcher)),*])
6060
}}
6161
}

googletest/src/matchers/elements_are_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
#[macro_export]
8080
macro_rules! elements_are {
8181
($($matcher:expr),* $(,)?) => {{
82-
use $crate::matchers::elements_are_matcher::internal::ElementsAre;
82+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::ElementsAre;
8383
ElementsAre::new(vec![$(Box::new($matcher)),*])
8484
}}
8585
}

googletest/src/matchers/field_matcher.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ macro_rules! field {
118118
#[macro_export]
119119
macro_rules! field_internal {
120120
($($t:ident)::+.$field:tt, $m:expr) => {{
121-
use $crate::matchers::field_matcher::internal::field_matcher;
121+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::field_matcher;
122122
field_matcher(
123123
|o| {
124124
match o {

googletest/src/matchers/matches_pattern.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ macro_rules! matches_pattern_internal {
259259
[$($struct_name:tt)*],
260260
{ $field_name:ident : $matcher:expr $(,)? }
261261
) => {
262-
$crate::matchers::is_matcher::is(
262+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(
263263
stringify!($($struct_name)*),
264264
all!(field!($($struct_name)*.$field_name, $matcher))
265265
)
@@ -269,7 +269,7 @@ macro_rules! matches_pattern_internal {
269269
[$($struct_name:tt)*],
270270
{ $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
271271
) => {
272-
$crate::matchers::is_matcher::is(
272+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(
273273
stringify!($($struct_name)*),
274274
all!(property!($($struct_name)*.$property_name($($argument),*), $matcher))
275275
)
@@ -279,7 +279,7 @@ macro_rules! matches_pattern_internal {
279279
[$($struct_name:tt)*],
280280
{ ref $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
281281
) => {
282-
$crate::matchers::is_matcher::is(
282+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(
283283
stringify!($($struct_name)*),
284284
all!(property!(ref $($struct_name)*.$property_name($($argument),*), $matcher))
285285
)
@@ -323,7 +323,7 @@ macro_rules! matches_pattern_internal {
323323
[$($struct_name:tt)*],
324324
{ $field_name:ident : $matcher:expr $(,)? }
325325
) => {
326-
$crate::matchers::is_matcher::is(stringify!($($struct_name)*), all!(
326+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(stringify!($($struct_name)*), all!(
327327
$($processed)*,
328328
field!($($struct_name)*.$field_name, $matcher)
329329
))
@@ -334,7 +334,7 @@ macro_rules! matches_pattern_internal {
334334
[$($struct_name:tt)*],
335335
{ $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
336336
) => {
337-
$crate::matchers::is_matcher::is(stringify!($($struct_name)*), all!(
337+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(stringify!($($struct_name)*), all!(
338338
$($processed)*,
339339
property!($($struct_name)*.$property_name($($argument),*), $matcher)
340340
))
@@ -345,7 +345,7 @@ macro_rules! matches_pattern_internal {
345345
[$($struct_name:tt)*],
346346
{ ref $property_name:ident($($argument:expr),* $(,)?) : $matcher:expr $(,)? }
347347
) => {
348-
$crate::matchers::is_matcher::is(stringify!($($struct_name)*), all!(
348+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(stringify!($($struct_name)*), all!(
349349
$($processed)*,
350350
property!(ref $($struct_name)*.$property_name($($argument),*), $matcher)
351351
))
@@ -410,7 +410,7 @@ macro_rules! matches_pattern_internal {
410410
[$($struct_name:tt)*],
411411
($matcher:expr $(,)?)
412412
) => {
413-
$crate::matchers::is_matcher::is(
413+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(
414414
stringify!($($struct_name)*),
415415
all!(field!($($struct_name)*.0, $matcher))
416416
)
@@ -436,7 +436,7 @@ macro_rules! matches_pattern_internal {
436436
$field:tt,
437437
($matcher:expr $(,)?)
438438
) => {
439-
$crate::matchers::is_matcher::is(stringify!($($struct_name)*), all!(
439+
$crate::matchers::__internal_unstable_do_not_depend_on_these::is(stringify!($($struct_name)*), all!(
440440
$($processed)*,
441441
field!($($struct_name)*.$field, $matcher)
442442
))

googletest/src/matchers/mod.rs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,27 @@
1414

1515
//! All built-in matchers of this crate are in submodules of this module.
1616
17-
pub mod all_matcher;
18-
pub mod any_matcher;
17+
mod all_matcher;
18+
mod any_matcher;
1919
mod anything_matcher;
2020
mod char_count_matcher;
21-
pub mod conjunction_matcher;
21+
mod conjunction_matcher;
2222
mod container_eq_matcher;
2323
mod contains_matcher;
2424
mod contains_regex_matcher;
25-
pub mod disjunction_matcher;
25+
mod disjunction_matcher;
2626
mod display_matcher;
2727
mod each_matcher;
28-
pub mod elements_are_matcher;
28+
mod elements_are_matcher;
2929
mod empty_matcher;
3030
mod eq_deref_of_matcher;
3131
mod eq_matcher;
3232
mod err_matcher;
33-
pub mod field_matcher;
33+
mod field_matcher;
3434
mod ge_matcher;
3535
mod gt_matcher;
3636
mod has_entry_matcher;
37-
pub mod is_matcher;
37+
mod is_matcher;
3838
mod is_nan_matcher;
3939
mod le_matcher;
4040
mod len_matcher;
@@ -46,15 +46,15 @@ mod none_matcher;
4646
mod not_matcher;
4747
mod ok_matcher;
4848
mod points_to_matcher;
49-
pub mod pointwise_matcher;
49+
mod pointwise_matcher;
5050
mod predicate_matcher;
51-
pub mod property_matcher;
51+
mod property_matcher;
5252
mod some_matcher;
5353
mod str_matcher;
5454
mod subset_of_matcher;
5555
mod superset_of_matcher;
5656
mod tuple_matcher;
57-
pub mod unordered_elements_are_matcher;
57+
mod unordered_elements_are_matcher;
5858

5959
pub use anything_matcher::anything;
6060
pub use char_count_matcher::char_count;
@@ -87,3 +87,31 @@ pub use str_matcher::{
8787
};
8888
pub use subset_of_matcher::subset_of;
8989
pub use superset_of_matcher::superset_of;
90+
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.
94+
pub use crate::{
95+
all, any, contains_each, elements_are, field, is_contained_in, matches_pattern, pat, pointwise,
96+
property, unordered_elements_are,
97+
};
98+
99+
// Types and functions used by macros matchers.
100+
// Do not use directly.
101+
// We may perform incompatible changes without major release. These elements
102+
// should only be used through their respective macros.
103+
#[doc(hidden)]
104+
pub mod __internal_unstable_do_not_depend_on_these {
105+
pub use super::all_matcher::internal::AllMatcher;
106+
pub use super::any_matcher::internal::AnyMatcher;
107+
pub use super::conjunction_matcher::ConjunctionMatcher;
108+
pub use super::disjunction_matcher::DisjunctionMatcher;
109+
pub use super::elements_are_matcher::internal::ElementsAre;
110+
pub use super::field_matcher::internal::field_matcher;
111+
pub use super::is_matcher::is;
112+
pub use super::pointwise_matcher::internal::PointwiseMatcher;
113+
pub use super::property_matcher::internal::{property_matcher, property_ref_matcher};
114+
pub use super::unordered_elements_are_matcher::internal::{
115+
Requirements, UnorderedElementsAreMatcher, UnorderedElementsOfMapAreMatcher,
116+
};
117+
}

googletest/src/matchers/pointwise_matcher.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,12 @@
117117
#[macro_export]
118118
macro_rules! pointwise {
119119
($matcher:expr, $container:expr) => {{
120-
use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher;
120+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::PointwiseMatcher;
121121
PointwiseMatcher::new($container.into_iter().map($matcher).collect())
122122
}};
123123

124124
($matcher:expr, $left_container:expr, $right_container:expr) => {{
125-
use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher;
125+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::PointwiseMatcher;
126126
PointwiseMatcher::new(
127127
$left_container
128128
.into_iter()
@@ -133,7 +133,7 @@ macro_rules! pointwise {
133133
}};
134134

135135
($matcher:expr, $left_container:expr, $middle_container:expr, $right_container:expr) => {{
136-
use $crate::matchers::pointwise_matcher::internal::PointwiseMatcher;
136+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::PointwiseMatcher;
137137
PointwiseMatcher::new(
138138
$left_container
139139
.into_iter()

googletest/src/matchers/property_matcher.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,15 +113,15 @@ macro_rules! property {
113113
#[macro_export]
114114
macro_rules! property_internal {
115115
($($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{
116-
use $crate::matchers::property_matcher::internal::property_matcher;
116+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::property_matcher;
117117
property_matcher(
118118
|o: &$($t)::+| o.$method($($argument),*),
119119
&stringify!($method($($argument),*)),
120120
$m)
121121
}};
122122

123123
(ref $($t:ident)::+.$method:tt($($argument:tt),* $(,)?), $m:expr) => {{
124-
use $crate::matchers::property_matcher::internal::property_ref_matcher;
124+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::property_ref_matcher;
125125
property_ref_matcher(
126126
|o: &$($t)::+| o.$method($($argument),*),
127127
&stringify!($method($($argument),*)),

googletest/src/matchers/unordered_elements_are_matcher.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
#[macro_export]
118118
macro_rules! unordered_elements_are {
119119
($(,)?) => {{
120-
use $crate::matchers::unordered_elements_are_matcher::internal::{
120+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
121121
UnorderedElementsAreMatcher, Requirements
122122
};
123123
UnorderedElementsAreMatcher::new([], Requirements::PerfectMatch)
@@ -126,7 +126,7 @@ macro_rules! unordered_elements_are {
126126
// TODO: Consider an alternative map-like syntax here similar to that used in
127127
// https://crates.io/crates/maplit.
128128
($(($key_matcher:expr, $value_matcher:expr)),* $(,)?) => {{
129-
use $crate::matchers::unordered_elements_are_matcher::internal::{
129+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
130130
UnorderedElementsOfMapAreMatcher, Requirements
131131
};
132132
UnorderedElementsOfMapAreMatcher::new(
@@ -136,7 +136,7 @@ macro_rules! unordered_elements_are {
136136
}};
137137

138138
($($matcher:expr),* $(,)?) => {{
139-
use $crate::matchers::unordered_elements_are_matcher::internal::{
139+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
140140
UnorderedElementsAreMatcher, Requirements
141141
};
142142
UnorderedElementsAreMatcher::new([$(Box::new($matcher)),*], Requirements::PerfectMatch)
@@ -219,7 +219,7 @@ macro_rules! unordered_elements_are {
219219
#[macro_export]
220220
macro_rules! contains_each {
221221
($(,)?) => {{
222-
use $crate::matchers::unordered_elements_are_matcher::internal::{
222+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
223223
UnorderedElementsAreMatcher, Requirements
224224
};
225225
UnorderedElementsAreMatcher::new([], Requirements::Superset)
@@ -228,7 +228,7 @@ macro_rules! contains_each {
228228
// TODO: Consider an alternative map-like syntax here similar to that used in
229229
// https://crates.io/crates/maplit.
230230
($(($key_matcher:expr, $value_matcher:expr)),* $(,)?) => {{
231-
use $crate::matchers::unordered_elements_are_matcher::internal::{
231+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
232232
UnorderedElementsOfMapAreMatcher, Requirements
233233
};
234234
UnorderedElementsOfMapAreMatcher::new(
@@ -238,7 +238,7 @@ macro_rules! contains_each {
238238
}};
239239

240240
($($matcher:expr),* $(,)?) => {{
241-
use $crate::matchers::unordered_elements_are_matcher::internal::{
241+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
242242
UnorderedElementsAreMatcher, Requirements
243243
};
244244
UnorderedElementsAreMatcher::new([$(Box::new($matcher)),*], Requirements::Superset)
@@ -325,7 +325,7 @@ macro_rules! contains_each {
325325
#[macro_export]
326326
macro_rules! is_contained_in {
327327
($(,)?) => {{
328-
use $crate::matchers::unordered_elements_are_matcher::internal::{
328+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
329329
UnorderedElementsAreMatcher, Requirements
330330
};
331331
UnorderedElementsAreMatcher::new([], Requirements::Subset)
@@ -334,7 +334,7 @@ macro_rules! is_contained_in {
334334
// TODO: Consider an alternative map-like syntax here similar to that used in
335335
// https://crates.io/crates/maplit.
336336
($(($key_matcher:expr, $value_matcher:expr)),* $(,)?) => {{
337-
use $crate::matchers::unordered_elements_are_matcher::internal::{
337+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
338338
UnorderedElementsOfMapAreMatcher, Requirements
339339
};
340340
UnorderedElementsOfMapAreMatcher::new(
@@ -344,7 +344,7 @@ macro_rules! is_contained_in {
344344
}};
345345

346346
($($matcher:expr),* $(,)?) => {{
347-
use $crate::matchers::unordered_elements_are_matcher::internal::{
347+
use $crate::matchers::__internal_unstable_do_not_depend_on_these::{
348348
UnorderedElementsAreMatcher, Requirements
349349
};
350350
UnorderedElementsAreMatcher::new([$(Box::new($matcher)),*], Requirements::Subset)

0 commit comments

Comments
 (0)