@@ -859,90 +859,107 @@ impl<L, R> fmt::Display for Either<L, R>
859859 }
860860}
861861
862- // #[test]
863- fn basic ( ) {
864- let mut e = Left ( 2 ) ;
865- let r = Right ( 2 ) ;
866- assert_eq ! ( e, Left ( 2 ) ) ;
867- e = r;
868- assert_eq ! ( e, Right ( 2 ) ) ;
869- assert_eq ! ( e. left( ) , None ) ;
870- assert_eq ! ( e. right( ) , Some ( 2 ) ) ;
871- assert_eq ! ( e. as_ref( ) . right( ) , Some ( & 2 ) ) ;
872- assert_eq ! ( e. as_mut( ) . right( ) , Some ( & mut 2 ) ) ;
873- }
862+ #[ cfg( feature = "enclave_unit_test" ) ]
863+ pub mod tests {
864+ use super :: * ;
865+ use sgx_tunittest:: * ;
874866
875- // #[test]
876- fn macros ( ) {
877- fn a ( ) -> Either < u32 , u32 > {
878- let x: u32 = try_left ! ( Right ( 1337u32 ) ) ;
879- Left ( x * 2 )
867+ pub fn run_tests ( ) {
868+ rsgx_unit_tests ! (
869+ basic,
870+ macros,
871+ deref,
872+ iter,
873+ read_write,
874+ error,
875+ ) ;
880876 }
881- assert_eq ! ( a( ) , Right ( 1337 ) ) ;
882877
883- fn b ( ) -> Either < String , & ' static str > {
884- Right ( try_right ! ( Left ( "foo bar" ) ) )
878+ // #[test]
879+ fn basic ( ) {
880+ let mut e = Left ( 2 ) ;
881+ let r = Right ( 2 ) ;
882+ assert_eq ! ( e, Left ( 2 ) ) ;
883+ e = r;
884+ assert_eq ! ( e, Right ( 2 ) ) ;
885+ assert_eq ! ( e. left( ) , None ) ;
886+ assert_eq ! ( e. right( ) , Some ( 2 ) ) ;
887+ assert_eq ! ( e. as_ref( ) . right( ) , Some ( & 2 ) ) ;
888+ assert_eq ! ( e. as_mut( ) . right( ) , Some ( & mut 2 ) ) ;
889+ }
890+
891+ // #[test]
892+ fn macros ( ) {
893+ fn a ( ) -> Either < u32 , u32 > {
894+ let x: u32 = try_left ! ( Right ( 1337u32 ) ) ;
895+ Left ( x * 2 )
896+ }
897+ assert_eq ! ( a( ) , Right ( 1337 ) ) ;
898+
899+ fn b ( ) -> Either < String , & ' static str > {
900+ Right ( try_right ! ( Left ( "foo bar" ) ) )
901+ }
902+ assert_eq ! ( b( ) , Left ( String :: from( "foo bar" ) ) ) ;
885903 }
886- assert_eq ! ( b( ) , Left ( String :: from( "foo bar" ) ) ) ;
887- }
888904
889- // #[test]
890- fn deref ( ) {
891- fn is_str ( _: & str ) { }
892- let value: Either < String , & str > = Left ( String :: from ( "test" ) ) ;
893- is_str ( & * value) ;
894- }
905+ // #[test]
906+ fn deref ( ) {
907+ fn is_str ( _: & str ) { }
908+ let value: Either < String , & str > = Left ( String :: from ( "test" ) ) ;
909+ is_str ( & * value) ;
910+ }
895911
896- // #[test]
897- fn iter ( ) {
898- let x = 3 ;
899- let mut iter = match x {
900- 3 => Left ( 0 ..10 ) ,
901- _ => Right ( 17 ..) ,
902- } ;
912+ // #[test]
913+ fn iter ( ) {
914+ let x = 3 ;
915+ let mut iter = match x {
916+ 3 => Left ( 0 ..10 ) ,
917+ _ => Right ( 17 ..) ,
918+ } ;
903919
904- assert_eq ! ( iter. next( ) , Some ( 0 ) ) ;
905- assert_eq ! ( iter. count( ) , 9 ) ;
906- }
920+ assert_eq ! ( iter. next( ) , Some ( 0 ) ) ;
921+ assert_eq ! ( iter. count( ) , 9 ) ;
922+ }
907923
908- // #[test]
909- fn read_write ( ) {
910- use std:: io;
924+ // #[test]
925+ fn read_write ( ) {
926+ use std:: io;
911927
912- let use_stdio = false ;
913- let mockdata = [ 0xff ; 256 ] ;
928+ let use_stdio = false ;
929+ let mockdata = [ 0xff ; 256 ] ;
914930
915- let mut reader = if use_stdio {
916- Left ( io:: stdin ( ) )
917- } else {
918- Right ( & mockdata[ ..] )
919- } ;
931+ let mut reader = if use_stdio {
932+ Left ( io:: stdin ( ) )
933+ } else {
934+ Right ( & mockdata[ ..] )
935+ } ;
920936
921- let mut buf = [ 0u8 ; 16 ] ;
922- assert_eq ! ( reader. read( & mut buf) . unwrap( ) , buf. len( ) ) ;
923- assert_eq ! ( & buf, & mockdata[ ..buf. len( ) ] ) ;
937+ let mut buf = [ 0u8 ; 16 ] ;
938+ assert_eq ! ( reader. read( & mut buf) . unwrap( ) , buf. len( ) ) ;
939+ assert_eq ! ( & buf, & mockdata[ ..buf. len( ) ] ) ;
924940
925- let mut mockbuf = [ 0u8 ; 256 ] ;
926- let mut writer = if use_stdio {
927- Left ( io:: stdout ( ) )
928- } else {
929- Right ( & mut mockbuf[ ..] )
930- } ;
941+ let mut mockbuf = [ 0u8 ; 256 ] ;
942+ let mut writer = if use_stdio {
943+ Left ( io:: stdout ( ) )
944+ } else {
945+ Right ( & mut mockbuf[ ..] )
946+ } ;
931947
932- let buf = [ 1u8 ; 16 ] ;
933- assert_eq ! ( writer. write( & buf) . unwrap( ) , buf. len( ) ) ;
934- }
948+ let buf = [ 1u8 ; 16 ] ;
949+ assert_eq ! ( writer. write( & buf) . unwrap( ) , buf. len( ) ) ;
950+ }
935951
936- // #[test]
937- fn error ( ) {
938- let invalid_utf8 = b"\xff " ;
939- let res = || -> Result < _ , Either < _ , _ > > {
940- try!( :: std:: str:: from_utf8 ( invalid_utf8) . map_err ( Left ) ) ;
941- try!( "x" . parse :: < i32 > ( ) . map_err ( Right ) ) ;
942- Ok ( ( ) )
943- } ( ) ;
944- assert ! ( res. is_err( ) ) ;
945- res. unwrap_err ( ) . description ( ) ; // make sure this can be called
952+ // #[test]
953+ fn error ( ) {
954+ let invalid_utf8 = b"\xff " ;
955+ let res = || -> Result < _ , Either < _ , _ > > {
956+ try!( :: std:: str:: from_utf8 ( invalid_utf8) . map_err ( Left ) ) ;
957+ try!( "x" . parse :: < i32 > ( ) . map_err ( Right ) ) ;
958+ Ok ( ( ) )
959+ } ( ) ;
960+ assert ! ( res. is_err( ) ) ;
961+ res. unwrap_err ( ) . description ( ) ; // make sure this can be called
962+ }
946963}
947964
948965/// A helper macro to check if AsRef and AsMut are implemented for a given type.
@@ -982,20 +999,3 @@ fn _unsized_std_propagation() {
982999 check_t ! ( :: std:: ffi:: OsStr ) ;
9831000 check_t ! ( :: std:: ffi:: CStr ) ;
9841001}
985-
986- #[ cfg( feature = "enclave_unit_test" ) ]
987- pub mod tests {
988- use super :: * ;
989- use sgx_tunittest:: * ;
990-
991- pub fn run_tests ( ) {
992- rsgx_unit_tests ! (
993- basic,
994- macros,
995- deref,
996- iter,
997- read_write,
998- error,
999- ) ;
1000- }
1001- }
0 commit comments