Skip to content

Commit 8a4c19c

Browse files
dustinlagoyDustin Lagoy
authored and
Dustin Lagoy
committed
automatically find coverage file
1 parent c81ae71 commit 8a4c19c

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

helix-view/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ log = "~0.4"
5252
parking_lot.workspace = true
5353
thiserror.workspace = true
5454
quick-xml = { version = "0.31.0", features = ["serialize"] }
55+
walkdir = "2.5.0"
5556

5657
[target.'cfg(windows)'.dependencies]
5758
clipboard-win = { version = "5.4", features = ["std"] }

helix-view/src/coverage.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::collections::HashMap;
44
use std::fs::File;
55
use std::io::BufReader;
66
use std::time::SystemTime;
7+
use walkdir;
78

89
#[derive(Debug)]
910
pub struct Coverage {
@@ -81,9 +82,9 @@ struct Line {
8182
/// function will return None if the coverage file is not found, invalid, does
8283
/// not contain the document, or if it is out of date compared to the document.
8384
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)?;
8788
log::debug!("coverage is valid");
8889

8990
log::debug!("document path: {:?}", document_path);
@@ -106,6 +107,21 @@ pub fn get_coverage(document_path: &std::path::PathBuf) -> Option<FileCoverage>
106107
}
107108
}
108109

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+
109125
fn read_cobertura_coverage(path: &std::path::PathBuf) -> Option<Coverage> {
110126
let file = File::open(path).ok()?;
111127
let metadata = file.metadata().ok()?;

0 commit comments

Comments
 (0)