@@ -1767,6 +1767,16 @@ mod tests {
17671767 }
17681768 ) }
17691769
1770+ #[ cfg( windows) ]
1771+ macro_rules! error { ( $e: expr, $s: expr) => (
1772+ match $e {
1773+ Ok ( _) => panic!( "Unexpected success. Should've been: {:?}" , $s) ,
1774+ Err ( ref err) => assert!( err. raw_os_error( ) == Some ( $s) ,
1775+ format!( "`{}` did not have a code of `{}`" , err, $s) )
1776+ }
1777+ ) }
1778+
1779+ #[ cfg( unix) ]
17701780 macro_rules! error { ( $e: expr, $s: expr) => (
17711781 match $e {
17721782 Ok ( _) => panic!( "Unexpected success. Should've been: {:?}" , $s) ,
@@ -1787,12 +1797,9 @@ mod tests {
17871797
17881798 match symlink_file ( r"nonexisting_target" , link) {
17891799 Ok ( _) => true ,
1790- Err ( ref err) =>
1791- if err. to_string ( ) . contains ( "A required privilege is not held by the client." ) {
1792- false
1793- } else {
1794- true
1795- }
1800+ // ERROR_PRIVILEGE_NOT_HELD = 1314
1801+ Err ( ref err) if err. raw_os_error ( ) == Some ( 1314 ) => false ,
1802+ Err ( _) => true ,
17961803 }
17971804 }
17981805
@@ -1823,12 +1830,10 @@ mod tests {
18231830 let filename = & tmpdir. join ( "file_that_does_not_exist.txt" ) ;
18241831 let result = File :: open ( filename) ;
18251832
1826- if cfg ! ( unix) {
1827- error ! ( result, "No such file or directory" ) ;
1828- }
1829- if cfg ! ( windows) {
1830- error ! ( result, "The system cannot find the file specified" ) ;
1831- }
1833+ #[ cfg( unix) ]
1834+ error ! ( result, "No such file or directory" ) ;
1835+ #[ cfg( windows) ]
1836+ error ! ( result, 2 ) ; // ERROR_FILE_NOT_FOUND
18321837 }
18331838
18341839 #[ test]
@@ -1838,12 +1843,10 @@ mod tests {
18381843
18391844 let result = fs:: remove_file ( filename) ;
18401845
1841- if cfg ! ( unix) {
1842- error ! ( result, "No such file or directory" ) ;
1843- }
1844- if cfg ! ( windows) {
1845- error ! ( result, "The system cannot find the file specified" ) ;
1846- }
1846+ #[ cfg( unix) ]
1847+ error ! ( result, "No such file or directory" ) ;
1848+ #[ cfg( windows) ]
1849+ error ! ( result, 2 ) ; // ERROR_FILE_NOT_FOUND
18471850 }
18481851
18491852 #[ test]
@@ -2598,8 +2601,10 @@ mod tests {
25982601 let mut a = OO :: new ( ) ; a. append ( true ) ;
25992602 let mut ra = OO :: new ( ) ; ra. read ( true ) . append ( true ) ;
26002603
2601- let invalid_options = if cfg ! ( windows) { "The parameter is incorrect" }
2602- else { "Invalid argument" } ;
2604+ #[ cfg( windows) ]
2605+ let invalid_options = 87 ; // ERROR_INVALID_PARAMETER
2606+ #[ cfg( unix) ]
2607+ let invalid_options = "Invalid argument" ;
26032608
26042609 // Test various combinations of creation modes and access modes.
26052610 //
0 commit comments