Skip to content

Commit

Permalink
Handle non-copyable type in (expect|verify)_(ne|eq)!
Browse files Browse the repository at this point in the history
This is similar to the behavior and implementation of `assert_eq!(..., ...)`

PiperOrigin-RevId: 656301261
  • Loading branch information
bjacotg authored and copybara-github committed Jul 26, 2024
1 parent cccc94a commit 07dffcf
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
8 changes: 4 additions & 4 deletions googletest/src/assertions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,13 +571,13 @@ macro_rules! expect_false {
#[macro_export]
macro_rules! verify_eq {
($actual:expr, [$($expected:expr),+ $(,)?] $(,)?) => {
verify_that!($actual, [$($crate::matchers::eq(&$expected)),*])
verify_that!(&$actual, [$($crate::matchers::eq(&$expected)),*])
};
($actual:expr, {$($expected:expr),+ $(,)?} $(,)?) => {
verify_that!($actual, {$($crate::matchers::eq(&$expected)),*})
verify_that!(&$actual, {$($crate::matchers::eq(&$expected)),*})
};
($actual:expr, $expected:expr $(,)?) => {
verify_that!($actual, $crate::matchers::eq($expected))
verify_that!(&$actual, $crate::matchers::eq(&$expected))
};
}

Expand Down Expand Up @@ -681,7 +681,7 @@ macro_rules! expect_eq {
#[macro_export]
macro_rules! verify_ne {
($actual:expr, $expected:expr $(,)?) => {
verify_that!($actual, $crate::matchers::not($crate::matchers::eq($expected)))
verify_that!(&$actual, $crate::matchers::not($crate::matchers::eq(&$expected)))
};
}

Expand Down
28 changes: 28 additions & 0 deletions integration_tests/src/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,13 @@ mod tests {
verify_eq!(value, 2)
}

#[googletest::test]
fn verify_eq_with_non_copyable_type() -> Result<()> {
#[derive(Debug, PartialEq)]
struct NonCopyable(i32);
verify_eq!(NonCopyable(123), NonCopyable(123))
}

#[test]
fn verify_eq_supports_trailing_comma() -> Result<()> {
let value = 2;
Expand Down Expand Up @@ -926,6 +933,13 @@ mod tests {
expect_eq!(value, 2);
}

#[googletest::test]
fn expect_eq_with_non_copyable_type() {
#[derive(Debug, PartialEq)]
struct NonCopyable(i32);
expect_eq!(NonCopyable(123), NonCopyable(123));
}

#[googletest::test]
fn expect_eq_should_allow_multiple_calls() {
expect_eq!(1, 1);
Expand Down Expand Up @@ -1090,6 +1104,13 @@ mod tests {
verify_ne!(value, 3)
}

#[googletest::test]
fn verify_ne_with_non_copyable_type() -> Result<()> {
#[derive(Debug, PartialEq)]
struct NonCopyable(i32);
verify_ne!(NonCopyable(123), NonCopyable(321))
}

#[test]
fn verify_ne_supports_trailing_comma() -> Result<()> {
let value = 2;
Expand All @@ -1116,6 +1137,13 @@ mod tests {
expect_ne!(1, 2);
}

#[googletest::test]
fn expect_ne_with_non_copyable_type() {
#[derive(Debug, PartialEq)]
struct NonCopyable(i32);
expect_ne!(NonCopyable(123), NonCopyable(321));
}

#[googletest::test]
fn expect_ne_should_allow_multiple_calls() {
expect_ne!(1, 2);
Expand Down

0 comments on commit 07dffcf

Please sign in to comment.