diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 00:24:27 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 00:24:27 +0000 |
commit | 6d3caf58ca042cf6b5707822e51619adf511acd0 (patch) | |
tree | 3043582bb7927d5ea494cdea29323cd4e666dc47 /tests/testutils | |
parent | 5e0752ceda8f195c2e40727cc59a4b86b97b2e1b (diff) | |
parent | 58ff03086fe53308879e754e05e49a7048ac0457 (diff) |
Merge #14
14: Normalize test newlines r=matklad a=CAD97
Tests pass with CRLF newlines now
Diffstat (limited to 'tests/testutils')
-rw-r--r-- | tests/testutils/src/lib.rs | 19 |
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 | ||
7 | use difference::Changeset; | 7 | use 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. | ||
20 | fn read_text(path: &Path) -> String { | ||
21 | file::get_text(path).unwrap().replace("\r\n", "\n") | ||
22 | } | ||
23 | |||
9 | pub fn dir_tests<F>( | 24 | pub 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); |