Skip to content

Commit 89655d0

Browse files
bjacotgcopybara-github
authored andcommitted
Handle non-copyable type in (expect|verify)_(ne|eq)!
This is similar to the behavior and implementation of `assert_eq!(..., ...)` PiperOrigin-RevId: 656390256
1 parent c33408e commit 89655d0

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

googletest/src/assertions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -571,13 +571,13 @@ macro_rules! expect_false {
571571
#[macro_export]
572572
macro_rules! verify_eq {
573573
($actual:expr, [$($expected:expr),+ $(,)?] $(,)?) => {
574-
verify_that!($actual, [$($crate::matchers::eq(&$expected)),*])
574+
verify_that!(&$actual, [$($crate::matchers::eq(&$expected)),*])
575575
};
576576
($actual:expr, {$($expected:expr),+ $(,)?} $(,)?) => {
577-
verify_that!($actual, {$($crate::matchers::eq(&$expected)),*})
577+
verify_that!(&$actual, {$($crate::matchers::eq(&$expected)),*})
578578
};
579579
($actual:expr, $expected:expr $(,)?) => {
580-
verify_that!($actual, $crate::matchers::eq($expected))
580+
verify_that!(&$actual, $crate::matchers::eq(&$expected))
581581
};
582582
}
583583

@@ -681,7 +681,7 @@ macro_rules! expect_eq {
681681
#[macro_export]
682682
macro_rules! verify_ne {
683683
($actual:expr, $expected:expr $(,)?) => {
684-
verify_that!($actual, $crate::matchers::not($crate::matchers::eq($expected)))
684+
verify_that!(&$actual, $crate::matchers::not($crate::matchers::eq(&$expected)))
685685
};
686686
}
687687

integration_tests/src/integration_tests.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,13 @@ mod tests {
825825
verify_eq!(value, 2)
826826
}
827827

828+
#[googletest::test]
829+
fn verify_eq_with_non_copyable_type() -> Result<()> {
830+
#[derive(Debug, PartialEq)]
831+
struct NonCopyable(i32);
832+
verify_eq!(NonCopyable(123), NonCopyable(123))
833+
}
834+
828835
#[test]
829836
fn verify_eq_supports_trailing_comma() -> Result<()> {
830837
let value = 2;
@@ -926,6 +933,13 @@ mod tests {
926933
expect_eq!(value, 2);
927934
}
928935

936+
#[googletest::test]
937+
fn expect_eq_with_non_copyable_type() {
938+
#[derive(Debug, PartialEq)]
939+
struct NonCopyable(i32);
940+
expect_eq!(NonCopyable(123), NonCopyable(123));
941+
}
942+
929943
#[googletest::test]
930944
fn expect_eq_should_allow_multiple_calls() {
931945
expect_eq!(1, 1);
@@ -1090,6 +1104,13 @@ mod tests {
10901104
verify_ne!(value, 3)
10911105
}
10921106

1107+
#[googletest::test]
1108+
fn verify_ne_with_non_copyable_type() -> Result<()> {
1109+
#[derive(Debug, PartialEq)]
1110+
struct NonCopyable(i32);
1111+
verify_ne!(NonCopyable(123), NonCopyable(321))
1112+
}
1113+
10931114
#[test]
10941115
fn verify_ne_supports_trailing_comma() -> Result<()> {
10951116
let value = 2;
@@ -1116,6 +1137,13 @@ mod tests {
11161137
expect_ne!(1, 2);
11171138
}
11181139

1140+
#[googletest::test]
1141+
fn expect_ne_with_non_copyable_type() {
1142+
#[derive(Debug, PartialEq)]
1143+
struct NonCopyable(i32);
1144+
expect_ne!(NonCopyable(123), NonCopyable(321));
1145+
}
1146+
11191147
#[googletest::test]
11201148
fn expect_ne_should_allow_multiple_calls() {
11211149
expect_ne!(1, 2);

0 commit comments

Comments
 (0)