aboutsummaryrefslogtreecommitdiff
path: root/tests/testutils/src/lib.rs
diff options
context:
space:
mode:
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);