@@ -1767,6 +1767,16 @@ mod tests {
1767
1767
}
1768
1768
) }
1769
1769
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) ]
1770
1780
macro_rules! error { ( $e: expr, $s: expr) => (
1771
1781
match $e {
1772
1782
Ok ( _) => panic!( "Unexpected success. Should've been: {:?}" , $s) ,
@@ -1787,12 +1797,9 @@ mod tests {
1787
1797
1788
1798
match symlink_file ( r"nonexisting_target" , link) {
1789
1799
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 ,
1796
1803
}
1797
1804
}
1798
1805
@@ -1823,12 +1830,10 @@ mod tests {
1823
1830
let filename = & tmpdir. join ( "file_that_does_not_exist.txt" ) ;
1824
1831
let result = File :: open ( filename) ;
1825
1832
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
1832
1837
}
1833
1838
1834
1839
#[ test]
@@ -1838,12 +1843,10 @@ mod tests {
1838
1843
1839
1844
let result = fs:: remove_file ( filename) ;
1840
1845
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
1847
1850
}
1848
1851
1849
1852
#[ test]
@@ -2598,8 +2601,10 @@ mod tests {
2598
2601
let mut a = OO :: new ( ) ; a. append ( true ) ;
2599
2602
let mut ra = OO :: new ( ) ; ra. read ( true ) . append ( true ) ;
2600
2603
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" ;
2603
2608
2604
2609
// Test various combinations of creation modes and access modes.
2605
2610
//
0 commit comments