Fix UI tests and merge assert_eq and assert_ne internal functions

This commit is contained in:
Benoît du Garreau 2020-11-16 21:33:01 +01:00 committed by Benoît du Garreau
parent bbad2b2182
commit 52197d356c
12 changed files with 164 additions and 738 deletions

View file

@ -4,82 +4,45 @@ use crate::{fmt, panic};
#[doc(hidden)]
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
#[track_caller]
pub fn assert_eq_failed<T, U>(left: &T, right: &U) -> !
pub fn assert_failed<T, U>(op: &str, left: &T, right: &U) -> !
where
T: fmt::Debug + ?Sized,
U: fmt::Debug + ?Sized,
{
#[track_caller]
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
fn inner(op: &str, left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
panic!(
r#"assertion failed: `(left == right)`
left: `{:?}`,
right: `{:?}`"#,
left, right
r#"assertion failed: `(left {} right)`
left: `{:?}`,
right: `{:?}`"#,
op, left, right
)
}
inner(&left, &right)
inner(op, &left, &right)
}
#[cold]
#[doc(hidden)]
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
#[track_caller]
pub fn assert_eq_failed_args<T, U>(left: &T, right: &U, args: fmt::Arguments<'_>) -> !
pub fn assert_failed_args<T, U>(op: &str, left: &T, right: &U, args: fmt::Arguments<'_>) -> !
where
T: fmt::Debug + ?Sized,
U: fmt::Debug + ?Sized,
{
#[track_caller]
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug, args: fmt::Arguments<'_>) -> ! {
fn inner(
op: &str,
left: &dyn fmt::Debug,
right: &dyn fmt::Debug,
args: fmt::Arguments<'_>,
) -> ! {
panic!(
r#"assertion failed: `(left == right)`
left: `{:?}`,
right: `{:?}: {}`"#,
left, right, args
r#"assertion failed: `(left {} right)`
left: `{:?}`,
right: `{:?}: {}`"#,
op, left, right, args
)
}
inner(&left, &right, args)
}
#[cold]
#[doc(hidden)]
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
#[track_caller]
pub fn assert_ne_failed<T, U>(left: &T, right: &U) -> !
where
T: fmt::Debug + ?Sized,
U: fmt::Debug + ?Sized,
{
#[track_caller]
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug) -> ! {
panic!(
r#"assertion failed: `(left != right)`
left: `{:?}`,
right: `{:?}`"#,
left, right
)
}
inner(&left, &right)
}
#[cold]
#[doc(hidden)]
#[unstable(feature = "macros_internals", reason = "macros implementation detail", issue = "none")]
#[track_caller]
pub fn assert_ne_failed_args<T, U>(left: &T, right: &U, args: fmt::Arguments<'_>) -> !
where
T: fmt::Debug + ?Sized,
U: fmt::Debug + ?Sized,
{
#[track_caller]
fn inner(left: &dyn fmt::Debug, right: &dyn fmt::Debug, args: fmt::Arguments<'_>) -> ! {
panic!(
r#"assertion failed: `(left != right)`
left: `{:?}`,
right: `{:?}: {}`"#,
left, right, args
)
}
inner(&left, &right, args)
inner(op, &left, &right, args)
}

View file

@ -66,7 +66,7 @@ macro_rules! assert_eq {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
$crate::macros_internals::assert_eq_failed(&*left_val, &*right_val);
$crate::macros_internals::assert_failed("==", &*left_val, &*right_val);
}
}
}
@ -78,7 +78,7 @@ macro_rules! assert_eq {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
$crate::macros_internals::assert_eq_failed_args(&*left_val, &*right_val, $crate::format_args!($($arg)+));
$crate::macros_internals::assert_failed_args("==", &*left_val, &*right_val, $crate::format_args!($($arg)+));
}
}
}
@ -113,7 +113,7 @@ macro_rules! assert_ne {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
$crate::macros_internals::assert_eq_failed(&*left_val, &*right_val);
$crate::macros_internals::assert_failed("!=", &*left_val, &*right_val);
}
}
}
@ -125,7 +125,7 @@ macro_rules! assert_ne {
// The reborrows below are intentional. Without them, the stack slot for the
// borrow is initialized even before the values are compared, leading to a
// noticeable slow down.
$crate::macros_internals::assert_ne_failed_args(&*left_val, &*right_val, $crate::format_args!($($arg)+));
$crate::macros_internals::assert_failed_args("!=", &*left_val, &*right_val, $crate::format_args!($($arg)+));
}
}
}