Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit ac543e7

Browse files
committed
Merge #51
51: Fix test edge cases r=oli-obk a=killercup Noticed this while adding test case for ~~fun~~ rust-lang/rust-clippy#2350
2 parents fb54121 + 9121d77 commit ac543e7

File tree

5 files changed

+372
-4
lines changed

5 files changed

+372
-4
lines changed

tests/everything.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn compile_and_get_json_errors(file: &Path) -> Result<String, Box<Error>> {
3939

4040
use std::io::{Error, ErrorKind};
4141
match res.status.code() {
42-
Some(0) | Some(1) => Ok(stderr),
42+
Some(0) | Some(1) | Some(101) => Ok(stderr),
4343
_ => Err(Box::new(Error::new(
4444
ErrorKind::Other,
4545
format!("failed with status {:?}: {}", res.status.code(), stderr),
@@ -122,7 +122,7 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
122122
let json_file = file.with_extension("json");
123123
let fixed_file = file.with_extension("fixed.rs");
124124

125-
debug!("{:?}", file);
125+
debug!("next up: {:?}", file);
126126
let code = read_file(file)?;
127127
let errors = compile_and_get_json_errors(file)?;
128128
let suggestions = rustfix::get_suggestions_from_json(&errors, &HashSet::new());
@@ -143,7 +143,7 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
143143

144144
let mut fixed = code.clone();
145145

146-
for sug in suggestions {
146+
for sug in suggestions.into_iter().rev() {
147147
trace!("{:?}", sug);
148148
for sol in sug.solutions {
149149
trace!("{:?}", sol);
@@ -155,6 +155,12 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
155155
}
156156
}
157157

158+
if std::env::var("RUSTFIX_TEST_RECORD_FIXED_RUST").is_ok() {
159+
use std::io::Write;
160+
let mut recorded_rust = fs::File::create(&file.with_extension("recorded.rs"))?;
161+
recorded_rust.write_all(fixed.as_bytes())?;
162+
}
163+
158164
let expected_fixed = read_file(&fixed_file)?;
159165
assert_eq!(fixed.trim(), expected_fixed.trim(), "file doesn't look fixed");
160166

@@ -170,7 +176,7 @@ fn get_fixture_files() -> Result<Vec<PathBuf>, Box<Error>> {
170176
.filter(|p| p.is_file())
171177
.filter(|p| {
172178
let x = p.to_string_lossy();
173-
x.ends_with(".rs") && !x.ends_with(".fixed.rs")
179+
x.ends_with(".rs") && !x.ends_with(".fixed.rs") && !x.ends_with(".recorded.rs")
174180
})
175181
.collect())
176182
}

tests/fixtures/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.recorded.json
2+
*.recorded.rs
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let a = 42;
3+
4+
let b = 42;
5+
6+
let c = "x";
7+
}

0 commit comments

Comments
 (0)