1
1
use std:: fs:: { self , DirEntry } ;
2
- use std:: io;
3
2
use std:: path:: Path ;
4
3
5
4
#[ test]
6
5
fn test_missing_tests ( ) {
7
- explore_directory ( Path :: new ( "./tests" ) ) . unwrap ( ) ;
6
+ let missing_files = explore_directory ( Path :: new ( "./tests" ) ) ;
7
+ if missing_files. len ( ) > 0 {
8
+ assert ! (
9
+ false ,
10
+ format!(
11
+ "Didn't see a test file for the following files:\n \n {}\n " ,
12
+ missing_files
13
+ . iter( )
14
+ . map( |s| format!( "\t {}" , s) )
15
+ . collect:: <Vec <_>>( )
16
+ . join( "\n " )
17
+ )
18
+ ) ;
19
+ }
8
20
}
9
21
10
22
/*
@@ -14,27 +26,25 @@ Since rs files are alphabetically before stderr/stdout, we can sort by the full
14
26
and iter in that order. If we've seen the file stem for the first time and it's not
15
27
a rust file, it means the rust file has to be missing.
16
28
*/
17
- fn explore_directory ( dir : & Path ) -> io:: Result < ( ) > {
29
+ fn explore_directory ( dir : & Path ) -> Vec < String > {
30
+ let mut missing_files: Vec < String > = Vec :: new ( ) ;
18
31
let mut current_file = String :: new ( ) ;
19
- let mut files: Vec < DirEntry > = fs:: read_dir ( dir) ? . filter_map ( Result :: ok) . collect ( ) ;
32
+ let mut files: Vec < DirEntry > = fs:: read_dir ( dir) . unwrap ( ) . filter_map ( Result :: ok) . collect ( ) ;
20
33
files. sort_by_key ( |e| e. path ( ) ) ;
21
34
for entry in files. iter ( ) {
22
35
let path = entry. path ( ) ;
23
36
if path. is_dir ( ) {
24
- explore_directory ( & path) ? ;
37
+ missing_files . extend ( explore_directory ( & path) ) ;
25
38
} else {
26
39
let file_stem = path. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ;
27
40
match path. extension ( ) {
28
41
Some ( ext) => {
29
42
match ext. to_str ( ) . unwrap ( ) {
30
43
"rs" => current_file = file_stem. clone ( ) ,
31
44
"stderr" | "stdout" => {
32
- assert_eq ! (
33
- file_stem,
34
- current_file,
35
- "{}" ,
36
- format!( "Didn't see a test file for {:}" , path. to_str( ) . unwrap( ) )
37
- ) ;
45
+ if file_stem != current_file {
46
+ missing_files. push ( path. to_str ( ) . unwrap ( ) . to_string ( ) ) ;
47
+ }
38
48
} ,
39
49
_ => continue ,
40
50
} ;
@@ -43,5 +53,5 @@ fn explore_directory(dir: &Path) -> io::Result<()> {
43
53
}
44
54
}
45
55
}
46
- Ok ( ( ) )
56
+ missing_files
47
57
}
0 commit comments