Skip to content

Commit d86c981

Browse files
committed
Remove all usages of tmp_dir from tests
1 parent 94ccb9b commit d86c981

File tree

64 files changed

+182
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+182
-210
lines changed

src/tools/run-make-support/src/cc.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::path::Path;
22
use std::process::Command;
33

4-
use crate::{
5-
bin_name, cygpath_windows, env_var, handle_failed_output, is_msvc, is_windows, tmp_dir, uname,
6-
};
4+
use crate::{bin_name, cygpath_windows, env_var, handle_failed_output, is_msvc, is_windows, uname};
75

86
/// Construct a new platform-specific C compiler invocation.
97
///

src/tools/run-make-support/src/clang.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::Path;
22
use std::process::Command;
33

4-
use crate::{bin_name, env_var, handle_failed_output, tmp_dir};
4+
use crate::{bin_name, env_var, handle_failed_output};
55

66
/// Construct a new `clang` invocation. `clang` is not always available for all targets.
77
pub fn clang() -> Clang {

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

+5
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ pub fn bin_name(name: &str) -> String {
171171
if is_windows() { format!("{name}.exe") } else { name.to_string() }
172172
}
173173

174+
/// Return the current working directory.
175+
pub fn cwd() -> PathBuf {
176+
env::current_dir().unwrap()
177+
}
178+
174179
/// Use `cygpath -w` on a path to get a Windows path string back. This assumes that `cygpath` is
175180
/// available on the platform!
176181
#[track_caller]

tests/run-make/CURRENT_RUSTC_VERSION/rmake.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ use run_make_support::{aux_build, rustc};
1010
fn main() {
1111
aux_build().input("stable.rs").emit("metadata").run();
1212

13-
let mut stable_path = PathBuf::from(env!("TMPDIR"));
14-
stable_path.push("libstable.rmeta");
15-
16-
let output =
17-
rustc().input("main.rs").emit("metadata").extern_("stable", &stable_path).command_output();
13+
let output = rustc()
14+
.input("main.rs")
15+
.emit("metadata")
16+
.extern_("stable", "libstable.rmeta")
17+
.command_output();
1818

1919
let stderr = String::from_utf8_lossy(&output.stderr);
2020
let version = include_str!(concat!(env!("S"), "/src/version"));

tests/run-make/artifact-incr-cache-no-obj/rmake.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
//
66
// Fixes: rust-lang/rust#123234
77

8-
use run_make_support::{rustc, tmp_dir};
8+
use run_make_support::rustc;
99

1010
fn main() {
11-
let inc_dir = tmp_dir();
12-
1311
for _ in 0..=1 {
1412
rustc()
1513
.input("lib.rs")
1614
.crate_type("lib")
1715
.emit("asm,dep-info,link,mir,llvm-ir,llvm-bc")
18-
.incremental(&inc_dir)
16+
.incremental("incremental")
1917
.run();
2018
}
2119
}

tests/run-make/artifact-incr-cache/rmake.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
// Also see discussion at
88
// <https://internals.rust-lang.org/t/interaction-between-incremental-compilation-and-emit/20551>
99

10-
use run_make_support::{rustc, tmp_dir};
10+
use run_make_support::rustc;
1111

1212
fn main() {
13-
let inc_dir = tmp_dir();
14-
1513
for _ in 0..=1 {
1614
rustc()
1715
.input("lib.rs")
1816
.crate_type("lib")
1917
.emit("obj,asm,dep-info,link,mir,llvm-ir,llvm-bc")
20-
.incremental(&inc_dir)
18+
.incremental("incremental")
2119
.run();
2220
}
2321
}

tests/run-make/box-struct-no-segfault/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
// This test checks that this bug does not resurface.
66
// See https://github.com/rust-lang/rust/issues/28766
77

8-
use run_make_support::{rustc, tmp_dir};
8+
use run_make_support::rustc;
99

1010
fn main() {
1111
rustc().opt().input("foo.rs").run();
12-
rustc().opt().library_search_path(tmp_dir()).input("main.rs").run();
12+
rustc().opt().input("main.rs").run();
1313
}

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

+4-10
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,23 @@
55

66
use std::fs::remove_file;
77

8-
use run_make_support::{
9-
cc, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc, tmp_dir,
10-
};
8+
use run_make_support::{cc, cwd, dynamic_lib_extension, is_msvc, read_dir, run, run_fail, rustc};
119

1210
fn main() {
1311
rustc().input("foo.rs").run();
1412

1513
if is_msvc() {
16-
let lib = tmp_dir().join("foo.dll.lib");
14+
let lib = "foo.dll.lib";
1715

1816
cc().input("bar.c").arg(lib).out_exe("bar").run();
1917
} else {
20-
cc().input("bar.c")
21-
.arg("-lfoo")
22-
.output(tmp_dir().join("bar"))
23-
.library_search_path(tmp_dir())
24-
.run();
18+
cc().input("bar.c").arg("-lfoo").output("bar").library_search_path(cwd()).run();
2519
}
2620

2721
run("bar");
2822

2923
let expected_extension = dynamic_lib_extension();
30-
read_dir(tmp_dir(), |path| {
24+
read_dir(std::env::current_dir().unwrap(), |path| {
3125
if path.is_file()
3226
&& path.extension().is_some_and(|ext| ext == expected_extension)
3327
&& path.file_name().and_then(|name| name.to_str()).is_some_and(|name| {

tests/run-make/cdylib/rmake.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,16 @@
1212

1313
use std::fs::remove_file;
1414

15-
use run_make_support::{cc, dynamic_lib, is_msvc, run, rustc, tmp_dir};
15+
use run_make_support::{cc, cwd, dynamic_lib, is_msvc, run, rustc};
1616

1717
fn main() {
1818
rustc().input("bar.rs").run();
1919
rustc().input("foo.rs").run();
2020

2121
if is_msvc() {
22-
cc().input("foo.c").arg(tmp_dir().join("foo.dll.lib")).out_exe("foo").run();
22+
cc().input("foo.c").arg("foo.dll.lib").out_exe("foo").run();
2323
} else {
24-
cc().input("foo.c")
25-
.arg("-lfoo")
26-
.output(tmp_dir().join("foo"))
27-
.library_search_path(tmp_dir())
28-
.run();
24+
cc().input("foo.c").arg("-lfoo").library_search_path(cwd()).output("foo").run();
2925
}
3026

3127
run("foo");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "scratch"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
path = "lib.rs"
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#![no_std]

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

+3-15
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,17 @@ use run_make_support::object::ObjectSection;
2020
use run_make_support::object::ObjectSymbol;
2121
use run_make_support::object::RelocationTarget;
2222
use run_make_support::set_host_rpath;
23-
use run_make_support::tmp_dir;
2423
use run_make_support::{env_var, object};
2524
use std::collections::HashSet;
26-
27-
const MANIFEST: &str = r#"
28-
[package]
29-
name = "scratch"
30-
version = "0.1.0"
31-
edition = "2021"
32-
33-
[lib]
34-
path = "lib.rs""#;
25+
use std::path::PathBuf;
3526

3627
fn main() {
37-
let target_dir = tmp_dir().join("target");
28+
let target_dir = PathBuf::from("target");
3829
let target = env_var("TARGET");
3930

4031
println!("Testing compiler_builtins for {}", target);
4132

42-
// Set up the tiniest Cargo project: An empty no_std library. Just enough to run -Zbuild-std.
43-
let manifest_path = tmp_dir().join("Cargo.toml");
44-
std::fs::write(&manifest_path, MANIFEST.as_bytes()).unwrap();
45-
std::fs::write(tmp_dir().join("lib.rs"), b"#![no_std]").unwrap();
33+
let manifest_path = PathBuf::from("Cargo.toml");
4634

4735
let path = env_var("PATH");
4836
let rustc = env_var("RUSTC");

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
use std::fs;
44

5-
use run_make_support::{rustc, tmp_dir};
5+
use run_make_support::rustc;
66

77
fn main() {
88
rustc().input("input.rs").run_fail_assert_exit_code(1);
99

10-
for entry in fs::read_dir(tmp_dir()).unwrap() {
10+
for entry in fs::read_dir(std::env::current_dir().unwrap()).unwrap() {
1111
let entry = entry.unwrap();
1212
let path = entry.path();
1313

tests/run-make/core-no-oom-handling/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// when the no_global_oom_handling feature is turned on.
33
// See https://github.com/rust-lang/rust/pull/110649
44

5-
use run_make_support::{rustc, source_root, tmp_dir};
5+
use run_make_support::{rustc, source_root};
66

77
fn main() {
88
rustc()
99
.edition("2021")
1010
.arg("-Dwarnings")
1111
.crate_type("rlib")
1212
.input(source_root().join("library/core/src/lib.rs"))
13-
.sysroot(tmp_dir().join("fakeroot"))
13+
.sysroot("fakeroot")
1414
.cfg("no_global_oom_handling")
1515
.run();
1616
}

tests/run-make/cross-lang-lto-riscv-abi/rmake.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//@ needs-matching-clang
44
//@ needs-llvm-components riscv
55

6-
use run_make_support::{bin_name, clang, llvm_readobj, rustc, tmp_dir};
6+
use run_make_support::{bin_name, clang, llvm_readobj, rustc};
77
use std::{
88
env,
99
path::PathBuf,
@@ -30,11 +30,11 @@ fn check_target(target: &str, clang_target: &str, carch: &str, is_double_float:
3030
.no_stdlib()
3131
.out_exe("riscv-xlto")
3232
.input("cstart.c")
33-
.input(tmp_dir().join("libriscv_xlto.rlib"))
33+
.input("libriscv_xlto.rlib")
3434
.run();
3535

3636
// Check that the built binary has correct float abi
37-
let executable = tmp_dir().join(bin_name("riscv-xlto"));
37+
let executable = bin_name("riscv-xlto");
3838
let output = llvm_readobj().input(&executable).file_header().run();
3939
let stdout = String::from_utf8_lossy(&output.stdout);
4040
eprintln!("obj:\n{}", stdout);

tests/run-make/deref-impl-rustdoc-ice/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
//@ ignore-cross-compile
99

10-
use run_make_support::{rustc, rustdoc, tmp_dir};
10+
use run_make_support::{cwd, rustc, rustdoc};
1111

1212
fn main() {
1313
rustc().input("foo.rs").run();
1414
rustc().input("bar.rs").run();
15-
rustdoc().input("baz.rs").library_search_path(tmp_dir()).output(tmp_dir()).run();
15+
rustdoc().input("baz.rs").library_search_path(cwd()).output(cwd()).run();
1616
}

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

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
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::{run, rustc, rustdoc, tmp_dir};
4+
use run_make_support::{run, rustc, rustdoc};
55
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) {
9-
let out_dir = tmp_dir().join("doctests");
9+
let out_dir = Path::new("doctests");
1010
create_dir(&out_dir).expect("failed to create doctests folder");
1111
rustc().input("t.rs").crate_type("rlib").run();
12-
callback(&out_dir, &tmp_dir().join("libt.rlib"));
12+
callback(&out_dir, Path::new("libt.rlib"));
1313
remove_dir_all(out_dir);
1414
}
1515

@@ -44,19 +44,17 @@ fn main() {
4444
});
4545
// Behavior with --test-run-directory with relative paths.
4646
setup_test_env(|_out_dir, extern_path| {
47-
let run_dir = "rundir";
48-
let run_dir_path = tmp_dir().join("rundir");
47+
let run_dir_path = Path::new("rundir");
4948
create_dir(&run_dir_path).expect("failed to create rundir folder");
5049

5150
rustdoc()
52-
.current_dir(tmp_dir())
53-
.input(std::env::current_dir().unwrap().join("t.rs"))
51+
.input("t.rs")
5452
.arg("-Zunstable-options")
5553
.arg("--test")
5654
.arg("--persist-doctests")
5755
.arg("doctests")
5856
.arg("--test-run-directory")
59-
.arg(run_dir)
57+
.arg(run_dir_path)
6058
.extern_("t", "libt.rlib")
6159
.run();
6260

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

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

3-
use run_make_support::{rustc, rustdoc, tmp_dir};
4-
use std::env::current_dir;
3+
use run_make_support::{rustc, rustdoc};
54
use std::fs::{create_dir, remove_dir_all};
65
use std::path::PathBuf;
76

87
fn mkdir(name: &str) -> PathBuf {
9-
let dir = tmp_dir().join(name);
8+
let dir = PathBuf::from(name);
109
create_dir(&dir).expect("failed to create doctests folder");
1110
dir
1211
}
@@ -22,15 +21,14 @@ fn main() {
2221
rustc().input("runtool.rs").output(&run_tool_binary).run();
2322

2423
rustdoc()
25-
.input(current_dir().unwrap().join("t.rs"))
24+
.input("t.rs")
2625
.arg("-Zunstable-options")
2726
.arg("--test")
2827
.arg("--test-run-directory")
2928
.arg(run_dir_name)
3029
.arg("--runtool")
3130
.arg(&run_tool_binary)
3231
.extern_("t", "libt.rlib")
33-
.current_dir(tmp_dir())
3432
.run();
3533

3634
remove_dir_all(run_dir);

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fs::create_dir;
22
use std::path::Path;
33

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

66
fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
77
let out_file = out_dir.join(out_file);
@@ -10,7 +10,7 @@ fn emit_and_check(out_dir: &Path, out_file: &str, format: &str) {
1010
}
1111

1212
fn main() {
13-
let out_dir = tmp_dir().join("emit");
13+
let out_dir = Path::new("emit");
1414

1515
create_dir(&out_dir).unwrap();
1616

tests/run-make/exit-code/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Test that we exit with the correct exit code for successful / unsuccessful / ICE compilations
22

3-
use run_make_support::{rustc, rustdoc, tmp_dir};
3+
use run_make_support::{rustc, rustdoc};
44

55
fn main() {
66
rustc().arg("success.rs").run();
@@ -15,7 +15,7 @@ fn main() {
1515
.arg("compile-error.rs")
1616
.run_fail_assert_exit_code(101);
1717

18-
rustdoc().arg("success.rs").output(tmp_dir().join("exit-code")).run();
18+
rustdoc().arg("success.rs").output("exit-code").run();
1919

2020
rustdoc().arg("--invalid-arg-foo").run_fail_assert_exit_code(1);
2121

tests/run-make/external-crate-panic-handle-no-lint/rmake.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
// and cause the test to fail.
55
// See https://github.com/rust-lang/rust/issues/53964
66

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

99
fn main() {
1010
rustc().input("panic.rs").run();
11-
rustc().input("app.rs").panic("abort").emit("obj").library_search_path(tmp_dir()).run();
11+
rustc().input("app.rs").panic("abort").emit("obj").run();
1212
}

0 commit comments

Comments
 (0)