From 26bcf58bfe051504e7b894a8cf59ea2125712dce Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Thu, 9 May 2024 09:08:18 -0400 Subject: [PATCH] test(rustfix): run some tests only on nightly --- Cargo.lock | 2 +- crates/rustfix/Cargo.toml | 2 +- ...rs => multiple-solutions.nightly.fixed.rs} | 0 ...s.json => multiple-solutions.nightly.json} | 0 ...tions.rs => multiple-solutions.nightly.rs} | 0 crates/rustfix/tests/parse_and_replace.rs | 33 +++++++++++++++++++ 6 files changed, 35 insertions(+), 2 deletions(-) rename crates/rustfix/tests/everything/{multiple-solutions.fixed.rs => multiple-solutions.nightly.fixed.rs} (100%) rename crates/rustfix/tests/everything/{multiple-solutions.json => multiple-solutions.nightly.json} (100%) rename crates/rustfix/tests/everything/{multiple-solutions.rs => multiple-solutions.nightly.rs} (100%) diff --git a/Cargo.lock b/Cargo.lock index 8158ebeeb..e5611f1f0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2938,7 +2938,7 @@ checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" [[package]] name = "rustfix" -version = "0.8.3" +version = "0.8.4" dependencies = [ "anyhow", "proptest", diff --git a/crates/rustfix/Cargo.toml b/crates/rustfix/Cargo.toml index 533d028d9..1f9b61cd5 100644 --- a/crates/rustfix/Cargo.toml +++ b/crates/rustfix/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rustfix" -version = "0.8.3" +version = "0.8.4" authors = [ "Pascal Hertleif ", "Oliver Schneider ", diff --git a/crates/rustfix/tests/everything/multiple-solutions.fixed.rs b/crates/rustfix/tests/everything/multiple-solutions.nightly.fixed.rs similarity index 100% rename from crates/rustfix/tests/everything/multiple-solutions.fixed.rs rename to crates/rustfix/tests/everything/multiple-solutions.nightly.fixed.rs diff --git a/crates/rustfix/tests/everything/multiple-solutions.json b/crates/rustfix/tests/everything/multiple-solutions.nightly.json similarity index 100% rename from crates/rustfix/tests/everything/multiple-solutions.json rename to crates/rustfix/tests/everything/multiple-solutions.nightly.json diff --git a/crates/rustfix/tests/everything/multiple-solutions.rs b/crates/rustfix/tests/everything/multiple-solutions.nightly.rs similarity index 100% rename from crates/rustfix/tests/everything/multiple-solutions.rs rename to crates/rustfix/tests/everything/multiple-solutions.nightly.rs diff --git a/crates/rustfix/tests/parse_and_replace.rs b/crates/rustfix/tests/parse_and_replace.rs index 949903b23..7bb11d332 100644 --- a/crates/rustfix/tests/parse_and_replace.rs +++ b/crates/rustfix/tests/parse_and_replace.rs @@ -45,6 +45,26 @@ mod settings { pub const BLESS: &str = "RUSTFIX_TEST_BLESS"; } +static mut VERSION: (u32, bool) = (0, false); + +// Temporarily copy from `cargo_test_macro::version`. +fn version() -> (u32, bool) { + static INIT: std::sync::Once = std::sync::Once::new(); + INIT.call_once(|| { + let output = Command::new("rustc") + .arg("-V") + .output() + .expect("cargo should run"); + let stdout = std::str::from_utf8(&output.stdout).expect("utf8"); + let vers = stdout.split_whitespace().skip(1).next().unwrap(); + let is_nightly = option_env!("CARGO_TEST_DISABLE_NIGHTLY").is_none() + && (vers.contains("-nightly") || vers.contains("-dev")); + let minor = vers.split('.').skip(1).next().unwrap().parse().unwrap(); + unsafe { VERSION = (minor, is_nightly) } + }); + unsafe { VERSION } +} + fn compile(file: &Path) -> Result { let tmp = tempdir()?; @@ -220,7 +240,20 @@ fn assert_fixtures(dir: &str, mode: &str) { .unwrap(); let mut failures = 0; + let is_not_nightly = !version().1; + for file in &files { + if file + .file_stem() + .unwrap() + .to_str() + .unwrap() + .ends_with(".nightly") + && is_not_nightly + { + info!("skipped: {file:?}"); + continue; + } if let Err(err) = test_rustfix_with_file(file, mode) { println!("failed: {}", file.display()); warn!("{:?}", err);