File tree Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Expand file tree Collapse file tree 1 file changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,21 @@ use std::fs::read_dir;
6
6
7
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
24
pub fn dir_tests < F > (
10
25
paths : & [ & str ] ,
11
26
f : F
15
30
{
16
31
for path in collect_tests ( paths) {
17
32
let actual = {
18
- let text = file :: get_text ( & path) . unwrap ( ) ;
33
+ let text = read_text ( & path) ;
19
34
f ( & text)
20
35
} ;
21
36
let path = path. with_extension ( "txt" ) ;
25
40
file:: put_text ( & path, actual) . unwrap ( ) ;
26
41
panic ! ( "No expected result" )
27
42
}
28
- let expected = file :: get_text ( & path) . unwrap ( ) ;
43
+ let expected = read_text ( & path) ;
29
44
let expected = expected. as_str ( ) ;
30
45
let actual = actual. as_str ( ) ;
31
46
assert_equal_text ( expected, actual, & path) ;
You can’t perform that action at this time.
0 commit comments