1
1
#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
2
2
#![ warn( rust_2018_idioms, unused_lifetimes) ]
3
3
#![ allow( clippy:: assertions_on_constants) ]
4
+ #![ feature( path_file_prefix) ]
4
5
6
+ use std:: cmp:: Ordering ;
7
+ use std:: ffi:: OsStr ;
5
8
use std:: fs:: { self , DirEntry } ;
6
9
use std:: path:: Path ;
7
10
@@ -21,29 +24,39 @@ fn test_missing_tests() {
21
24
}
22
25
}
23
26
24
- /*
25
- Test for missing files.
26
-
27
- Since rs files are alphabetically before stderr/stdout, we can sort by the full name
28
- and iter in that order. If we've seen the file stem for the first time and it's not
29
- a rust file, it means the rust file has to be missing.
30
- */
27
+ // Test for missing files.
31
28
fn explore_directory ( dir : & Path ) -> Vec < String > {
32
29
let mut missing_files: Vec < String > = Vec :: new ( ) ;
33
30
let mut current_file = String :: new ( ) ;
34
31
let mut files: Vec < DirEntry > = fs:: read_dir ( dir) . unwrap ( ) . filter_map ( Result :: ok) . collect ( ) ;
35
- files. sort_by_key ( std:: fs:: DirEntry :: path) ;
32
+ files. sort_by ( |x, y| {
33
+ match x. path ( ) . file_prefix ( ) . cmp ( & y. path ( ) . file_prefix ( ) ) {
34
+ Ordering :: Equal => ( ) ,
35
+ ord => return ord,
36
+ }
37
+ // Sort rs files before the others if they share the same prefix. So when we see
38
+ // the file prefix for the first time and it's not a rust file, it means the rust
39
+ // file has to be missing.
40
+ match (
41
+ x. path ( ) . extension ( ) . and_then ( OsStr :: to_str) ,
42
+ y. path ( ) . extension ( ) . and_then ( OsStr :: to_str) ,
43
+ ) {
44
+ ( Some ( "rs" ) , _) => Ordering :: Less ,
45
+ ( _, Some ( "rs" ) ) => Ordering :: Greater ,
46
+ _ => Ordering :: Equal ,
47
+ }
48
+ } ) ;
36
49
for entry in & files {
37
50
let path = entry. path ( ) ;
38
51
if path. is_dir ( ) {
39
52
missing_files. extend ( explore_directory ( & path) ) ;
40
53
} else {
41
- let file_stem = path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
54
+ let file_prefix = path. file_prefix ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
42
55
if let Some ( ext) = path. extension ( ) {
43
56
match ext. to_str ( ) . unwrap ( ) {
44
- "rs" => current_file = file_stem . clone ( ) ,
57
+ "rs" => current_file = file_prefix . clone ( ) ,
45
58
"stderr" | "stdout" => {
46
- if file_stem != current_file {
59
+ if file_prefix != current_file {
47
60
missing_files. push ( path. to_str ( ) . unwrap ( ) . to_string ( ) ) ;
48
61
}
49
62
} ,
0 commit comments