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;
66
77use 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+
924pub fn dir_tests < F > (
1025 paths : & [ & str ] ,
1126 f : F
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" ) ;
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) ;
You can’t perform that action at this time.
0 commit comments