Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 7503379

Browse files
committedJun 9, 2024·
Implement fs wrapper for run_make_support
1 parent 6c4755d commit 7503379

File tree

36 files changed

+211
-108
lines changed

36 files changed

+211
-108
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
use std::fs;
2+
use std::path::Path;
3+
4+
/// A wrapper around [`std::fs::remove_file`] which includes the file path in the panic message..
5+
#[track_caller]
6+
pub fn remove_file<P: AsRef<Path>>(path: P) {
7+
fs::remove_file(path.as_ref())
8+
.expect(&format!("the file in path \"{}\" could not be removed", path.as_ref().display()));
9+
}
10+
11+
/// A wrapper around [`std::fs::copy`] which includes the file path in the panic message.
12+
#[track_caller]
13+
pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
14+
fs::copy(from.as_ref(), to.as_ref()).expect(&format!(
15+
"the file \"{}\" could not be copied over to \"{}\"",
16+
from.as_ref().display(),
17+
to.as_ref().display(),
18+
));
19+
}
20+
21+
/// A wrapper around [`std::fs::File::create`] which includes the file path in the panic message..
22+
#[track_caller]
23+
pub fn create_file<P: AsRef<Path>>(path: P) {
24+
fs::File::create(path.as_ref())
25+
.expect(&format!("the file in path \"{}\" could not be created", path.as_ref().display()));
26+
}
27+
28+
/// A wrapper around [`std::fs::read`] which includes the file path in the panic message..
29+
#[track_caller]
30+
pub fn read<P: AsRef<Path>>(path: P) -> Vec<u8> {
31+
fs::read(path.as_ref())
32+
.expect(&format!("the file in path \"{}\" could not be read", path.as_ref().display()))
33+
}
34+
35+
/// A wrapper around [`std::fs::read_to_string`] which includes the file path in the panic message..
36+
#[track_caller]
37+
pub fn read_to_string<P: AsRef<Path>>(path: P) -> String {
38+
fs::read_to_string(path.as_ref()).expect(&format!(
39+
"the file in path \"{}\" could not be read into a String",
40+
path.as_ref().display()
41+
))
42+
}
43+
44+
/// A wrapper around [`std::fs::read_dir`] which includes the file path in the panic message..
45+
#[track_caller]
46+
pub fn read_dir<P: AsRef<Path>>(path: P) -> fs::ReadDir {
47+
fs::read_dir(path.as_ref())
48+
.expect(&format!("the directory in path \"{}\" could not be read", path.as_ref().display()))
49+
}
50+
51+
/// A wrapper around [`std::fs::write`] which includes the file path in the panic message..
52+
#[track_caller]
53+
pub fn write<P: AsRef<Path>, C: AsRef<[u8]>>(path: P, contents: C) {
54+
fs::write(path.as_ref(), contents.as_ref()).expect(&format!(
55+
"the file in path \"{}\" could not be written to",
56+
path.as_ref().display()
57+
));
58+
}
59+
60+
/// A wrapper around [`std::fs::remove_dir_all`] which includes the file path in the panic message..
61+
#[track_caller]
62+
pub fn remove_dir_all<P: AsRef<Path>>(path: P) {
63+
fs::remove_dir_all(path.as_ref()).expect(&format!(
64+
"the directory in path \"{}\" could not be removed alongside all its contents",
65+
path.as_ref().display(),
66+
));
67+
}
68+
69+
/// A wrapper around [`std::fs::create_dir`] which includes the file path in the panic message..
70+
#[track_caller]
71+
pub fn create_dir<P: AsRef<Path>>(path: P) {
72+
fs::create_dir(path.as_ref()).expect(&format!(
73+
"the directory in path \"{}\" could not be created",
74+
path.as_ref().display()
75+
));
76+
}
77+
78+
/// A wrapper around [`std::fs::create_dir_all`] which includes the file path in the panic message..
79+
#[track_caller]
80+
pub fn create_dir_all<P: AsRef<Path>>(path: P) {
81+
fs::create_dir_all(path.as_ref()).expect(&format!(
82+
"the directory (and all its parents) in path \"{}\" could not be created",
83+
path.as_ref().display()
84+
));
85+
}
86+
87+
/// A wrapper around [`std::fs::metadata`] which includes the file path in the panic message..
88+
#[track_caller]
89+
pub fn metadata<P: AsRef<Path>>(path: P) -> fs::Metadata {
90+
fs::metadata(path.as_ref()).expect(&format!(
91+
"the file's metadata in path \"{}\" could not be read",
92+
path.as_ref().display()
93+
))
94+
}
95+
96+
/// A wrapper around [`std::fs::rename`] which includes the file path in the panic message.
97+
#[track_caller]
98+
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) {
99+
fs::rename(from.as_ref(), to.as_ref()).expect(&format!(
100+
"the file \"{}\" could not be moved over to \"{}\"",
101+
from.as_ref().display(),
102+
to.as_ref().display(),
103+
));
104+
}
105+
106+
/// A wrapper around [[`std::fs::set_permissions`] which includes the file path in the panic message.
107+
#[track_caller]
108+
pub fn set_permissions<P: AsRef<Path>>(path: P, perm: fs::Permissions) {
109+
fs::set_permissions(path.as_ref(), perm).expect(&format!(
110+
"the file's permissions in path \"{}\" could not be changed",
111+
path.as_ref().display()
112+
));
113+
}

‎src/tools/run-make-support/src/lib.rs

+8-14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub mod cc;
77
pub mod clang;
88
mod command;
99
pub mod diff;
10+
pub mod fs_wrapper;
1011
pub mod llvm_readobj;
1112
pub mod run;
1213
pub mod rustc;
@@ -142,7 +143,7 @@ pub fn dynamic_lib_extension() -> &'static str {
142143
}
143144
}
144145

145-
/// Construct a rust library (rlib) name.
146+
/// Generate the name a rust library (rlib) would have.
146147
pub fn rust_lib_name(name: &str) -> String {
147148
format!("lib{name}.rlib")
148149
}
@@ -221,15 +222,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
221222
fn copy_dir_all_inner(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> io::Result<()> {
222223
let dst = dst.as_ref();
223224
if !dst.is_dir() {
224-
fs::create_dir_all(&dst)?;
225+
std::fs::create_dir_all(&dst)?;
225226
}
226-
for entry in fs::read_dir(src)? {
227+
for entry in std::fs::read_dir(src)? {
227228
let entry = entry?;
228229
let ty = entry.file_type()?;
229230
if ty.is_dir() {
230231
copy_dir_all_inner(entry.path(), dst.join(entry.file_name()))?;
231232
} else {
232-
fs::copy(entry.path(), dst.join(entry.file_name()))?;
233+
std::fs::copy(entry.path(), dst.join(entry.file_name()))?;
233234
}
234235
}
235236
Ok(())
@@ -248,22 +249,15 @@ pub fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) {
248249

249250
/// Check that all files in `dir1` exist and have the same content in `dir2`. Panic otherwise.
250251
pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
251-
fn read_file(path: &Path) -> Vec<u8> {
252-
match fs::read(path) {
253-
Ok(c) => c,
254-
Err(e) => panic!("Failed to read `{}`: {:?}", path.display(), e),
255-
}
256-
}
257-
258252
let dir2 = dir2.as_ref();
259253
read_dir(dir1, |entry_path| {
260254
let entry_name = entry_path.file_name().unwrap();
261255
if entry_path.is_dir() {
262256
recursive_diff(&entry_path, &dir2.join(entry_name));
263257
} else {
264258
let path2 = dir2.join(entry_name);
265-
let file1 = read_file(&entry_path);
266-
let file2 = read_file(&path2);
259+
let file1 = fs_wrapper::read(&entry_path);
260+
let file2 = fs_wrapper::read(&path2);
267261

268262
// We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
269263
// Why not using String? Because there might be minified files or even potentially
@@ -279,7 +273,7 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
279273
}
280274

281275
pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
282-
for entry in fs::read_dir(dir).unwrap() {
276+
for entry in fs_wrapper::read_dir(dir) {
283277
callback(&entry.unwrap().path());
284278
}
285279
}

‎tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
use std::path::PathBuf;
77

8-
use run_make_support::{aux_build, rustc, source_root};
8+
use run_make_support::{aux_build, fs_wrapper, rustc, source_root};
99

1010
fn main() {
1111
aux_build().input("stable.rs").emit("metadata").run();
1212

1313
let output =
1414
rustc().input("main.rs").emit("metadata").extern_("stable", "libstable.rmeta").run();
1515

16-
let version = std::fs::read_to_string(source_root().join("src/version")).unwrap();
16+
let version = fs_wrapper::read_to_string(source_root().join("src/version"));
1717
let expected_string = format!("stable since {}", version.trim());
1818
output.assert_stderr_contains(expected_string);
1919
}

‎tests/run-make/c-link-to-rust-dylib/rmake.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
//@ ignore-cross-compile
55

6-
use std::fs::remove_file;
7-
8-
use run_make_support::{cc, cwd, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc};
6+
use run_make_support::{
7+
cc, cwd, dynamic_lib_extension, fs_wrapper, is_msvc, read_dir, run, run_fail, rustc,
8+
};
99

1010
fn main() {
1111
rustc().input("foo.rs").run();
@@ -28,7 +28,7 @@ fn main() {
2828
name.ends_with(".so") || name.ends_with(".dll") || name.ends_with(".dylib")
2929
})
3030
{
31-
remove_file(path).unwrap();
31+
fs_wrapper::remove_file(path);
3232
}
3333
});
3434
run_fail("bar");

‎tests/run-make/c-link-to-rust-staticlib/rmake.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33

44
//@ ignore-cross-compile
55

6+
use run_make_support::fs_wrapper::remove_file;
67
use run_make_support::{cc, extra_c_flags, run, rustc, static_lib_name};
78
use std::fs;
89

910
fn main() {
1011
rustc().input("foo.rs").run();
1112
cc().input("bar.c").input(static_lib_name("foo")).out_exe("bar").args(&extra_c_flags()).run();
1213
run("bar");
13-
fs::remove_file(static_lib_name("foo"));
14+
remove_file(static_lib_name("foo"));
1415
run("bar");
1516
}

‎tests/run-make/cdylib/rmake.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010

1111
//@ ignore-cross-compile
1212

13-
use std::fs::remove_file;
14-
15-
use run_make_support::{cc, cwd, dynamic_lib_name, is_msvc, run, rustc};
13+
use run_make_support::{cc, cwd, dynamic_lib_name, fs_wrapper, is_msvc, run, rustc};
1614

1715
fn main() {
1816
rustc().input("bar.rs").run();
@@ -25,7 +23,7 @@ fn main() {
2523
}
2624

2725
run("foo");
28-
remove_file(dynamic_lib_name("foo")).unwrap();
26+
fs_wrapper::remove_file(dynamic_lib_name("foo"));
2927

3028
rustc().input("foo.rs").arg("-Clto").run();
3129
run("foo");

‎tests/run-make/compiler-builtins/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#![deny(warnings)]
1616

17+
use run_make_support::fs_wrapper::{read, read_dir};
1718
use run_make_support::object::read::archive::ArchiveFile;
1819
use run_make_support::object::read::Object;
1920
use run_make_support::object::ObjectSection;
@@ -55,8 +56,7 @@ fn main() {
5556
cmd.run();
5657

5758
let rlibs_path = target_dir.join(target).join("debug").join("deps");
58-
let compiler_builtins_rlib = std::fs::read_dir(rlibs_path)
59-
.unwrap()
59+
let compiler_builtins_rlib = read_dir(rlibs_path)
6060
.find_map(|e| {
6161
let path = e.unwrap().path();
6262
let file_name = path.file_name().unwrap().to_str().unwrap();
@@ -70,7 +70,7 @@ fn main() {
7070

7171
// rlib files are archives, where the archive members each a CGU, and we also have one called
7272
// lib.rmeta which is the encoded metadata. Each of the CGUs is an object file.
73-
let data = std::fs::read(compiler_builtins_rlib).unwrap();
73+
let data = read(compiler_builtins_rlib);
7474

7575
let mut defined_symbols = HashSet::new();
7676
let mut undefined_relocations = HashSet::new();

‎tests/run-make/const-prop-lint/rmake.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
// Tests that const prop lints interrupting codegen don't leave `.o` files around.
22

3-
use std::fs;
4-
5-
use run_make_support::{cwd, rustc};
3+
use run_make_support::{cwd, fs_wrapper, rustc};
64

75
fn main() {
86
rustc().input("input.rs").run_fail().assert_exit_code(1);
97

10-
for entry in fs::read_dir(cwd()).unwrap() {
8+
for entry in fs_wrapper::read_dir(cwd()) {
119
let entry = entry.unwrap();
1210
let path = entry.path();
1311

‎tests/run-make/doctests-keep-binaries/rmake.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Check that valid binaries are persisted by running them, regardless of whether the
22
// --run or --no-run option is used.
33

4+
use run_make_support::fs_wrapper::{create_dir, remove_dir_all};
45
use run_make_support::{run, rustc, rustdoc};
5-
use std::fs::{create_dir, remove_dir_all};
66
use std::path::Path;
77

88
fn setup_test_env<F: FnOnce(&Path, &Path)>(callback: F) {
99
let out_dir = Path::new("doctests");
10-
create_dir(&out_dir).expect("failed to create doctests folder");
10+
create_dir(&out_dir);
1111
rustc().input("t.rs").crate_type("rlib").run();
1212
callback(&out_dir, Path::new("libt.rlib"));
1313
remove_dir_all(out_dir);
@@ -43,9 +43,9 @@ fn main() {
4343
check_generated_binaries();
4444
});
4545
// Behavior with --test-run-directory with relative paths.
46-
setup_test_env(|_out_dir, extern_path| {
46+
setup_test_env(|_out_dir, _extern_path| {
4747
let run_dir_path = Path::new("rundir");
48-
create_dir(&run_dir_path).expect("failed to create rundir folder");
48+
create_dir(&run_dir_path);
4949

5050
rustdoc()
5151
.input("t.rs")

‎tests/run-make/doctests-runtool/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Tests behavior of rustdoc `--runtool`.
22

3+
use run_make_support::fs_wrapper::{create_dir, remove_dir_all};
34
use run_make_support::{rustc, rustdoc};
4-
use std::fs::{create_dir, remove_dir_all};
55
use std::path::PathBuf;
66

77
fn mkdir(name: &str) -> PathBuf {
88
let dir = PathBuf::from(name);
9-
create_dir(&dir).expect("failed to create doctests folder");
9+
create_dir(&dir);
1010
dir
1111
}
1212

‎tests/run-make/emit-named-files/rmake.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use std::fs::create_dir;
21
use std::path::Path;
32

4-
use run_make_support::rustc;
3+
use run_make_support::{fs_wrapper, rustc};
54

65
fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
76
let out_file = out_dir.join(out_file);
@@ -12,7 +11,7 @@ fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
1211
fn main() {
1312
let out_dir = Path::new("emit");
1413

15-
create_dir(&out_dir).unwrap();
14+
fs_wrapper::create_dir(&out_dir);
1615

1716
emit_and_check(&out_dir, "libfoo.s", "asm");
1817
emit_and_check(&out_dir, "libfoo.bc", "llvm-bc");

‎tests/run-make/incr-prev-body-beyond-eof/rmake.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
//@ ignore-nvptx64-nvidia-cuda
1414
// FIXME: can't find crate for `std`
1515

16+
use run_make_support::fs_wrapper as fs;
1617
use run_make_support::rustc;
17-
use std::fs;
1818

1919
fn main() {
20-
// FIXME(Oneirical): Use run_make_support::fs_wrapper here.
21-
fs::create_dir("src").unwrap();
22-
fs::create_dir("incr").unwrap();
23-
fs::copy("a.rs", "src/main.rs").unwrap();
20+
fs::create_dir("src");
21+
fs::create_dir("incr");
22+
fs::copy("a.rs", "src/main.rs");
2423
rustc().incremental("incr").input("src/main.rs").run();
25-
fs::copy("b.rs", "src/main.rs").unwrap();
24+
fs::copy("b.rs", "src/main.rs");
2625
rustc().incremental("incr").input("src/main.rs").run();
2726
}

‎tests/run-make/issue-107495-archive-permissions/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
#[cfg(unix)]
44
extern crate libc;
55

6-
use run_make_support::aux_build;
7-
use std::fs;
6+
use run_make_support::{aux_build, fs_wrapper};
7+
88
#[cfg(unix)]
99
use std::os::unix::fs::PermissionsExt;
1010
use std::path::Path;
@@ -20,7 +20,7 @@ fn main() {
2020
}
2121

2222
fn verify(path: &Path) {
23-
let perm = fs::metadata(path).unwrap().permissions();
23+
let perm = fs_wrapper::metadata(path).permissions();
2424

2525
assert!(!perm.readonly());
2626

‎tests/run-make/mixing-formats/rmake.rs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
//@ ignore-cross-compile
1414

1515
use run_make_support::{run_in_tmpdir, rustc};
16-
use std::fs;
1716

1817
fn main() {
1918
run_in_tmpdir(|| {
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use run_make_support::fs_wrapper;
12
use run_make_support::rustc;
23

34
fn main() {
@@ -6,6 +7,6 @@ fn main() {
67
#[cfg(windows)]
78
let non_unicode: std::ffi::OsString = std::os::windows::ffi::OsStringExt::from_wide(&[0xD800]);
89
let output = rustc().input("non_unicode_env.rs").env("NON_UNICODE_VAR", non_unicode).run_fail();
9-
let expected = std::fs::read_to_string("non_unicode_env.stderr").unwrap();
10+
let expected = fs_wrapper::read_to_string("non_unicode_env.stderr");
1011
output.assert_stderr_equals(expected);
1112
}

‎tests/run-make/non-unicode-in-incremental-dir/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use run_make_support::rustc;
1+
use run_make_support::{fs_wrapper, rustc};
22

33
fn main() {
44
#[cfg(unix)]
@@ -17,8 +17,8 @@ fn main() {
1717
}
1818
let incr_dir = "incr-dir";
1919
rustc().input("foo.rs").incremental(&incr_dir).run();
20-
for crate_dir in std::fs::read_dir(&incr_dir).unwrap() {
21-
std::fs::create_dir(crate_dir.unwrap().path().join(&non_unicode)).unwrap();
20+
for crate_dir in fs_wrapper::read_dir(&incr_dir) {
21+
fs_wrapper::create_dir(crate_dir.unwrap().path().join(&non_unicode));
2222
}
2323
rustc().input("foo.rs").incremental(&incr_dir).run();
2424
}

‎tests/run-make/print-cfg/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::ffi::OsString;
1010
use std::iter::FromIterator;
1111
use std::path::PathBuf;
1212

13-
use run_make_support::rustc;
13+
use run_make_support::{fs_wrapper, rustc};
1414

1515
struct PrintCfg {
1616
target: &'static str,
@@ -96,7 +96,7 @@ fn check(PrintCfg { target, includes, disallow }: PrintCfg) {
9696

9797
rustc().target(target).arg(print_arg).run();
9898

99-
let output = std::fs::read_to_string(&tmp_path).unwrap();
99+
let output = fs_wrapper::read_to_string(&tmp_path);
100100

101101
check_(&output, includes, disallow);
102102
}

‎tests/run-make/print-to-output/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
use std::ffi::OsString;
55
use std::path::PathBuf;
66

7-
use run_make_support::{rustc, target};
7+
use run_make_support::{fs_wrapper, rustc, target};
88

99
struct Option<'a> {
1010
target: &'a str,
@@ -49,7 +49,7 @@ fn check(args: Option) {
4949

5050
rustc().target(args.target).arg(print_arg).run();
5151

52-
std::fs::read_to_string(&tmp_path).unwrap()
52+
fs_wrapper::read_to_string(&tmp_path)
5353
};
5454

5555
check_(&stdout, args.includes);

‎tests/run-make/repr128-dwarf/rmake.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use gimli::{AttributeValue, EndianRcSlice, Reader, RunTimeEndian};
55
use object::{Object, ObjectSection};
6-
use run_make_support::{gimli, object, rustc};
6+
use run_make_support::{fs_wrapper, gimli, object, rustc};
77
use std::collections::HashMap;
88
use std::path::PathBuf;
99
use std::rc::Rc;
@@ -19,8 +19,7 @@ fn main() {
1919
.join("DWARF")
2020
.join("repr128");
2121
let output =
22-
std::fs::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output })
23-
.unwrap();
22+
fs_wrapper::read(if dsym_location.try_exists().unwrap() { dsym_location } else { output });
2423
let obj = object::File::parse(output.as_slice()).unwrap();
2524
let endian = if obj.is_little_endian() { RunTimeEndian::Little } else { RunTimeEndian::Big };
2625
let dwarf = gimli::Dwarf::load(|section| -> Result<_, ()> {

‎tests/run-make/reset-codegen-1/rmake.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
//@ ignore-cross-compile
99

10-
use run_make_support::rustc;
11-
use std::fs;
10+
use run_make_support::{bin_name, fs_wrapper, rustc};
11+
use std::path::Path;
1212

1313
fn compile(output_file: &str, emit: Option<&str>) {
1414
let mut rustc = rustc();
@@ -28,11 +28,15 @@ fn main() {
2828
("link-output", Some("link")),
2929
("obj-output", Some("obj")),
3030
("dep-output", Some("dep-info")),
31-
("multi-output", Some("asm,obj")),
3231
];
3332
for (output_file, emit) in flags {
34-
fs::remove_file(output_file).unwrap_or_default();
33+
// In the None case, bin_name is required for successful Windows compilation.
34+
let output_file = &bin_name(output_file);
3535
compile(output_file, emit);
36-
fs::remove_file(output_file);
36+
assert!(Path::new(output_file).is_file());
3737
}
38+
39+
compile("multi-output", Some("asm,obj"));
40+
assert!(Path::new("multi-output.s").is_file());
41+
assert!(Path::new("multi-output.o").is_file());
3842
}

‎tests/run-make/resolve-rename/rmake.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
// the renamed library.
66
// See https://github.com/rust-lang/rust/pull/49253
77

8+
use run_make_support::fs_wrapper;
89
use run_make_support::rustc;
9-
use std::fs;
10+
1011
fn main() {
1112
rustc().extra_filename("-hash").input("foo.rs").run();
1213
rustc().input("bar.rs").run();
13-
fs::rename("libfoo-hash.rlib", "libfoo-another-hash.rlib").unwrap();
14+
fs_wrapper::rename("libfoo-hash.rlib", "libfoo-another-hash.rlib");
1415
rustc().input("baz.rs").run();
1516
}

‎tests/run-make/rustdoc-scrape-examples-remap/scrape.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
use run_make_support::{htmldocck, rustc, rustdoc, source_root};
2-
use std::fs::read_dir;
1+
use run_make_support::{fs_wrapper, htmldocck, rustc, rustdoc, source_root};
32
use std::path::Path;
43

54
pub fn scrape(extra_args: &[&str]) {
65
let out_dir = Path::new("rustdoc");
76
let crate_name = "foobar";
8-
let deps = read_dir("examples")
9-
.unwrap()
7+
let deps = fs_wrapper::read_dir("examples")
108
.filter_map(|entry| entry.ok().map(|e| e.path()))
119
.filter(|path| path.is_file() && path.extension().is_some_and(|ext| ext == "rs"))
1210
.collect::<Vec<_>>();

‎tests/run-make/rustdoc-test-args/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use run_make_support::rustdoc;
1+
use run_make_support::{fs_wrapper, rustdoc};
2+
use std::iter;
23
use std::path::Path;
3-
use std::{fs, iter};
44

55
fn generate_a_lot_of_cfgs(path: &Path) {
66
let content = iter::repeat("--cfg=a\n").take(100_000).collect::<String>();
7-
fs::write(path, content.as_bytes()).expect("failed to create args file");
7+
fs_wrapper::write(path, content.as_bytes());
88
}
99

1010
fn main() {

‎tests/run-make/rustdoc-themes/rmake.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Test that rustdoc will properly load in a theme file and display it in the theme selector.
22

3-
use run_make_support::{htmldocck, rustdoc, source_root};
3+
use run_make_support::{fs_wrapper, htmldocck, rustdoc, source_root};
44
use std::path::Path;
55

66
fn main() {
77
let out_dir = Path::new("rustdoc-themes");
88
let test_css = "test.css";
99

10-
let no_script =
11-
std::fs::read_to_string(source_root().join("src/librustdoc/html/static/css/noscript.css"))
12-
.unwrap();
10+
let no_script = fs_wrapper::read_to_string(
11+
source_root().join("src/librustdoc/html/static/css/noscript.css"),
12+
);
1313

1414
let mut test_content = String::new();
1515
let mut found_begin_light = false;
@@ -24,8 +24,8 @@ fn main() {
2424
}
2525
}
2626
assert!(!test_content.is_empty());
27-
std::fs::create_dir_all(&out_dir).unwrap();
28-
std::fs::write(&test_css, test_content).unwrap();
27+
fs_wrapper::create_dir_all(&out_dir);
28+
fs_wrapper::write(&test_css, test_content);
2929

3030
rustdoc().output(&out_dir).input("foo.rs").arg("--theme").arg(&test_css).run();
3131
assert!(htmldocck().arg(out_dir).arg("foo.rs").status().unwrap().success());

‎tests/run-make/rustdoc-verify-output-files/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::fs::copy;
1+
use run_make_support::fs_wrapper::copy;
22
use std::path::{Path, PathBuf};
33

44
use run_make_support::{copy_dir_all, recursive_diff, rustdoc};
@@ -38,7 +38,7 @@ fn main() {
3838
assert!(out_dir.join("foobar.json").is_file());
3939

4040
// Copy first json output to check if it's exactly same after second compilation.
41-
copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json")).unwrap();
41+
copy(out_dir.join("foobar.json"), tmp_out_dir.join("foobar.json"));
4242

4343
// Generate json doc on the same output.
4444
generate_docs(&out_dir, JsonOutput::Yes);

‎tests/run-make/wasm-custom-section/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::collections::HashMap;
55

66
fn main() {
77
rustc().input("foo.rs").target("wasm32-wasip1").run();
88
rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
99

10-
let file = std::fs::read("bar.wasm").unwrap();
10+
let file = fs_wrapper::read("bar.wasm");
1111

1212
let mut custom = HashMap::new();
1313
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-custom-sections-opt/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::collections::HashMap;
55
use std::path::Path;
66

77
fn main() {
88
rustc().input("foo.rs").target("wasm32-wasip1").opt().run();
99

10-
verify(&Path::new("foo.wasm"));
10+
verify(Path::new("foo.wasm"));
1111
}
1212

1313
fn verify(path: &Path) {
1414
eprintln!("verify {path:?}");
15-
let file = std::fs::read(&path).unwrap();
15+
let file = fs_wrapper::read(&path);
1616

1717
let mut custom = HashMap::new();
1818
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-export-all-symbols/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::collections::HashMap;
55
use std::path::Path;
66
use wasmparser::ExternalKind::*;
@@ -33,7 +33,7 @@ fn test(args: &[&str]) {
3333

3434
fn verify_exports(path: &Path, exports: &[(&str, wasmparser::ExternalKind)]) {
3535
println!("verify {path:?}");
36-
let file = std::fs::read(path).unwrap();
36+
let file = fs_wrapper::read(path);
3737
let mut wasm_exports = HashMap::new();
3838
for payload in wasmparser::Parser::new(0).parse_all(&file) {
3939
let payload = payload.unwrap();

‎tests/run-make/wasm-import-module/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::collections::HashMap;
55
use wasmparser::TypeRef::Func;
66

77
fn main() {
88
rustc().input("foo.rs").target("wasm32-wasip1").run();
99
rustc().input("bar.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
1010

11-
let file = std::fs::read("bar.wasm").unwrap();
11+
let file = fs_wrapper::read("bar.wasm");
1212

1313
let mut imports = HashMap::new();
1414
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-panic-small/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//@ only-wasm32-wasip1
22
#![deny(warnings)]
33

4-
use run_make_support::rustc;
4+
use run_make_support::{fs_wrapper, rustc};
55

66
fn main() {
77
test("a");
@@ -15,7 +15,7 @@ fn test(cfg: &str) {
1515

1616
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().cfg(cfg).run();
1717

18-
let bytes = std::fs::read("foo.wasm").unwrap();
18+
let bytes = fs_wrapper::read("foo.wasm");
1919
println!("{}", bytes.len());
2020
assert!(bytes.len() < 40_000);
2121
}

‎tests/run-make/wasm-spurious-import/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::collections::HashMap;
55

66
fn main() {
@@ -13,7 +13,7 @@ fn main() {
1313
.arg("-Copt-level=z")
1414
.run();
1515

16-
let file = std::fs::read("main.wasm").unwrap();
16+
let file = fs_wrapper::read("main.wasm");
1717

1818
let mut imports = HashMap::new();
1919
for payload in wasmparser::Parser::new(0).parse_all(&file) {
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
//@ only-wasm32-wasip1
22
#![deny(warnings)]
33

4-
use run_make_support::rustc;
4+
use run_make_support::{fs_wrapper, rustc};
55

66
fn main() {
77
rustc().input("foo.rs").target("wasm32-wasip1").arg("-Clto").opt().run();
88

9-
let bytes = std::fs::read("foo.wasm").unwrap();
9+
let bytes = fs_wrapper::read("foo.wasm");
1010
println!("{}", bytes.len());
1111
assert!(bytes.len() < 50_000);
1212
}

‎tests/run-make/wasm-symbols-different-module/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::collections::{HashMap, HashSet};
55
use std::path::Path;
66

@@ -23,7 +23,7 @@ fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) {
2323

2424
rustc().input(file).target("wasm32-wasip1").args(args).run();
2525

26-
let file = std::fs::read(Path::new(file).with_extension("wasm")).unwrap();
26+
let file = fs_wrapper::read(Path::new(file).with_extension("wasm"));
2727

2828
let mut imports = HashMap::new();
2929
for payload in wasmparser::Parser::new(0).parse_all(&file) {

‎tests/run-make/wasm-symbols-not-exported/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::path::Path;
55

66
fn main() {
@@ -17,7 +17,7 @@ fn main() {
1717

1818
fn verify_symbols(path: &Path) {
1919
eprintln!("verify {path:?}");
20-
let file = std::fs::read(&path).unwrap();
20+
let file = fs_wrapper::read(&path);
2121

2222
for payload in wasmparser::Parser::new(0).parse_all(&file) {
2323
let payload = payload.unwrap();

‎tests/run-make/wasm-symbols-not-imported/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//@ only-wasm32-wasip1
22

3-
use run_make_support::{rustc, wasmparser};
3+
use run_make_support::{fs_wrapper, rustc, wasmparser};
44
use std::path::Path;
55

66
fn main() {
@@ -16,7 +16,7 @@ fn main() {
1616

1717
fn verify_symbols(path: &Path) {
1818
eprintln!("verify {path:?}");
19-
let file = std::fs::read(&path).unwrap();
19+
let file = fs_wrapper::read(&path);
2020

2121
for payload in wasmparser::Parser::new(0).parse_all(&file) {
2222
let payload = payload.unwrap();

‎tests/run-make/windows-ws2_32/rmake.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// Tests that WS2_32.dll is not unnecessarily linked, see issue #85441
44

55
use run_make_support::object::{self, read::Object};
6-
use run_make_support::rustc;
7-
use std::fs;
6+
use run_make_support::{fs_wrapper, rustc};
87

98
fn main() {
109
rustc().input("empty.rs").run();
@@ -15,7 +14,7 @@ fn main() {
1514
}
1615

1716
fn links_ws2_32(exe: &str) -> bool {
18-
let binary_data = fs::read(exe).unwrap();
17+
let binary_data = fs_wrapper::read(exe);
1918
let file = object::File::parse(&*binary_data).unwrap();
2019
for import in file.imports().unwrap() {
2120
if import.library().eq_ignore_ascii_case(b"WS2_32.dll") {

0 commit comments

Comments
 (0)
Please sign in to comment.