aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils/src/lib.rs
diff options
context:
space:
mode:
authorChristopher Durham <[email protected]>2018-01-28 00:17:05 +0000
committerChristopher Durham <[email protected]>2018-01-28 00:19:53 +0000
commit58ff03086fe53308879e754e05e49a7048ac0457 (patch)
treed8aa87979040fc2a20bdc084b955beb2b77c1c98 /tests/testutils/src/lib.rs
parente6e61251abb68b3e6a47fd3708f4dea6059a9ec3 (diff)
Normalize test newlines
Tests pass with CRLF newlines now
Diffstat (limited to 'tests/testutils/src/lib.rs')
-rw-r--r--tests/testutils/src/lib.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/tests/testutils/src/lib.rs b/tests/testutils/src/lib.rs
index b34517c5f..80a94fb66 100644
--- a/tests/testutils/src/lib.rs
+++ b/tests/testutils/src/lib.rs
@@ -6,6 +6,21 @@ use std::fs::read_dir;
6 6
7use difference::Changeset; 7use difference::Changeset;
8 8
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.
20fn read_text(path: &Path) -> String {
21 file::get_text(path).unwrap().replace("\r\n", "\n")
22}
23
9pub fn dir_tests<F>( 24pub fn dir_tests<F>(
10 paths: &[&str], 25 paths: &[&str],
11 f: F 26 f: F
@@ -15,7 +30,7 @@ where
15{ 30{
16 for path in collect_tests(paths) { 31 for path in collect_tests(paths) {
17 let actual = { 32 let actual = {
18 let text = file::get_text(&path).unwrap(); 33 let text = read_text(&path);
19 f(&text) 34 f(&text)
20 }; 35 };
21 let path = path.with_extension("txt"); 36 let path = path.with_extension("txt");
@@ -25,7 +40,7 @@ where
25 file::put_text(&path, actual).unwrap(); 40 file::put_text(&path, actual).unwrap();
26 panic!("No expected result") 41 panic!("No expected result")
27 } 42 }
28 let expected = file::get_text(&path).unwrap(); 43 let expected = read_text(&path);
29 let expected = expected.as_str(); 44 let expected = expected.as_str();
30 let actual = actual.as_str(); 45 let actual = actual.as_str();
31 assert_equal_text(expected, actual, &path); 46 assert_equal_text(expected, actual, &path);