@@ -10,10 +10,27 @@ mod integration {
1010 const PEOPLE_TSV_PATH : & ' static str = "test-resources/people.tsv" ;
1111 const PEOPLE_JSON_PATH : & ' static str = "test-resources/people.json" ;
1212
13+ fn native_newlines < S : Into < String > > ( s : S ) -> String {
14+ if cfg ! ( target_os = "windows" ) {
15+ return s. into ( ) . replace ( "\n " , "\r \n " ) ;
16+ }
17+
18+ s. into ( )
19+ }
20+
21+ fn read_resource ( path : & ' static str , fix_newlines : bool ) -> String {
22+ let s = std:: fs:: read_to_string ( path) . unwrap ( ) ;
23+ if fix_newlines {
24+ native_newlines ( s)
25+ } else {
26+ s
27+ }
28+ }
29+
1330 lazy_static:: lazy_static! {
14- static ref PEOPLE_CSV : String = std :: fs :: read_to_string ( PEOPLE_CSV_PATH ) . unwrap ( ) ;
15- static ref PEOPLE_TSV : String = std :: fs :: read_to_string ( PEOPLE_TSV_PATH ) . unwrap ( ) ;
16- static ref PEOPLE_JSON : String = std :: fs :: read_to_string ( PEOPLE_JSON_PATH ) . unwrap ( ) ;
31+ static ref PEOPLE_CSV : String = read_resource ( PEOPLE_CSV_PATH , true ) ;
32+ static ref PEOPLE_TSV : String = read_resource ( PEOPLE_TSV_PATH , true ) ;
33+ static ref PEOPLE_JSON : String = read_resource ( PEOPLE_JSON_PATH , false ) ;
1734 }
1835
1936 fn expect_people_json ( got_str : & str ) -> bool {
@@ -109,8 +126,11 @@ mod integration {
109126 . succeeds ( )
110127 . and ( )
111128 . stdout ( )
112- . is ( r#"Bart Simpson <bart@example.com>
113- Homer Simpson <homer@example.com>"# )
129+ . is ( native_newlines (
130+ r#"Bart Simpson <bart@example.com>
131+ Homer Simpson <homer@example.com>"# ,
132+ )
133+ . as_str ( ) )
114134 . unwrap ( ) ;
115135 }
116136
@@ -120,7 +140,8 @@ Homer Simpson <homer@example.com>"#)
120140 . with_args ( & [ "-i" , PEOPLE_JSON_PATH , "-F" , "csv" ] )
121141 . succeeds ( )
122142 . and ( )
123- . stdout ( ) . is ( PEOPLE_CSV . as_str ( ) )
143+ . stdout ( )
144+ . is ( PEOPLE_CSV . as_str ( ) )
124145 . unwrap ( ) ;
125146 }
126147}
0 commit comments