@@ -8,6 +8,8 @@ use std::{
88use once_cell:: sync:: OnceCell ;
99use rustc_version:: VersionMeta ;
1010
11+ use crate :: ToUtf8 ;
12+
1113static WORKSPACE : OnceCell < PathBuf > = OnceCell :: new ( ) ;
1214
1315/// Returns the cargo workspace for the manifest
@@ -26,19 +28,22 @@ pub fn get_cargo_workspace() -> &'static Path {
2628pub fn walk_dir < ' a > (
2729 root : & ' _ Path ,
2830 skip : & ' a [ impl AsRef < OsStr > ] ,
31+ ext : impl for < ' s > Fn ( Option < & ' s std:: ffi:: OsStr > ) -> bool + ' static ,
2932) -> impl Iterator < Item = Result < walkdir:: DirEntry , walkdir:: Error > > + ' a {
30- walkdir:: WalkDir :: new ( root) . into_iter ( ) . filter_entry ( |e| {
31- if skip
32- . iter ( )
33- . map ( |s| -> & std:: ffi:: OsStr { s. as_ref ( ) } )
34- . any ( |dir| e. file_name ( ) == dir)
35- {
36- return false ;
37- } else if e. file_type ( ) . is_dir ( ) {
38- return true ;
39- }
40- e. path ( ) . extension ( ) == Some ( "md" . as_ref ( ) )
41- } )
33+ walkdir:: WalkDir :: new ( root)
34+ . into_iter ( )
35+ . filter_entry ( move |e| {
36+ if skip
37+ . iter ( )
38+ . map ( |s| -> & std:: ffi:: OsStr { s. as_ref ( ) } )
39+ . any ( |dir| e. file_name ( ) == dir)
40+ {
41+ return false ;
42+ } else if e. file_type ( ) . is_dir ( ) {
43+ return true ;
44+ }
45+ ext ( e. path ( ) . extension ( ) )
46+ } )
4247}
4348
4449#[ test]
@@ -124,3 +129,21 @@ release: {version}
124129 "1.0.0-nightly (22222222 2022-02-02)" ,
125130 ) ;
126131}
132+
133+ #[ test]
134+ fn check_newlines ( ) -> crate :: Result < ( ) > {
135+ for file in walk_dir ( get_cargo_workspace ( ) , & [ ".git" , "target" ] , |_| true ) {
136+ let file = file?;
137+ if !file. file_type ( ) . is_file ( ) {
138+ continue ;
139+ }
140+ assert ! (
141+ crate :: file:: read( file. path( ) )
142+ . unwrap_or_else( |_| String :: from( "\n " ) )
143+ . ends_with( '\n' ) ,
144+ "file {:?} does not end with a newline" ,
145+ file. path( ) . to_utf8( ) ?
146+ ) ;
147+ }
148+ Ok ( ( ) )
149+ }
0 commit comments