Skip to content

Commit

Permalink
Handle Windows newlines.
Browse files Browse the repository at this point in the history
Suggestions that come from rustc that are multi-line only use LF line
endings. But if the file is checked out on windows with CRLF
line-endings, then you end up with a mix of line endings that don't
match the "fixed.rs" file.

Tracking this at rust-lang/rust#119482.
  • Loading branch information
ehuss committed Jan 1, 2024
1 parent a21997f commit 3d3e1b3
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions crates/rustfix/tests/parse_and_replace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
}

let fixed = apply_suggestions(&code, &suggestions)
.context(format!("could not apply suggestions to {}", file.display()))?;
.context(format!("could not apply suggestions to {}", file.display()))?
.replace('\r', "");

if std::env::var(settings::RECORD_FIXED_RUST).is_ok() {
fs::write(file.with_extension("recorded.rs"), &fixed)?;
Expand All @@ -188,7 +189,8 @@ fn test_rustfix_with_file<P: AsRef<Path>>(file: P, mode: &str) -> Result<(), Err
}

let expected_fixed = fs::read_to_string(&fixed_file)
.context(format!("could read fixed file for {}", file.display()))?;
.context(format!("could read fixed file for {}", file.display()))?
.replace('\r', "");
ensure!(
fixed.trim() == expected_fixed.trim(),
"file {} doesn't look fixed:\n{}",
Expand Down

0 comments on commit 3d3e1b3

Please sign in to comment.