Skip to content

Commit c13878c

Browse files
Googlercopybara-github
authored andcommitted
Move general pattern to the end to avoid accidental processing before the sequence-specialized cases.
We want to put the sequence-specialized cases up front, so that they are first checked before falling through to the general cases. PiperOrigin-RevId: 695348636
1 parent e1abbb8 commit c13878c

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

googletest/src/assertions.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
/// not supported; see [Rust by Example](https://doc.rust-lang.org/rust-by-example/primitives/tuples.html#tuples).
121121
#[macro_export]
122122
macro_rules! verify_that {
123+
// specialized to sequences:
123124
($actual:expr, [$($expecteds:expr),+ $(,)?]) => {
124125
{
125126
use $crate::assertions::internal::Subject as _;
@@ -129,6 +130,8 @@ macro_rules! verify_that {
129130
)
130131
}
131132
};
133+
134+
// specialized to unordered sequences:
132135
($actual:expr, {$($expecteds:expr),+ $(,)?}) => {
133136
{
134137
use $crate::assertions::internal::Subject as _;
@@ -138,6 +141,8 @@ macro_rules! verify_that {
138141
)
139142
}
140143
};
144+
145+
// general case:
141146
($actual:expr, $expected:expr $(,)?) => {
142147
{
143148
use $crate::assertions::internal::Subject as _;
@@ -1373,12 +1378,6 @@ macro_rules! expect_that {
13731378
$crate::verify_that!($actual, {$($expected),*}).and_log_failure();
13741379
}};
13751380

1376-
// general case:
1377-
($actual:expr, $expected:expr $(,)?) => {{
1378-
use $crate::GoogleTestSupport as _;
1379-
$crate::verify_that!($actual, $expected).and_log_failure();
1380-
}};
1381-
13821381
// w/ format args, specialized to sequence:
13831382
($actual:expr, [$($expected:expr),*], $($format_args:expr),* $(,)?) => {
13841383
use $crate::GoogleTestSupport as _;
@@ -1395,6 +1394,12 @@ macro_rules! expect_that {
13951394
.and_log_failure()
13961395
};
13971396

1397+
// general case:
1398+
($actual:expr, $expected:expr $(,)?) => {{
1399+
use $crate::GoogleTestSupport as _;
1400+
$crate::verify_that!($actual, $expected).and_log_failure();
1401+
}};
1402+
13981403
// w/ format args, general case:
13991404
($actual:expr, $expected:expr, $($format_args:expr),* $(,)?) => {
14001405
use $crate::GoogleTestSupport as _;

integration_tests/src/integration_tests.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ mod tests {
106106
expect_that!(vec![1, 2], [eq(&1), eq(&2)], "A custom error message");
107107
}
108108

109+
#[gtest]
110+
fn expect_that_with_unordered_elements_supports_custom_error_msg() {
111+
expect_that!(vec![1, 2], {eq(&2), eq(&1)}, "A custom error message");
112+
}
113+
109114
#[gtest]
110115
fn should_fail_on_assertion_failure() -> Result<()> {
111116
let status = run_external_process("simple_assertion_failure").status()?;

0 commit comments

Comments
 (0)