@@ -123,12 +123,23 @@ pub fn dynamic_lib_name(name: &str) -> String {
123123 // ```
124124 assert ! ( !name. contains( char :: is_whitespace) , "dynamic library name cannot contain whitespace" ) ;
125125
126+ let extension = dynamic_lib_extension ( ) ;
126127 if is_darwin ( ) {
127- format ! ( "lib{name}.dylib " )
128+ format ! ( "lib{name}.{extension} " )
128129 } else if is_windows ( ) {
129- format ! ( "{name}.dll " )
130+ format ! ( "{name}.{extension} " )
130131 } else {
131- format ! ( "lib{name}.so" )
132+ format ! ( "lib{name}.{extension}" )
133+ }
134+ }
135+
136+ pub fn dynamic_lib_extension ( ) -> & ' static str {
137+ if is_darwin ( ) {
138+ "dylib"
139+ } else if is_windows ( ) {
140+ "dll"
141+ } else {
142+ "so"
132143 }
133144}
134145
@@ -243,16 +254,13 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
243254 }
244255
245256 let dir2 = dir2. as_ref ( ) ;
246- for entry in fs:: read_dir ( dir1) . unwrap ( ) {
247- let entry = entry. unwrap ( ) ;
248- let entry_name = entry. file_name ( ) ;
249- let path = entry. path ( ) ;
250-
251- if path. is_dir ( ) {
252- recursive_diff ( & path, & dir2. join ( entry_name) ) ;
257+ read_dir ( dir1, |entry_path| {
258+ let entry_name = entry_path. file_name ( ) . unwrap ( ) ;
259+ if entry_path. is_dir ( ) {
260+ recursive_diff ( & entry_path, & dir2. join ( entry_name) ) ;
253261 } else {
254262 let path2 = dir2. join ( entry_name) ;
255- let file1 = read_file ( & path ) ;
263+ let file1 = read_file ( & entry_path ) ;
256264 let file2 = read_file ( & path2) ;
257265
258266 // We don't use `assert_eq!` because they are `Vec<u8>`, so not great for display.
@@ -261,10 +269,16 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
261269 assert ! (
262270 file1 == file2,
263271 "`{}` and `{}` have different content" ,
264- path . display( ) ,
272+ entry_path . display( ) ,
265273 path2. display( ) ,
266274 ) ;
267275 }
276+ } ) ;
277+ }
278+
279+ pub fn read_dir < F : Fn ( & Path ) > ( dir : impl AsRef < Path > , callback : F ) {
280+ for entry in fs:: read_dir ( dir) . unwrap ( ) {
281+ callback ( & entry. unwrap ( ) . path ( ) ) ;
268282 }
269283}
270284
0 commit comments