|
1 | 1 | // ignore-windows: File handling is not implemented yet |
2 | 2 | // compile-flags: -Zmiri-disable-isolation |
3 | 3 |
|
4 | | -use std::fs::{File, create_dir, read_dir, remove_dir, remove_dir_all, remove_file, rename}; |
| 4 | +use std::fs::{ |
| 5 | + File, create_dir, OpenOptions, read_dir, remove_dir, remove_dir_all, remove_file, rename, |
| 6 | +}; |
5 | 7 | use std::io::{Read, Write, ErrorKind, Result, Seek, SeekFrom}; |
6 | 8 | use std::path::{PathBuf, Path}; |
7 | 9 |
|
8 | 10 | fn main() { |
9 | 11 | test_file(); |
10 | 12 | test_file_clone(); |
| 13 | + test_file_create_new(); |
11 | 14 | test_seek(); |
12 | 15 | test_metadata(); |
13 | 16 | test_symlink(); |
@@ -85,6 +88,20 @@ fn test_file_clone() { |
85 | 88 | remove_file(&path).unwrap(); |
86 | 89 | } |
87 | 90 |
|
| 91 | +fn test_file_create_new() { |
| 92 | + let path = prepare("miri_test_fs_file_create_new.txt"); |
| 93 | + |
| 94 | + // Creating a new file that doesn't yet exist should succeed. |
| 95 | + OpenOptions::new().write(true).create_new(true).open(&path).unwrap(); |
| 96 | + // Creating a new file that already exists should fail. |
| 97 | + assert_eq!(ErrorKind::AlreadyExists, OpenOptions::new().write(true).create_new(true).open(&path).unwrap_err().kind()); |
| 98 | + // Optionally creating a new file that already exists should succeed. |
| 99 | + OpenOptions::new().write(true).create(true).open(&path).unwrap(); |
| 100 | + |
| 101 | + // Clean up |
| 102 | + remove_file(&path).unwrap(); |
| 103 | +} |
| 104 | + |
88 | 105 | fn test_seek() { |
89 | 106 | let bytes = b"Hello, entire World!\n"; |
90 | 107 | let path = prepare_with_content("miri_test_fs_seek.txt", bytes); |
|
0 commit comments