Skip to content

Commit 652417e

Browse files
authored
Rollup merge of rust-lang#103258 - SUPERCILEX:miri, r=RalfJung
Make miri read_dir test a little more robust r? `@RalfJung`
2 parents 952c156 + b0f6935 commit 652417e

File tree

1 file changed

+17
-11
lines changed
  • src/tools/miri/tests/pass-dep/shims

1 file changed

+17
-11
lines changed

Diff for: src/tools/miri/tests/pass-dep/shims/fs.rs

+17-11
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#![feature(io_error_more)]
55
#![feature(io_error_uncategorized)]
66

7-
use std::ffi::CString;
7+
use std::collections::HashMap;
8+
use std::ffi::{CString, OsString};
89
use std::fs::{
910
create_dir, read_dir, read_link, remove_dir, remove_dir_all, remove_file, rename, File,
1011
OpenOptions,
@@ -394,29 +395,34 @@ fn test_directory() {
394395
// Creating a directory when it already exists should fail.
395396
assert_eq!(ErrorKind::AlreadyExists, create_dir(&dir_path).unwrap_err().kind());
396397

397-
// Create some files inside the directory
398+
// Create some files and dirs inside the directory
398399
let path_1 = dir_path.join("test_file_1");
399400
drop(File::create(&path_1).unwrap());
400401
let path_2 = dir_path.join("test_file_2");
401402
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();
407405
// Test that read_dir metadata calls succeed
408406
assert_eq!(
409-
&[true, true],
410-
&*read_dir(&dir_path)
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)
411413
.unwrap()
412-
.map(|e| e.unwrap().metadata().unwrap().is_file())
413-
.collect::<Vec<_>>()
414+
.map(|e| {
415+
let e = e.unwrap();
416+
(e.file_name(), e.metadata().unwrap().is_file())
417+
})
418+
.collect::<HashMap<_, _>>()
414419
);
415420
// Deleting the directory should fail, since it is not empty.
416421
assert_eq!(ErrorKind::DirectoryNotEmpty, remove_dir(&dir_path).unwrap_err().kind());
417422
// Clean up the files in the directory
418423
remove_file(&path_1).unwrap();
419424
remove_file(&path_2).unwrap();
425+
remove_dir(&dir_1).unwrap();
420426
// Now there should be nothing left in the directory.
421427
let dir_iter = read_dir(&dir_path).unwrap();
422428
let file_names = dir_iter.map(|e| e.unwrap().file_name()).collect::<Vec<_>>();

0 commit comments

Comments
 (0)