@@ -4,6 +4,7 @@ use std::collections::HashMap;
4
4
use std:: fs:: File ;
5
5
use std:: io:: BufReader ;
6
6
use std:: time:: SystemTime ;
7
+ use walkdir;
7
8
8
9
#[ derive( Debug ) ]
9
10
pub struct Coverage {
@@ -81,9 +82,9 @@ struct Line {
81
82
/// function will return None if the coverage file is not found, invalid, does
82
83
/// not contain the document, or if it is out of date compared to the document.
83
84
pub fn get_coverage ( document_path : & std:: path:: PathBuf ) -> Option < FileCoverage > {
84
- let coverage_path = std :: env :: var ( "HELIX_COVERAGE_FILE" ) . ok ( ) ?;
85
- log:: debug!( "coverage file is {}" , coverage_path) ;
86
- let coverage = read_cobertura_coverage ( & std :: path :: PathBuf :: from ( coverage_path) ) ?;
85
+ let coverage_path = find_coverage_file ( ) ?;
86
+ log:: debug!( "coverage file is {:? }" , coverage_path) ;
87
+ let coverage = read_cobertura_coverage ( & coverage_path) ?;
87
88
log:: debug!( "coverage is valid" ) ;
88
89
89
90
log:: debug!( "document path: {:?}" , document_path) ;
@@ -106,6 +107,21 @@ pub fn get_coverage(document_path: &std::path::PathBuf) -> Option<FileCoverage>
106
107
}
107
108
}
108
109
110
+ fn find_coverage_file ( ) -> Option < std:: path:: PathBuf > {
111
+ if let Some ( coverage_path) = std:: env:: var ( "HELIX_COVERAGE_FILE" ) . ok ( ) {
112
+ return Some ( std:: path:: PathBuf :: from ( coverage_path) ) ;
113
+ }
114
+ for entry in walkdir:: WalkDir :: new ( "." )
115
+ . into_iter ( )
116
+ . filter_map ( |e| e. ok ( ) )
117
+ {
118
+ if entry. file_name ( ) == "coverage.xml" || entry. file_name ( ) == "cobertura.xml" {
119
+ return Some ( entry. path ( ) . to_path_buf ( ) ) ;
120
+ }
121
+ }
122
+ return None ;
123
+ }
124
+
109
125
fn read_cobertura_coverage ( path : & std:: path:: PathBuf ) -> Option < Coverage > {
110
126
let file = File :: open ( path) . ok ( ) ?;
111
127
let metadata = file. metadata ( ) . ok ( ) ?;
0 commit comments