Skip to content

Commit cabac98

Browse files
committed
Auto merge of rust-lang#3366 - RalfJung:tempdir, r=oli-obk
compiletest: create fresh tempdir for tests to use Fixes rust-lang/miri#3364
2 parents 4db028f + 4235ec5 commit cabac98

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

src/tools/miri/Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,7 @@ dependencies = [
497497
"regex",
498498
"rustc_version",
499499
"smallvec",
500+
"tempfile",
500501
"ui_test",
501502
]
502503

src/tools/miri/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ ui_test = "0.21.1"
4545
rustc_version = "0.4"
4646
regex = "1.5.5"
4747
lazy_static = "1.4.0"
48+
tempfile = "3"
4849

4950
[package.metadata.rust-analyzer]
5051
# This crate uses #[feature(rustc_private)].

src/tools/miri/tests/compiletest.rs

+29-14
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,6 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
7979
program.args.push(flag);
8080
}
8181

82-
// Add a test env var to do environment communication tests.
83-
program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
84-
85-
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
86-
let miri_temp = env::var_os("MIRI_TEMP").unwrap_or_else(|| env::temp_dir().into());
87-
program.envs.push(("MIRI_TEMP".into(), Some(miri_temp)));
88-
8982
let mut config = Config {
9083
target: Some(target.to_owned()),
9184
stderr_filters: STDERR.clone(),
@@ -116,9 +109,21 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
116109
config
117110
}
118111

119-
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> {
112+
fn run_tests(
113+
mode: Mode,
114+
path: &str,
115+
target: &str,
116+
with_dependencies: bool,
117+
tmpdir: &Path,
118+
) -> Result<()> {
120119
let mut config = test_config(target, path, mode, with_dependencies);
121120

121+
// Add a test env var to do environment communication tests.
122+
config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
123+
124+
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
125+
config.program.envs.push(("MIRI_TEMP".into(), Some(tmpdir.to_owned().into())));
126+
122127
// Handle command-line arguments.
123128
let args = ui_test::Args::test()?;
124129
let default_bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
@@ -211,15 +216,21 @@ enum Dependencies {
211216

212217
use Dependencies::*;
213218

214-
fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) -> Result<()> {
219+
fn ui(
220+
mode: Mode,
221+
path: &str,
222+
target: &str,
223+
with_dependencies: Dependencies,
224+
tmpdir: &Path,
225+
) -> Result<()> {
215226
let msg = format!("## Running ui tests in {path} against miri for {target}");
216227
eprintln!("{}", msg.green().bold());
217228

218229
let with_dependencies = match with_dependencies {
219230
WithDependencies => true,
220231
WithoutDependencies => false,
221232
};
222-
run_tests(mode, path, target, with_dependencies)
233+
run_tests(mode, path, target, with_dependencies, tmpdir)
223234
}
224235

225236
fn get_target() -> String {
@@ -230,6 +241,7 @@ fn main() -> Result<()> {
230241
ui_test::color_eyre::install()?;
231242

232243
let target = get_target();
244+
let tmpdir = tempfile::Builder::new().prefix("miri-compiletest-").tempdir()?;
233245

234246
let mut args = std::env::args_os();
235247

@@ -240,28 +252,31 @@ fn main() -> Result<()> {
240252
}
241253
}
242254

243-
ui(Mode::Pass, "tests/pass", &target, WithoutDependencies)?;
244-
ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies)?;
245-
ui(Mode::Panic, "tests/panic", &target, WithDependencies)?;
255+
ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?;
256+
ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies, tmpdir.path())?;
257+
ui(Mode::Panic, "tests/panic", &target, WithDependencies, tmpdir.path())?;
246258
ui(
247259
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
248260
"tests/fail",
249261
&target,
250262
WithoutDependencies,
263+
tmpdir.path(),
251264
)?;
252265
ui(
253266
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
254267
"tests/fail-dep",
255268
&target,
256269
WithDependencies,
270+
tmpdir.path(),
257271
)?;
258272
if cfg!(target_os = "linux") {
259-
ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies)?;
273+
ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies, tmpdir.path())?;
260274
ui(
261275
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
262276
"tests/extern-so/fail",
263277
&target,
264278
WithoutDependencies,
279+
tmpdir.path(),
265280
)?;
266281
}
267282

src/tools/miri/tests/pass/shims/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ fn test_canonicalize() {
295295
drop(File::create(&path).unwrap());
296296

297297
let p = canonicalize(format!("{}/./test_file", dir_path.to_string_lossy())).unwrap();
298-
assert_eq!(p.to_string_lossy().find('.'), None);
298+
assert_eq!(p.to_string_lossy().find("/./"), None);
299299

300300
remove_dir_all(&dir_path).unwrap();
301301
}

0 commit comments

Comments
 (0)