From 928f30695d2fd14d4d26406c7b0e49f01fffc548 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 1 Oct 2024 15:50:51 +0200 Subject: [PATCH 1/2] Avoid a bool and use an Option of ZST instead --- src/tools/miri/tests/ui.rs | 36 +++++++++++++++++++++++------------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/src/tools/miri/tests/ui.rs b/src/tools/miri/tests/ui.rs index 9b9542b88a96..2c7d574d960d 100644 --- a/src/tools/miri/tests/ui.rs +++ b/src/tools/miri/tests/ui.rs @@ -82,9 +82,16 @@ fn build_native_lib() -> PathBuf { native_lib_path } +struct WithDependencies {} + /// Does *not* set any args or env vars, since it is shared between the test runner and /// run_dep_mode. -fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> Config { +fn miri_config( + target: &str, + path: &str, + mode: Mode, + with_dependencies: Option, +) -> Config { // Miri is rustc-like, so we create a default builder for rustc and modify it let mut program = CommandBuilder::rustc(); program.program = miri_path(); @@ -119,7 +126,7 @@ fn miri_config(target: &str, path: &str, mode: Mode, with_dependencies: bool) -> // keep in sync with `./miri run` config.comment_defaults.base().add_custom("edition", Edition("2021".into())); - if with_dependencies { + if let Some(WithDependencies {}) = with_dependencies { config.comment_defaults.base().set_custom("dependencies", DependencyBuilder { program: CommandBuilder { // Set the `cargo-miri` binary, which we expect to be in the same folder as the `miri` binary. @@ -146,7 +153,20 @@ fn run_tests( with_dependencies: bool, tmpdir: &Path, ) -> Result<()> { + // Handle command-line arguments. + let mut args = ui_test::Args::test()?; + args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); + + let with_dependencies = with_dependencies.then_some(WithDependencies {}); + let mut config = miri_config(target, path, mode, with_dependencies); + config.with_args(&args); + config.bless_command = Some("./miri test --bless".into()); + + if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() { + assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"); + config.output_conflict_handling = OutputConflictHandling::Ignore; + } // Add a test env var to do environment communication tests. config.program.envs.push(("MIRI_ENV_VAR_TEST".into(), Some("0".into()))); @@ -182,16 +202,6 @@ fn run_tests( config.program.args.push(flag); } - // Handle command-line arguments. - let mut args = ui_test::Args::test()?; - args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); - config.with_args(&args); - config.bless_command = Some("./miri test --bless".into()); - - if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() { - assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"); - config.output_conflict_handling = OutputConflictHandling::Ignore; - } eprintln!(" Compiler: {}", config.program.display()); ui_test::run_tests_generic( // Only run one test suite. In the future we can add all test suites to one `Vec` and run @@ -327,7 +337,7 @@ fn main() -> Result<()> { } fn run_dep_mode(target: String, args: impl Iterator) -> Result<()> { - let mut config = miri_config(&target, "", Mode::RunDep, /* with dependencies */ true); + let mut config = miri_config(&target, "", Mode::RunDep, Some(WithDependencies {})); config.comment_defaults.base().custom.remove("edition"); // `./miri` adds an `--edition` in `args`, so don't set it twice config.fill_host_and_target()?; config.program.args = args.collect(); From 18f8310fe4ac9dfc2dd76567fb8a4a80c7889b55 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Mon, 7 Oct 2024 14:50:46 +0200 Subject: [PATCH 2/2] Bump ui_test --- src/tools/miri/Cargo.lock | 4 ++-- src/tools/miri/Cargo.toml | 2 +- src/tools/miri/tests/ui.rs | 16 ++++++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/tools/miri/Cargo.lock b/src/tools/miri/Cargo.lock index 363b96fdff1f..076a807c4ef6 100644 --- a/src/tools/miri/Cargo.lock +++ b/src/tools/miri/Cargo.lock @@ -1051,9 +1051,9 @@ checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "ui_test" -version = "0.26.5" +version = "0.27.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32ee4c40e5a5f9fa6864ff976473e5d6a6e9884b6ce68b40690d9f87e1994c83" +checksum = "180a1250feba0214b892e22c3a14e9f6688cc084d7b45ec4672106fcb7914641" dependencies = [ "annotate-snippets", "anyhow", diff --git a/src/tools/miri/Cargo.toml b/src/tools/miri/Cargo.toml index 6e8e270985e0..1d4657b0dfd8 100644 --- a/src/tools/miri/Cargo.toml +++ b/src/tools/miri/Cargo.toml @@ -47,8 +47,8 @@ windows-sys = { version = "0.52", features = [ ] } [dev-dependencies] +ui_test = "0.27.1" colored = "2" -ui_test = "0.26.5" rustc_version = "0.4" regex = "1.5.5" tempfile = "3" diff --git a/src/tools/miri/tests/ui.rs b/src/tools/miri/tests/ui.rs index 2c7d574d960d..a3760d306f87 100644 --- a/src/tools/miri/tests/ui.rs +++ b/src/tools/miri/tests/ui.rs @@ -13,7 +13,7 @@ use ui_test::custom_flags::edition::Edition; use ui_test::dependencies::DependencyBuilder; use ui_test::per_test_config::TestConfig; use ui_test::spanned::Spanned; -use ui_test::{CommandBuilder, Config, Format, Match, OutputConflictHandling, status_emitter}; +use ui_test::{CommandBuilder, Config, Format, Match, ignore_output_conflict, status_emitter}; #[derive(Copy, Clone, Debug)] enum Mode { @@ -82,7 +82,9 @@ fn build_native_lib() -> PathBuf { native_lib_path } -struct WithDependencies {} +struct WithDependencies { + bless: bool, +} /// Does *not* set any args or env vars, since it is shared between the test runner and /// run_dep_mode. @@ -126,7 +128,7 @@ fn miri_config( // keep in sync with `./miri run` config.comment_defaults.base().add_custom("edition", Edition("2021".into())); - if let Some(WithDependencies {}) = with_dependencies { + if let Some(WithDependencies { bless }) = with_dependencies { config.comment_defaults.base().set_custom("dependencies", DependencyBuilder { program: CommandBuilder { // Set the `cargo-miri` binary, which we expect to be in the same folder as the `miri` binary. @@ -141,6 +143,7 @@ fn miri_config( }, crate_manifest_path: Path::new("test_dependencies").join("Cargo.toml"), build_std: None, + bless_lockfile: bless, }); } config @@ -157,7 +160,7 @@ fn run_tests( let mut args = ui_test::Args::test()?; args.bless |= env::var_os("RUSTC_BLESS").is_some_and(|v| v != "0"); - let with_dependencies = with_dependencies.then_some(WithDependencies {}); + let with_dependencies = with_dependencies.then_some(WithDependencies { bless: args.bless }); let mut config = miri_config(target, path, mode, with_dependencies); config.with_args(&args); @@ -165,7 +168,7 @@ fn run_tests( if env::var_os("MIRI_SKIP_UI_CHECKS").is_some() { assert!(!args.bless, "cannot use RUSTC_BLESS and MIRI_SKIP_UI_CHECKS at the same time"); - config.output_conflict_handling = OutputConflictHandling::Ignore; + config.output_conflict_handling = ignore_output_conflict; } // Add a test env var to do environment communication tests. @@ -337,7 +340,8 @@ fn main() -> Result<()> { } fn run_dep_mode(target: String, args: impl Iterator) -> Result<()> { - let mut config = miri_config(&target, "", Mode::RunDep, Some(WithDependencies {})); + let mut config = + miri_config(&target, "", Mode::RunDep, Some(WithDependencies { bless: false })); config.comment_defaults.base().custom.remove("edition"); // `./miri` adds an `--edition` in `args`, so don't set it twice config.fill_host_and_target()?; config.program.args = args.collect();