Skip to content

Commit

Permalink
Merge pull request #78 from tommilligan/test-macro-integrate
Browse files Browse the repository at this point in the history
chore: make macro tests external
  • Loading branch information
tommilligan committed May 5, 2021
2 parents 9746ead + c45600c commit 55f9b7a
Show file tree
Hide file tree
Showing 2 changed files with 222 additions and 225 deletions.
225 changes: 0 additions & 225 deletions pretty_assertions/src/lib.rs
Expand Up @@ -238,228 +238,3 @@ macro_rules! assert_ne {
}
});
}

#[cfg(test)]
#[allow(clippy::eq_op)]
#[no_implicit_prelude]
mod test {
mod assert_eq {
use ::std::string::{String, ToString};

#[test]
fn passes() {
let a = "some value";
crate::assert_eq!(a, a);
}

#[test]
fn passes_unsized() {
let a: &[u8] = b"e";
crate::assert_eq!(*a, *a);
}

#[test]
fn passes_comparable_types() {
let s0: &'static str = "foo";
let s1: String = "foo".to_string();
crate::assert_eq!(s0, s1);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
Diff < left / right > :
<666
>999
"#)]
fn fails() {
crate::assert_eq!(666, 999);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
Diff < left / right > :
<666
>999
"#)]
fn fails_trailing_comma() {
crate::assert_eq!(666, 999,);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left == right)`
Diff < left / right > :
[
101,
> 101,
]
"#)]
fn fails_unsized() {
let a: &[u8] = b"e";
let b: &[u8] = b"ee";
crate::assert_eq!(*a, *b);
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left == right)`: custom panic message
Diff < left / right > :
<666
>999
"#
)]
fn fails_custom() {
crate::assert_eq!(666, 999, "custom panic message");
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left == right)`: custom panic message
Diff < left / right > :
<666
>999
"#
)]
fn fails_custom_trailing_comma() {
crate::assert_eq!(666, 999, "custom panic message",);
}
}

mod assert_ne {
use ::std::string::{String, ToString};

#[test]
fn passes() {
let a = "a";
let b = "b";
crate::assert_ne!(a, b);
}

#[test]
fn passes_unsized() {
let a: &[u8] = b"e";
let b: &[u8] = b"ee";
crate::assert_ne!(*a, *b);
}

#[test]
fn passes_comparable_types() {
let s0: &'static str = "foo";
let s1: String = "bar".to_string();
crate::assert_ne!(s0, s1);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
Both sides:
666
"#)]
fn fails() {
crate::assert_ne!(666, 666);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
Both sides:
666
"#)]
fn fails_trailing_comma() {
crate::assert_ne!(666, 666,);
}

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
Both sides:
[
101,
]
"#)]
fn fails_unsized() {
let a: &[u8] = b"e";
crate::assert_ne!(*a, *a);
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message
Both sides:
666
"#
)]
fn fails_custom() {
crate::assert_ne!(666, 666, "custom panic message");
}

#[test]
#[should_panic(
expected = r#"assertion failed: `(left != right)`: custom panic message
Both sides:
666
"#
)]
fn fails_custom_trailing_comma() {
crate::assert_ne!(666, 666, "custom panic message",);
}

// If the values are equal but their debug outputs are not
// show a specific warning

#[test]
#[should_panic(expected = r#"assertion failed: `(left != right)`
Diff < left / right > :
<-0.0
>0.0
Note: According to the `PartialEq` implementation, both of the values are partially equivalent, even if the `Debug` outputs differ.
"#)]
fn assert_ne_partial() {
// Workaround for https://github.com/rust-lang/rust/issues/47619
// can be removed, when we require rust 1.25 or higher
struct Foo(f32);

use ::std::fmt;
impl fmt::Debug for Foo {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
::std::write!(f, "{:.1?}", self.0)
}
}

impl ::std::cmp::PartialEq for Foo {
fn eq(&self, other: &Self) -> bool {
self.0 == other.0
}
}

crate::assert_ne!(Foo(-0.0), Foo(0.0));
}

// Regression tests

#[test]
#[should_panic]
fn assert_ne_non_empty_return() {
fn not_zero(x: u32) -> u32 {
crate::assert_ne!(x, 0);
x
}
not_zero(0);
}
}
}

0 comments on commit 55f9b7a

Please sign in to comment.