@@ -1265,12 +1265,7 @@ fn open_flavors() {
12651265    let  mut  ra = OO :: new ( ) ; 
12661266    ra. read ( true ) . append ( true ) ; 
12671267
1268-     #[ cfg( windows) ]  
1269-     let  invalid_options = 87 ;  // ERROR_INVALID_PARAMETER 
1270-     #[ cfg( all( unix,  not( target_os = "vxworks" ) ) ) ]  
1271-     let  invalid_options = "Invalid argument" ; 
1272-     #[ cfg( target_os = "vxworks" ) ]  
1273-     let  invalid_options = "invalid argument" ; 
1268+     let  invalid_options = "creating or truncating a file requires write or append access" ; 
12741269
12751270    // Test various combinations of creation modes and access modes. 
12761271    // 
@@ -2084,3 +2079,34 @@ fn test_rename_junction() {
20842079    // Junction links are always absolute so we just check the file name is correct. 
20852080    assert_eq ! ( fs:: read_link( & dest) . unwrap( ) . file_name( ) ,  Some ( not_exist. as_os_str( ) ) ) ; 
20862081} 
2082+ 
2083+ #[ test]  
2084+ fn  test_open_options_invalid_combinations ( )  { 
2085+     use  crate :: fs:: OpenOptions  as  OO ; 
2086+ 
2087+     let  test_cases:  & [ ( fn ( )  -> OO ,  & str ) ]  = & [ 
2088+         ( || OO :: new ( ) . create ( true ) . read ( true ) . clone ( ) ,  "create without write" ) , 
2089+         ( || OO :: new ( ) . create_new ( true ) . read ( true ) . clone ( ) ,  "create_new without write" ) , 
2090+         ( || OO :: new ( ) . truncate ( true ) . read ( true ) . clone ( ) ,  "truncate without write" ) , 
2091+         ( || OO :: new ( ) . truncate ( true ) . append ( true ) . clone ( ) ,  "truncate with append" ) , 
2092+     ] ; 
2093+ 
2094+     for  ( make_opts,  desc)  in  test_cases { 
2095+         let  opts = make_opts ( ) ; 
2096+         let  result = opts. open ( "nonexistent.txt" ) ; 
2097+         assert ! ( result. is_err( ) ,  "{desc} should fail" ) ; 
2098+         let  err = result. unwrap_err ( ) ; 
2099+         assert_eq ! ( err. kind( ) ,  ErrorKind :: InvalidInput ,  "{desc} - wrong error kind" ) ; 
2100+         assert_eq ! ( 
2101+             err. to_string( ) , 
2102+             "creating or truncating a file requires write or append access" , 
2103+             "{desc} - wrong error message" 
2104+         ) ; 
2105+     } 
2106+ 
2107+     let  result = OO :: new ( ) . open ( "nonexistent.txt" ) ; 
2108+     assert ! ( result. is_err( ) ,  "no access mode should fail" ) ; 
2109+     let  err = result. unwrap_err ( ) ; 
2110+     assert_eq ! ( err. kind( ) ,  ErrorKind :: InvalidInput ) ; 
2111+     assert_eq ! ( err. to_string( ) ,  "must specify at least one of read, write, or append access" ) ; 
2112+ } 
0 commit comments