Skip to content

Commit 6d7bbb1

Browse files
committed
Mask debug prints no-std mode
1 parent d195eaf commit 6d7bbb1

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/cast.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,19 @@ fn cast_to_unsigned_int_checks_overflow() {
691691
assert_eq!(None, cast::<f64, u64>(small_f));
692692
}
693693

694+
#[cfg(all(test, feature = "std"))]
695+
fn dbg(args: ::core::fmt::Arguments) {
696+
println!("{}", args);
697+
}
698+
699+
#[cfg(all(test, not(feature = "std")))]
700+
fn dbg(_: ::core::fmt::Arguments) {}
701+
702+
// Rust 1.8 doesn't handle cfg on macros correctly
703+
// #[cfg(test)]
704+
#[allow(unused)]
705+
macro_rules! dbg { ($($tok:tt)*) => { dbg(format_args!($($tok)*)) } }
706+
694707
#[test]
695708
fn cast_float_to_int_edge_cases() {
696709
use core::mem::transmute;
@@ -720,15 +733,15 @@ fn cast_float_to_int_edge_cases() {
720733

721734
macro_rules! test_edge {
722735
($f:ident -> $($t:ident)+) => { $({
723-
println!("testing cast edge cases for {} -> {}", stringify!($f), stringify!($t));
736+
dbg!("testing cast edge cases for {} -> {}", stringify!($f), stringify!($t));
724737

725738
let small = if $t::MIN == 0 || size_of::<$t>() < size_of::<$f>() {
726739
$t::MIN as $f - 1.0
727740
} else {
728741
($t::MIN as $f).raw_offset(1).floor()
729742
};
730743
let fmin = small.raw_offset(-1);
731-
println!(" testing min {}\n\tvs. {:.16}\n\tand {:.16}", $t::MIN, fmin, small);
744+
dbg!(" testing min {}\n\tvs. {:.16}\n\tand {:.16}", $t::MIN, fmin, small);
732745
assert_eq!(Some($t::MIN), cast::<$f, $t>($t::MIN as $f));
733746
assert_eq!(Some($t::MIN), cast::<$f, $t>(fmin));
734747
assert_eq!(None, cast::<$f, $t>(small));
@@ -742,12 +755,12 @@ fn cast_float_to_int_edge_cases() {
742755
(max, large)
743756
};
744757
let fmax = large.raw_offset(-1);
745-
println!(" testing max {}\n\tvs. {:.16}\n\tand {:.16}", max, fmax, large);
758+
dbg!(" testing max {}\n\tvs. {:.16}\n\tand {:.16}", max, fmax, large);
746759
assert_eq!(Some(max), cast::<$f, $t>(max as $f));
747760
assert_eq!(Some(max), cast::<$f, $t>(fmax));
748761
assert_eq!(None, cast::<$f, $t>(large));
749762

750-
println!(" testing non-finite values");
763+
dbg!(" testing non-finite values");
751764
assert_eq!(None, cast::<$f, $t>($f::NAN));
752765
assert_eq!(None, cast::<$f, $t>($f::INFINITY));
753766
assert_eq!(None, cast::<$f, $t>($f::NEG_INFINITY));

0 commit comments

Comments
 (0)