@@ -691,6 +691,19 @@ fn cast_to_unsigned_int_checks_overflow() {
691
691
assert_eq ! ( None , cast:: <f64 , u64 >( small_f) ) ;
692
692
}
693
693
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
+
694
707
#[ test]
695
708
fn cast_float_to_int_edge_cases ( ) {
696
709
use core:: mem:: transmute;
@@ -720,15 +733,15 @@ fn cast_float_to_int_edge_cases() {
720
733
721
734
macro_rules! test_edge {
722
735
( $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) ) ;
724
737
725
738
let small = if $t:: MIN == 0 || size_of:: <$t>( ) < size_of:: <$f>( ) {
726
739
$t:: MIN as $f - 1.0
727
740
} else {
728
741
( $t:: MIN as $f) . raw_offset( 1 ) . floor( )
729
742
} ;
730
743
let fmin = small. raw_offset( -1 ) ;
731
- println !( " testing min {}\n \t vs. {:.16}\n \t and {:.16}" , $t:: MIN , fmin, small) ;
744
+ dbg !( " testing min {}\n \t vs. {:.16}\n \t and {:.16}" , $t:: MIN , fmin, small) ;
732
745
assert_eq!( Some ( $t:: MIN ) , cast:: <$f, $t>( $t:: MIN as $f) ) ;
733
746
assert_eq!( Some ( $t:: MIN ) , cast:: <$f, $t>( fmin) ) ;
734
747
assert_eq!( None , cast:: <$f, $t>( small) ) ;
@@ -742,12 +755,12 @@ fn cast_float_to_int_edge_cases() {
742
755
( max, large)
743
756
} ;
744
757
let fmax = large. raw_offset( -1 ) ;
745
- println !( " testing max {}\n \t vs. {:.16}\n \t and {:.16}" , max, fmax, large) ;
758
+ dbg !( " testing max {}\n \t vs. {:.16}\n \t and {:.16}" , max, fmax, large) ;
746
759
assert_eq!( Some ( max) , cast:: <$f, $t>( max as $f) ) ;
747
760
assert_eq!( Some ( max) , cast:: <$f, $t>( fmax) ) ;
748
761
assert_eq!( None , cast:: <$f, $t>( large) ) ;
749
762
750
- println !( " testing non-finite values" ) ;
763
+ dbg !( " testing non-finite values" ) ;
751
764
assert_eq!( None , cast:: <$f, $t>( $f:: NAN ) ) ;
752
765
assert_eq!( None , cast:: <$f, $t>( $f:: INFINITY ) ) ;
753
766
assert_eq!( None , cast:: <$f, $t>( $f:: NEG_INFINITY ) ) ;
0 commit comments