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

Fix test edge cases #51

Merged
merged 4 commits into from
Jan 18, 2018
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
14 changes: 10 additions & 4 deletions tests/everything.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn compile_and_get_json_errors(file: &Path) -> Result<String, Box<Error>> {

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

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

let mut fixed = code.clone();

for sug in suggestions {
for sug in suggestions.into_iter().rev() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a test

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only possible with an additional test that has a replacement that condenses n lines into m<n lines followed by ≥1 replacements.

…which I just added

trace!("{:?}", sug);
for sol in sug.solutions {
trace!("{:?}", sol);
Expand All @@ -155,6 +155,12 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P) -> Result<(), Box<Error>> {
}
}

if std::env::var("RUSTFIX_TEST_RECORD_FIXED_RUST").is_ok() {
use std::io::Write;
let mut recorded_rust = fs::File::create(&file.with_extension("recorded.rs"))?;
recorded_rust.write_all(fixed.as_bytes())?;
}

let expected_fixed = read_file(&fixed_file)?;
assert_eq!(fixed.trim(), expected_fixed.trim(), "file doesn't look fixed");

Expand All @@ -170,7 +176,7 @@ fn get_fixture_files() -> Result<Vec<PathBuf>, Box<Error>> {
.filter(|p| p.is_file())
.filter(|p| {
let x = p.to_string_lossy();
x.ends_with(".rs") && !x.ends_with(".fixed.rs")
x.ends_with(".rs") && !x.ends_with(".fixed.rs") && !x.ends_with(".recorded.rs")
})
.collect())
}
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.recorded.json
*.recorded.rs
7 changes: 7 additions & 0 deletions tests/fixtures/redundant_closure_call.fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
let a = 42;

let b = 42;

let c = "x";
}
Loading