@@ -18,7 +18,7 @@ const TONIC_INCLUDES: &[&str] = &["src/proto/opentelemetry-proto", "src/proto"];
18
18
19
19
#[ test]
20
20
fn build_tonic ( ) {
21
- let before_build = build_content_map ( TONIC_OUT_DIR ) ;
21
+ let before_build = build_content_map ( TONIC_OUT_DIR , false ) ;
22
22
23
23
let out_dir = TempDir :: new ( ) . expect ( "failed to create temp dir to store the generated files" ) ;
24
24
@@ -95,11 +95,11 @@ fn build_tonic() {
95
95
. compile ( TONIC_PROTO_FILES , TONIC_INCLUDES )
96
96
. expect ( "cannot compile protobuf using tonic" ) ;
97
97
98
- let after_build = build_content_map ( out_dir. path ( ) ) ;
98
+ let after_build = build_content_map ( out_dir. path ( ) , true ) ;
99
99
ensure_files_are_same ( before_build, after_build, TONIC_OUT_DIR ) ;
100
100
}
101
101
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 > {
103
103
std:: fs:: read_dir ( path)
104
104
. expect ( "cannot open dictionary of generated files" )
105
105
. flatten ( )
@@ -108,14 +108,28 @@ fn build_content_map(path: impl AsRef<Path>) -> HashMap<String, String> {
108
108
let file_name = path
109
109
. file_name ( )
110
110
. 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)
115
120
} )
116
121
. collect ( )
117
122
}
118
123
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
+
119
133
fn ensure_files_are_same (
120
134
before_build : HashMap < String , String > ,
121
135
after_build : HashMap < String , String > ,
0 commit comments