@@ -1799,6 +1799,16 @@ mod tests {
1799
1799
}
1800
1800
) }
1801
1801
1802
+ #[ cfg( windows) ]
1803
+ macro_rules! error { ( $e: expr, $s: expr) => (
1804
+ match $e {
1805
+ Ok ( _) => panic!( "Unexpected success. Should've been: {:?}" , $s) ,
1806
+ Err ( ref err) => assert!( err. raw_os_error( ) == Some ( $s) ,
1807
+ format!( "`{}` did not have a code of `{}`" , err, $s) )
1808
+ }
1809
+ ) }
1810
+
1811
+ #[ cfg( unix) ]
1802
1812
macro_rules! error { ( $e: expr, $s: expr) => (
1803
1813
match $e {
1804
1814
Ok ( _) => panic!( "Unexpected success. Should've been: {:?}" , $s) ,
@@ -1819,12 +1829,9 @@ mod tests {
1819
1829
1820
1830
match symlink_file ( r"nonexisting_target" , link) {
1821
1831
Ok ( _) => true ,
1822
- Err ( ref err) =>
1823
- if err. to_string ( ) . contains ( "A required privilege is not held by the client." ) {
1824
- false
1825
- } else {
1826
- true
1827
- }
1832
+ // ERROR_PRIVILEGE_NOT_HELD = 1314
1833
+ Err ( ref err) if err. raw_os_error ( ) == Some ( 1314 ) => false ,
1834
+ Err ( _) => true ,
1828
1835
}
1829
1836
}
1830
1837
@@ -1855,12 +1862,10 @@ mod tests {
1855
1862
let filename = & tmpdir. join ( "file_that_does_not_exist.txt" ) ;
1856
1863
let result = File :: open ( filename) ;
1857
1864
1858
- if cfg ! ( unix) {
1859
- error ! ( result, "No such file or directory" ) ;
1860
- }
1861
- if cfg ! ( windows) {
1862
- error ! ( result, "The system cannot find the file specified" ) ;
1863
- }
1865
+ #[ cfg( unix) ]
1866
+ error ! ( result, "No such file or directory" ) ;
1867
+ #[ cfg( windows) ]
1868
+ error ! ( result, 2 ) ; // ERROR_FILE_NOT_FOUND
1864
1869
}
1865
1870
1866
1871
#[ test]
@@ -1870,12 +1875,10 @@ mod tests {
1870
1875
1871
1876
let result = fs:: remove_file ( filename) ;
1872
1877
1873
- if cfg ! ( unix) {
1874
- error ! ( result, "No such file or directory" ) ;
1875
- }
1876
- if cfg ! ( windows) {
1877
- error ! ( result, "The system cannot find the file specified" ) ;
1878
- }
1878
+ #[ cfg( unix) ]
1879
+ error ! ( result, "No such file or directory" ) ;
1880
+ #[ cfg( windows) ]
1881
+ error ! ( result, 2 ) ; // ERROR_FILE_NOT_FOUND
1879
1882
}
1880
1883
1881
1884
#[ test]
@@ -2630,8 +2633,10 @@ mod tests {
2630
2633
let mut a = OO :: new ( ) ; a. append ( true ) ;
2631
2634
let mut ra = OO :: new ( ) ; ra. read ( true ) . append ( true ) ;
2632
2635
2633
- let invalid_options = if cfg ! ( windows) { "The parameter is incorrect" }
2634
- else { "Invalid argument" } ;
2636
+ #[ cfg( windows) ]
2637
+ let invalid_options = 87 ; // ERROR_INVALID_PARAMETER
2638
+ #[ cfg( unix) ]
2639
+ let invalid_options = "Invalid argument" ;
2635
2640
2636
2641
// Test various combinations of creation modes and access modes.
2637
2642
//
0 commit comments