Auto merge of #3366 - RalfJung:tempdir, r=oli-obk

compiletest: create fresh tempdir for tests to use

Fixes https://github.com/rust-lang/miri/issues/3364
This commit is contained in:
bors 2024-03-09 07:11:10 +00:00
commit cabac98df8
4 changed files with 32 additions and 15 deletions

View File

@ -497,6 +497,7 @@ dependencies = [
"regex", "regex",
"rustc_version", "rustc_version",
"smallvec", "smallvec",
"tempfile",
"ui_test", "ui_test",
] ]

View File

@ -45,6 +45,7 @@ ui_test = "0.21.1"
rustc_version = "0.4" rustc_version = "0.4"
regex = "1.5.5" regex = "1.5.5"
lazy_static = "1.4.0" lazy_static = "1.4.0"
tempfile = "3"
[package.metadata.rust-analyzer] [package.metadata.rust-analyzer]
# This crate uses #[feature(rustc_private)]. # This crate uses #[feature(rustc_private)].

View File

@ -79,13 +79,6 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
program.args.push(flag); program.args.push(flag);
} }
// Add a test env var to do environment communication tests.
program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
let miri_temp = env::var_os("MIRI_TEMP").unwrap_or_else(|| env::temp_dir().into());
program.envs.push(("MIRI_TEMP".into(), Some(miri_temp)));
let mut config = Config { let mut config = Config {
target: Some(target.to_owned()), target: Some(target.to_owned()),
stderr_filters: STDERR.clone(), stderr_filters: STDERR.clone(),
@ -116,9 +109,21 @@ fn test_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) ->
config config
} }
fn run_tests(mode: Mode, path: &str, target: &str, with_dependencies: bool) -> Result<()> { fn run_tests(
mode: Mode,
path: &str,
target: &str,
with_dependencies: bool,
tmpdir: &Path,
) -> Result<()> {
let mut config = test_config(target, path, mode, with_dependencies); let mut config = test_config(target, path, mode, with_dependencies);
// Add a test env var to do environment communication tests.
config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into())));
// Let the tests know where to store temp files (they might run for a different target, which can make this hard to find).
config.program.envs.push(("MIRI_TEMP".into(), Some(tmpdir.to_owned().into())));
// Handle command-line arguments. // Handle command-line arguments.
let args = ui_test::Args::test()?; let args = ui_test::Args::test()?;
let default_bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); let default_bless = env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0");
@ -211,7 +216,13 @@ enum Dependencies {
use Dependencies::*; use Dependencies::*;
fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) -> Result<()> { fn ui(
mode: Mode,
path: &str,
target: &str,
with_dependencies: Dependencies,
tmpdir: &Path,
) -> Result<()> {
let msg = format!("## Running ui tests in {path} against miri for {target}"); let msg = format!("## Running ui tests in {path} against miri for {target}");
eprintln!("{}", msg.green().bold()); eprintln!("{}", msg.green().bold());
@ -219,7 +230,7 @@ fn ui(mode: Mode, path: &str, target: &str, with_dependencies: Dependencies) ->
WithDependencies => true, WithDependencies => true,
WithoutDependencies => false, WithoutDependencies => false,
}; };
run_tests(mode, path, target, with_dependencies) run_tests(mode, path, target, with_dependencies, tmpdir)
} }
fn get_target() -> String { fn get_target() -> String {
@ -230,6 +241,7 @@ fn main() -> Result<()> {
ui_test::color_eyre::install()?; ui_test::color_eyre::install()?;
let target = get_target(); let target = get_target();
let tmpdir = tempfile::Builder::new().prefix("miri-compiletest-").tempdir()?;
let mut args = std::env::args_os(); let mut args = std::env::args_os();
@ -240,28 +252,31 @@ fn main() -> Result<()> {
} }
} }
ui(Mode::Pass, "tests/pass", &target, WithoutDependencies)?; ui(Mode::Pass, "tests/pass", &target, WithoutDependencies, tmpdir.path())?;
ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies)?; ui(Mode::Pass, "tests/pass-dep", &target, WithDependencies, tmpdir.path())?;
ui(Mode::Panic, "tests/panic", &target, WithDependencies)?; ui(Mode::Panic, "tests/panic", &target, WithDependencies, tmpdir.path())?;
ui( ui(
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled }, Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
"tests/fail", "tests/fail",
&target, &target,
WithoutDependencies, WithoutDependencies,
tmpdir.path(),
)?; )?;
ui( ui(
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled }, Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
"tests/fail-dep", "tests/fail-dep",
&target, &target,
WithDependencies, WithDependencies,
tmpdir.path(),
)?; )?;
if cfg!(target_os = "linux") { if cfg!(target_os = "linux") {
ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies)?; ui(Mode::Pass, "tests/extern-so/pass", &target, WithoutDependencies, tmpdir.path())?;
ui( ui(
Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled }, Mode::Fail { require_patterns: true, rustfix: RustfixMode::Disabled },
"tests/extern-so/fail", "tests/extern-so/fail",
&target, &target,
WithoutDependencies, WithoutDependencies,
tmpdir.path(),
)?; )?;
} }

View File

@ -295,7 +295,7 @@ fn test_canonicalize() {
drop(File::create(&path).unwrap()); drop(File::create(&path).unwrap());
let p = canonicalize(format!("{}/./test_file", dir_path.to_string_lossy())).unwrap(); let p = canonicalize(format!("{}/./test_file", dir_path.to_string_lossy())).unwrap();
assert_eq!(p.to_string_lossy().find('.'), None); assert_eq!(p.to_string_lossy().find("/./"), None);
remove_dir_all(&dir_path).unwrap(); remove_dir_all(&dir_path).unwrap();
} }