|
4 | 4 | #![feature(io_error_more)]
|
5 | 5 | #![feature(io_error_uncategorized)]
|
6 | 6 |
|
7 |
| -use std::ffi::CString; |
| 7 | +use std::collections::HashMap; |
| 8 | +use std::ffi::{CString, OsString}; |
8 | 9 | use std::fs::{
|
9 | 10 | create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename, File,
|
10 | 11 | OpenOptions,
|
@@ -394,21 +395,34 @@ fn test_directory() {
|
394 | 395 | // Creating a directory when it already exists should fail.
|
395 | 396 | assert_eq!(ErrorKind::AlreadyExists, create_dir(&dir_path).unwrap_err().kind());
|
396 | 397 |
|
397 |
| - // Create some files inside the directory |
| 398 | + // Create some files and dirs inside the directory |
398 | 399 | let path_1 = dir_path.join("test_file_1");
|
399 | 400 | drop(File::create(&path_1).unwrap());
|
400 | 401 | let path_2 = dir_path.join("test_file_2");
|
401 | 402 | drop(File::create(&path_2).unwrap());
|
402 |
| - // Test that the files are present inside the directory |
403 |
| - let dir_iter = read_dir(&dir_path).unwrap(); |
404 |
| - let mut file_names = dir_iter.map(|e| e.unwrap().file_name()).collect::<Vec<_>>(); |
405 |
| - file_names.sort_unstable(); |
406 |
| - assert_eq!(file_names, vec!["test_file_1", "test_file_2"]); |
| 403 | + let dir_1 = dir_path.join("test_dir_1"); |
| 404 | + create_dir(&dir_1).unwrap(); |
| 405 | + // Test that read_dir metadata calls succeed |
| 406 | + assert_eq!( |
| 407 | + HashMap::from([ |
| 408 | + (OsString::from("test_file_1"), true), |
| 409 | + (OsString::from("test_file_2"), true), |
| 410 | + (OsString::from("test_dir_1"), false) |
| 411 | + ]), |
| 412 | + read_dir(&dir_path) |
| 413 | + .unwrap() |
| 414 | + .map(|e| { |
| 415 | + let e = e.unwrap(); |
| 416 | + (e.file_name(), e.metadata().unwrap().is_file()) |
| 417 | + }) |
| 418 | + .collect::<HashMap<_, _>>() |
| 419 | + ); |
407 | 420 | // Deleting the directory should fail, since it is not empty.
|
408 | 421 | assert_eq!(ErrorKind::DirectoryNotEmpty, remove_dir(&dir_path).unwrap_err().kind());
|
409 | 422 | // Clean up the files in the directory
|
410 | 423 | remove_file(&path_1).unwrap();
|
411 | 424 | remove_file(&path_2).unwrap();
|
| 425 | + remove_dir(&dir_1).unwrap(); |
412 | 426 | // Now there should be nothing left in the directory.
|
413 | 427 | let dir_iter = read_dir(&dir_path).unwrap();
|
414 | 428 | let file_names = dir_iter.map(|e| e.unwrap().file_name()).collect::<Vec<_>>();
|
|
0 commit comments