Skip to content

Commit 0df32f4

Browse files
committed
Fix the matches_pattern! macro.
The last release included a change which redirected matches_pattern! to matches_pattern_internal!. It did not fix the references inside the macros themselves to use $crate::matches_pattern_internal!. This worked fine in contexts where matches_pattern_internal! was already imported, but does not work in general client code where it is not. This change adds the $crate qualifier to each invocation of matches_pattern_internal!. This also moves the tests of matches_pattern! out of the module and into a new integration test (see https://doc.rust-lang.org/rust-by-example/testing/integration_testing.html). This causes the tests to be compiled from outside the crate itself, precluding this type of bug in the future. Fixes #86
1 parent 57e70da commit 0df32f4

File tree

3 files changed

+444
-14
lines changed

3 files changed

+444
-14
lines changed

googletest/src/matchers/matches_pattern.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ macro_rules! matches_pattern_internal {
132132
[$($struct_name:tt)*],
133133
{ $field_name:ident : $matcher:expr, $($rest:tt)* }
134134
) => {
135-
matches_pattern_internal!(
135+
$crate::matches_pattern_internal!(
136136
all!(field!($($struct_name)*.$field_name, $matcher)),
137137
[$($struct_name)*],
138138
{ $($rest)* }
@@ -155,7 +155,7 @@ macro_rules! matches_pattern_internal {
155155
[$($struct_name:tt)*],
156156
{ $field_name:ident : $matcher:expr, $($rest:tt)* }
157157
) => {
158-
matches_pattern_internal!(
158+
$crate::matches_pattern_internal!(
159159
all!(
160160
$($processed)*,
161161
field!($($struct_name)*.$field_name, $matcher)
@@ -187,7 +187,7 @@ macro_rules! matches_pattern_internal {
187187
[$($struct_name:tt)*],
188188
($matcher:expr, $($rest:tt)*)
189189
) => {
190-
matches_pattern_internal!(
190+
$crate::matches_pattern_internal!(
191191
all!(
192192
field!($($struct_name)*.0, $matcher)
193193
),
@@ -218,7 +218,7 @@ macro_rules! matches_pattern_internal {
218218
1,
219219
($matcher:expr, $($rest:tt)*)
220220
) => {
221-
matches_pattern_internal!(
221+
$crate::matches_pattern_internal!(
222222
all!(
223223
$($processed)*,
224224
field!($($struct_name)*.1, $matcher)
@@ -235,7 +235,7 @@ macro_rules! matches_pattern_internal {
235235
2,
236236
($matcher:expr, $($rest:tt)*)
237237
) => {
238-
matches_pattern_internal!(
238+
$crate::matches_pattern_internal!(
239239
all!(
240240
$($processed)*,
241241
field!($($struct_name)*.2, $matcher)
@@ -252,7 +252,7 @@ macro_rules! matches_pattern_internal {
252252
3,
253253
($matcher:expr, $($rest:tt)*)
254254
) => {
255-
matches_pattern_internal!(
255+
$crate::matches_pattern_internal!(
256256
all!(
257257
$($processed)*,
258258
field!($($struct_name)*.3, $matcher)
@@ -269,7 +269,7 @@ macro_rules! matches_pattern_internal {
269269
4,
270270
($matcher:expr, $($rest:tt)*)
271271
) => {
272-
matches_pattern_internal!(
272+
$crate::matches_pattern_internal!(
273273
all!(
274274
$($processed)*,
275275
field!($($struct_name)*.4, $matcher)
@@ -286,7 +286,7 @@ macro_rules! matches_pattern_internal {
286286
5,
287287
($matcher:expr, $($rest:tt)*)
288288
) => {
289-
matches_pattern_internal!(
289+
$crate::matches_pattern_internal!(
290290
all!(
291291
$($processed)*,
292292
field!($($struct_name)*.5, $matcher)
@@ -303,7 +303,7 @@ macro_rules! matches_pattern_internal {
303303
6,
304304
($matcher:expr, $($rest:tt)*)
305305
) => {
306-
matches_pattern_internal!(
306+
$crate::matches_pattern_internal!(
307307
all!(
308308
$($processed)*,
309309
field!($($struct_name)*.6, $matcher)
@@ -320,7 +320,7 @@ macro_rules! matches_pattern_internal {
320320
7,
321321
($matcher:expr, $($rest:tt)*)
322322
) => {
323-
matches_pattern_internal!(
323+
$crate::matches_pattern_internal!(
324324
all!(
325325
$($processed)*,
326326
field!($($struct_name)*.7, $matcher)
@@ -337,7 +337,7 @@ macro_rules! matches_pattern_internal {
337337
8,
338338
($matcher:expr, $($rest:tt)*)
339339
) => {
340-
matches_pattern_internal!(
340+
$crate::matches_pattern_internal!(
341341
all!(
342342
$($processed)*,
343343
field!($($struct_name)*.8, $matcher)
@@ -349,7 +349,7 @@ macro_rules! matches_pattern_internal {
349349
};
350350

351351
([$($struct_name:tt)*], $first:tt $($rest:tt)*) => {
352-
matches_pattern_internal!([$($struct_name)* $first], $($rest)*)
352+
$crate::matches_pattern_internal!([$($struct_name)* $first], $($rest)*)
353353
};
354354

355355
($first:tt $($rest:tt)*) => {{
@@ -362,14 +362,14 @@ macro_rules! matches_pattern_internal {
362362
#[cfg(google3)]
363363
#[allow(unused)]
364364
use field_matcher::field;
365-
matches_pattern_internal!([$first], $($rest)*)
365+
$crate::matches_pattern_internal!([$first], $($rest)*)
366366
}};
367367
}
368368

369369
/// An alias for [`matches_pattern`].
370370
#[macro_export]
371371
macro_rules! pat {
372-
($($t:tt)*) => { matches_pattern_internal!($($t)*) }
372+
($($t:tt)*) => { $crate::matches_pattern_internal!($($t)*) }
373373
}
374374

375375
#[cfg(test)]

googletest/tests/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2023 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
mod matches_pattern_test;

0 commit comments

Comments
 (0)