Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(rustfix): run some tests only on nightly #13890

Merged
merged 2 commits into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 <killercup@gmail.com>",
"Oliver Schneider <oli-obk@users.noreply.github.com>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashSet};
use std::collections::HashSet;

fn main() {
let _: HashSet<()>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"$message_type": "diagnostic",
"message": "unused imports: `HashMap`, `VecDeque`",
"code": {
"code": "unused_imports",
Expand All @@ -7,7 +8,7 @@
"level": "warning",
"spans": [
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 23,
"byte_end": 30,
"line_start": 1,
Expand All @@ -28,7 +29,7 @@
"expansion": null
},
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 41,
"byte_end": 49,
"line_start": 1,
Expand All @@ -51,7 +52,7 @@
],
"children": [
{
"message": "#[warn(unused_imports)] on by default",
"message": "`#[warn(unused_imports)]` on by default",
"code": null,
"level": "note",
"spans": [],
Expand All @@ -64,7 +65,28 @@
"level": "help",
"spans": [
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 22,
"byte_end": 23,
"line_start": 1,
"line_end": 1,
"column_start": 23,
"column_end": 24,
"is_primary": true,
"text": [
{
"text": "use std::collections::{HashMap, HashSet, VecDeque};",
"highlight_start": 23,
"highlight_end": 24
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
},
{
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 23,
"byte_end": 32,
"line_start": 1,
Expand All @@ -85,7 +107,7 @@
"expansion": null
},
{
"file_name": "src/main.rs",
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 39,
"byte_end": 49,
"line_start": 1,
Expand All @@ -104,11 +126,41 @@
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
},
{
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
"byte_start": 49,
"byte_end": 50,
"line_start": 1,
"line_end": 1,
"column_start": 50,
"column_end": 51,
"is_primary": true,
"text": [
{
"text": "use std::collections::{HashMap, HashSet, VecDeque};",
"highlight_start": 50,
"highlight_end": 51
}
],
"label": null,
"suggested_replacement": "",
"suggestion_applicability": "MachineApplicable",
"expansion": null
}
],
"children": [],
"rendered": null
}
],
"rendered": "warning: unused imports: `HashMap`, `VecDeque`\n --> src/main.rs:1:24\n |\n1 | use std::collections::{HashMap, HashSet, VecDeque};\n | ^^^^^^^ ^^^^^^^^\n |\n = note: #[warn(unused_imports)] on by default\nhelp: remove the unused imports\n |\n1 | use std::collections::{HashSet};\n | -- --\n\n"
"rendered": "warning: unused imports: `HashMap`, `VecDeque`\n --> ./tests/everything/multiple-solutions.nightly.rs:1:24\n |\n1 | use std::collections::{HashMap, HashSet, VecDeque};\n | ^^^^^^^ ^^^^^^^^\n |\n = note: `#[warn(unused_imports)]` on by default\n\n"
}
{
"$message_type": "diagnostic",
"message": "1 warning emitted",
"code": null,
"level": "warning",
"spans": [],
"children": [],
"rendered": "warning: 1 warning emitted\n\n"
}
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