1919
2020#[ cfg( test) ]
2121mod test {
22- fn get_indexed_files_with_extension ( extension : & ' static str ) -> Vec < String > {
23- let repo = git2:: Repository :: open ( "." ) . expect ( "Could not open git repository" ) ;
24- let index = repo. index ( ) . expect ( "Could not get git index" ) ;
25- index. iter ( ) . filter_map ( move |entry| {
26- let path = std:: str:: from_utf8 ( & entry. path ) . expect ( "Invalid UTF-8 in file path" ) ;
27- if path. ends_with ( extension) {
28- Some ( path. to_string ( ) )
29- } else {
30- None
31- }
32- } ) . collect ( )
22+ fn get_files_with_extension ( extension : & ' static str ) -> Vec < String > {
23+ let files = walkdir:: WalkDir :: new ( "." ) ;
24+ files. into_iter ( )
25+ . filter_map ( |e|e. ok ( ) )
26+ . filter ( |e|!e. path ( ) . starts_with ( "./target" ) )
27+ . filter_map ( move |entry| {
28+ let path = entry. path ( ) . to_str ( )
29+ . expect ( "Invalid Unicode in file path" ) ;
30+ if path. ends_with ( extension) {
31+ Some ( path. to_string ( ) )
32+ } else {
33+ None
34+ }
35+ } ) . collect ( )
3336 }
3437
3538 fn compare_linewise ( canon : & str , content : & str ) -> bool {
@@ -44,7 +47,7 @@ mod test {
4447 #[ test]
4548 fn check_copyright_headers_rs ( ) {
4649 let mut missmatching_files = vec ! [ ] ;
47- for path in get_indexed_files_with_extension ( ".rs" ) {
50+ for path in get_files_with_extension ( ".rs" ) {
4851 let content = std:: fs:: read_to_string ( & path)
4952 . unwrap_or_else ( |e|panic ! ( "Could not read file {}, {}" , path, e) ) ;
5053 if !compare_linewise (
@@ -63,7 +66,7 @@ mod test {
6366 #[ test]
6467 fn check_copyright_headers_md ( ) {
6568 let mut missmatching_files = vec ! [ ] ;
66- for path in get_indexed_files_with_extension ( ".md" ) {
69+ for path in get_files_with_extension ( ".md" ) {
6770 let content = std:: fs:: read_to_string ( & path)
6871 . unwrap_or_else ( |e| panic ! ( "Could not read file {}, {}" , path, e) ) ;
6972 if !compare_linewise (
@@ -80,4 +83,4 @@ mod test {
8083 missmatching_files. join( "\n " ) ) ;
8184 }
8285 }
83- }
86+ }
0 commit comments