Split clamp panicking test into separate tests

This commit is contained in:
Jim Turner 2019-09-23 22:21:33 -04:00
parent d02f166765
commit 987ed8fd38
1 changed files with 32 additions and 21 deletions

View File

@ -437,27 +437,38 @@ fn clamp_test() {
} }
#[test] #[test]
fn clamp_nan_bound() { #[should_panic]
/// When debug assertions and the `std` feature are enabled, checks that #[cfg(debug_assertions)]
/// the expression panics. fn clamp_nan_min() {
macro_rules! assert_debug_panics { clamp(0., ::core::f32::NAN, 1.);
($body:expr) => { }
#[cfg(all(debug_assertions, feature = "std"))]
{ #[test]
if let Ok(v) = ::std::panic::catch_unwind(|| $body) { #[should_panic]
panic!( #[cfg(debug_assertions)]
"assertion failed: should_panic; non-panicking result: {:?}", fn clamp_nan_max() {
v clamp(0., -1., ::core::f32::NAN);
); }
}
} #[test]
}; #[should_panic]
} #[cfg(debug_assertions)]
assert_debug_panics!(clamp(0., ::core::f32::NAN, 1.)); fn clamp_nan_min_max() {
assert_debug_panics!(clamp(0., -1., ::core::f32::NAN)); clamp(0., ::core::f32::NAN, ::core::f32::NAN);
assert_debug_panics!(clamp(0., ::core::f32::NAN, ::core::f32::NAN)); }
assert_debug_panics!(clamp_min(0., ::core::f32::NAN));
assert_debug_panics!(clamp_max(0., ::core::f32::NAN)); #[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_min_nan_min() {
clamp_min(0., ::core::f32::NAN);
}
#[test]
#[should_panic]
#[cfg(debug_assertions)]
fn clamp_max_nan_max() {
clamp_max(0., ::core::f32::NAN);
} }
#[test] #[test]