Skip to content

Commit 1ffa953

Browse files
committed
Normalize test newlines
Tests pass with CRLF newlines now
1 parent e6e6125 commit 1ffa953

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tests/testutils/src/lib.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,21 @@ use std::fs::read_dir;
66

77
use difference::Changeset;
88

9+
/// Read file and normalize newlines.
10+
///
11+
/// `rustc` seems to always normalize `\r\n` newlines to `\n`:
12+
///
13+
/// ```
14+
/// let s = "
15+
/// ";
16+
/// assert_eq!(s.as_bytes, &[10]);
17+
/// ```
18+
///
19+
/// so this should always be correct.
20+
fn read_text(path: &Path) -> String {
21+
file::get_text(path).unwrap().replace("\r\n", "\n")
22+
}
23+
924
pub fn dir_tests<F>(
1025
paths: &[&str],
1126
f: F
@@ -15,7 +30,7 @@ where
1530
{
1631
for path in collect_tests(paths) {
1732
let actual = {
18-
let text = file::get_text(&path).unwrap();
33+
let text = read_text(&path);
1934
f(&text)
2035
};
2136
let path = path.with_extension("txt");
@@ -25,7 +40,7 @@ where
2540
file::put_text(&path, actual).unwrap();
2641
panic!("No expected result")
2742
}
28-
let expected = file::get_text(&path).unwrap();
43+
let expected = read_text(&path);
2944
let expected = expected.as_str();
3045
let actual = actual.as_str();
3146
assert_equal_text(expected, actual, &path);

0 commit comments

Comments
 (0)