From 4eea02e725052a8941abd728cb1da98e4d9770a8 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 4 Oct 2020 16:26:09 -0400 Subject: [PATCH] Normalize MIRI_TEMP before using it --- tests/run-pass/fs.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/run-pass/fs.rs b/tests/run-pass/fs.rs index 947c650197cc..f74d1c9a36b1 100644 --- a/tests/run-pass/fs.rs +++ b/tests/run-pass/fs.rs @@ -29,7 +29,19 @@ fn main() { } fn tmp() -> PathBuf { - std::env::var("MIRI_TEMP").map(PathBuf::from).unwrap_or_else(|_| std::env::temp_dir()) + std::env::var("MIRI_TEMP") + .map(|tmp| { + // MIRI_TEMP is set outside of our emulated + // program, so it may have path separators that don't + // correspond to our target platform. We normalize them here + // before constructing a `PathBuf` + + #[cfg(windows)] + return PathBuf::from(tmp.replace("/", "\\")); + + #[cfg(not(windows))] + return PathBuf::from(tmp.replace("\\", "/")); + }).unwrap_or_else(|_| std::env::temp_dir()) } /// Prepare: compute filename and make sure the file does not exist.