@@ -73,6 +73,11 @@ mod tests {
73
73
syn:: parse2 ( tokens. into_token_stream ( ) ) . unwrap ( )
74
74
}
75
75
76
+ fn sanitize_code ( mut code : String ) -> String {
77
+ code. retain ( |c| c != '\r' ) ;
78
+ code
79
+ }
80
+
76
81
/// Helper for testing if a given input Rust file generates the expected C++ & Rust code
77
82
/// This needs to be a macro rather than a function because include_str needs the file path at compile time.
78
83
macro_rules! test_code_generation {
@@ -86,25 +91,31 @@ mod tests {
86
91
let generated_cpp = GeneratedCppBlocks :: from( & parser) . unwrap( ) ;
87
92
let ( header, source) =
88
93
if let CppFragment :: Pair { header, source } = write_cpp( & generated_cpp) {
89
- ( header, source)
94
+ ( sanitize_code ( header) , sanitize_code ( source) )
90
95
} else {
91
96
panic!( "Expected CppFragment::Pair" )
92
97
} ;
93
98
let expected_cpp_header =
94
- clang_format( include_str!( concat!( "../test_outputs/" , $file_stem, ".h" ) ) ) . unwrap( ) ;
99
+ clang_format( include_str!( concat!( "../test_outputs/" , $file_stem, ".h" ) ) )
100
+ . map( sanitize_code)
101
+ . unwrap( ) ;
95
102
let expected_cpp_source = clang_format( include_str!( concat!(
96
103
"../test_outputs/" ,
97
104
$file_stem,
98
105
".cpp"
99
106
) ) )
107
+ . map( sanitize_code)
100
108
. unwrap( ) ;
101
109
assert_str_eq!( header, expected_cpp_header) ;
102
110
assert_str_eq!( source, expected_cpp_source) ;
103
111
104
112
let generated_rust = GeneratedRustBlocks :: from( & parser) . unwrap( ) ;
105
- let rust = format_rs_source( & write_rust( & generated_rust) . to_string( ) ) ;
106
- let expected_rust_output =
107
- format_rs_source( include_str!( concat!( "../test_outputs/" , $file_stem, ".rs" ) ) ) ;
113
+ let rust = sanitize_code( format_rs_source( & write_rust( & generated_rust) . to_string( ) ) ) ;
114
+ let expected_rust_output = sanitize_code( format_rs_source( include_str!( concat!(
115
+ "../test_outputs/" ,
116
+ $file_stem,
117
+ ".rs"
118
+ ) ) ) ) ;
108
119
assert_str_eq!( rust, expected_rust_output) ;
109
120
} ;
110
121
}
0 commit comments