Skip to content

Commit 7297f0f

Browse files
committed
Auto merge of #13890 - weihanglo:rustfix, r=ehuss
test(rustfix): run some tests only on nightly
2 parents 1fec089 + a477661 commit 7297f0f

File tree

6 files changed

+94
-9
lines changed

6 files changed

+94
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/rustfix/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rustfix"
3-
version = "0.8.3"
3+
version = "0.8.4"
44
authors = [
55
"Pascal Hertleif <killercup@gmail.com>",
66
"Oliver Schneider <oli-obk@users.noreply.github.com>",

crates/rustfix/tests/everything/multiple-solutions.fixed.rs renamed to crates/rustfix/tests/everything/multiple-solutions.nightly.fixed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::{HashSet};
1+
use std::collections::HashSet;
22

33
fn main() {
44
let _: HashSet<()>;

crates/rustfix/tests/everything/multiple-solutions.json renamed to crates/rustfix/tests/everything/multiple-solutions.nightly.json

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$message_type": "diagnostic",
23
"message": "unused imports: `HashMap`, `VecDeque`",
34
"code": {
45
"code": "unused_imports",
@@ -7,7 +8,7 @@
78
"level": "warning",
89
"spans": [
910
{
10-
"file_name": "src/main.rs",
11+
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
1112
"byte_start": 23,
1213
"byte_end": 30,
1314
"line_start": 1,
@@ -28,7 +29,7 @@
2829
"expansion": null
2930
},
3031
{
31-
"file_name": "src/main.rs",
32+
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
3233
"byte_start": 41,
3334
"byte_end": 49,
3435
"line_start": 1,
@@ -51,7 +52,7 @@
5152
],
5253
"children": [
5354
{
54-
"message": "#[warn(unused_imports)] on by default",
55+
"message": "`#[warn(unused_imports)]` on by default",
5556
"code": null,
5657
"level": "note",
5758
"spans": [],
@@ -64,7 +65,28 @@
6465
"level": "help",
6566
"spans": [
6667
{
67-
"file_name": "src/main.rs",
68+
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
69+
"byte_start": 22,
70+
"byte_end": 23,
71+
"line_start": 1,
72+
"line_end": 1,
73+
"column_start": 23,
74+
"column_end": 24,
75+
"is_primary": true,
76+
"text": [
77+
{
78+
"text": "use std::collections::{HashMap, HashSet, VecDeque};",
79+
"highlight_start": 23,
80+
"highlight_end": 24
81+
}
82+
],
83+
"label": null,
84+
"suggested_replacement": "",
85+
"suggestion_applicability": "MachineApplicable",
86+
"expansion": null
87+
},
88+
{
89+
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
6890
"byte_start": 23,
6991
"byte_end": 32,
7092
"line_start": 1,
@@ -85,7 +107,7 @@
85107
"expansion": null
86108
},
87109
{
88-
"file_name": "src/main.rs",
110+
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
89111
"byte_start": 39,
90112
"byte_end": 49,
91113
"line_start": 1,
@@ -104,11 +126,41 @@
104126
"suggested_replacement": "",
105127
"suggestion_applicability": "MachineApplicable",
106128
"expansion": null
129+
},
130+
{
131+
"file_name": "./tests/everything/multiple-solutions.nightly.rs",
132+
"byte_start": 49,
133+
"byte_end": 50,
134+
"line_start": 1,
135+
"line_end": 1,
136+
"column_start": 50,
137+
"column_end": 51,
138+
"is_primary": true,
139+
"text": [
140+
{
141+
"text": "use std::collections::{HashMap, HashSet, VecDeque};",
142+
"highlight_start": 50,
143+
"highlight_end": 51
144+
}
145+
],
146+
"label": null,
147+
"suggested_replacement": "",
148+
"suggestion_applicability": "MachineApplicable",
149+
"expansion": null
107150
}
108151
],
109152
"children": [],
110153
"rendered": null
111154
}
112155
],
113-
"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"
156+
"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"
157+
}
158+
{
159+
"$message_type": "diagnostic",
160+
"message": "1 warning emitted",
161+
"code": null,
162+
"level": "warning",
163+
"spans": [],
164+
"children": [],
165+
"rendered": "warning: 1 warning emitted\n\n"
114166
}

crates/rustfix/tests/parse_and_replace.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ mod settings {
4545
pub const BLESS: &str = "RUSTFIX_TEST_BLESS";
4646
}
4747

48+
static mut VERSION: (u32, bool) = (0, false);
49+
50+
// Temporarily copy from `cargo_test_macro::version`.
51+
fn version() -> (u32, bool) {
52+
static INIT: std::sync::Once = std::sync::Once::new();
53+
INIT.call_once(|| {
54+
let output = Command::new("rustc")
55+
.arg("-V")
56+
.output()
57+
.expect("cargo should run");
58+
let stdout = std::str::from_utf8(&output.stdout).expect("utf8");
59+
let vers = stdout.split_whitespace().skip(1).next().unwrap();
60+
let is_nightly = option_env!("CARGO_TEST_DISABLE_NIGHTLY").is_none()
61+
&& (vers.contains("-nightly") || vers.contains("-dev"));
62+
let minor = vers.split('.').skip(1).next().unwrap().parse().unwrap();
63+
unsafe { VERSION = (minor, is_nightly) }
64+
});
65+
unsafe { VERSION }
66+
}
67+
4868
fn compile(file: &Path) -> Result<Output, Error> {
4969
let tmp = tempdir()?;
5070

@@ -220,7 +240,20 @@ fn assert_fixtures(dir: &str, mode: &str) {
220240
.unwrap();
221241
let mut failures = 0;
222242

243+
let is_not_nightly = !version().1;
244+
223245
for file in &files {
246+
if file
247+
.file_stem()
248+
.unwrap()
249+
.to_str()
250+
.unwrap()
251+
.ends_with(".nightly")
252+
&& is_not_nightly
253+
{
254+
info!("skipped: {file:?}");
255+
continue;
256+
}
224257
if let Err(err) = test_rustfix_with_file(file, mode) {
225258
println!("failed: {}", file.display());
226259
warn!("{:?}", err);

0 commit comments

Comments
 (0)