@@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];
1818
1919#[ test]
2020fn build_tonic ( ) {
21- let before_build = build_content_map ( TONIC_OUT_DIR ) ;
21+ let before_build = build_content_map ( TONIC_OUT_DIR , false ) ;
2222
2323 let out_dir = TempDir :: new ( ) . expect ( "failed to create temp dir to store the generated files" ) ;
2424
@@ -95,11 +95,11 @@ fn build_tonic() {
9595 . compile ( TONIC_PROTO_FILES , TONIC_INCLUDES )
9696 . expect ( "cannot compile protobuf using tonic" ) ;
9797
98- let after_build = build_content_map ( out_dir. path ( ) ) ;
98+ let after_build = build_content_map ( out_dir. path ( ) , true ) ;
9999 ensure_files_are_same ( before_build, after_build, TONIC_OUT_DIR ) ;
100100}
101101
102- fn build_content_map ( path : impl AsRef < Path > ) -> HashMap < String , String > {
102+ fn build_content_map ( path : impl AsRef < Path > , normalize_line_feed : bool ) -> HashMap < String , String > {
103103 std:: fs:: read_dir ( path)
104104 . expect ( "cannot open dictionary of generated files" )
105105 . flatten ( )
@@ -108,14 +108,28 @@ fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
108108 let file_name = path
109109 . file_name ( )
110110 . expect ( "file name should always exist for generated files" ) ;
111- (
112- file_name. to_string_lossy ( ) . to_string ( ) ,
113- std:: fs:: read_to_string ( path) . expect ( "cannot read from existing generated file" ) ,
114- )
111+
112+ let mut file_contents = std:: fs:: read_to_string ( path. clone ( ) )
113+ . expect ( "cannot read from existing generated file" ) ;
114+
115+ if normalize_line_feed {
116+ file_contents = get_platform_specific_string ( file_contents) ;
117+ }
118+
119+ ( file_name. to_string_lossy ( ) . to_string ( ) , file_contents)
115120 } )
116121 . collect ( )
117122}
118123
124+ /// Returns a String with the platform specific new line feed character.
125+ fn get_platform_specific_string ( input : String ) -> String {
126+ if cfg ! ( windows) {
127+ input. replace ( '\n' , "\r \n " )
128+ } else {
129+ input
130+ }
131+ }
132+
119133fn ensure_files_are_same (
120134 before_build : HashMap < String , String > ,
121135 after_build : HashMap < String , String > ,
0 commit comments