Skip to content

Commit

Permalink
test(rustfix): run some tests only on nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo authored and epage committed May 22, 2024
1 parent c99b2e5 commit 8bfa91b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rustfix/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rustfix"
version = "0.8.3"
version = "0.8.4"
authors = [
"Pascal Hertleif <[email protected]>",
"Oliver Schneider <[email protected]>",
Expand Down
33 changes: 33 additions & 0 deletions crates/rustfix/tests/parse_and_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Output, Error> {
let tmp = tempdir()?;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8bfa91b

Please sign in to comment.