mirror of https://github.com/helix-editor/helix
automatically find coverage file
parent
c81ae710b5
commit
8a4c19ceb9
|
@ -1567,6 +1567,7 @@ dependencies = [
|
|||
"tokio-stream",
|
||||
"toml",
|
||||
"url",
|
||||
"walkdir",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -52,6 +52,7 @@ log = "~0.4"
|
|||
parking_lot.workspace = true
|
||||
thiserror.workspace = true
|
||||
quick-xml = { version = "0.31.0", features = ["serialize"] }
|
||||
walkdir = "2.5.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
clipboard-win = { version = "5.4", features = ["std"] }
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::collections::HashMap;
|
|||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::time::SystemTime;
|
||||
use walkdir;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Coverage {
|
||||
|
@ -81,9 +82,9 @@ struct Line {
|
|||
/// function will return None if the coverage file is not found, invalid, does
|
||||
/// not contain the document, or if it is out of date compared to the document.
|
||||
pub fn get_coverage(document_path: &std::path::PathBuf) -> Option<FileCoverage> {
|
||||
let coverage_path = std::env::var("HELIX_COVERAGE_FILE").ok()?;
|
||||
log::debug!("coverage file is {}", coverage_path);
|
||||
let coverage = read_cobertura_coverage(&std::path::PathBuf::from(coverage_path))?;
|
||||
let coverage_path = find_coverage_file()?;
|
||||
log::debug!("coverage file is {:?}", coverage_path);
|
||||
let coverage = read_cobertura_coverage(&coverage_path)?;
|
||||
log::debug!("coverage is valid");
|
||||
|
||||
log::debug!("document path: {:?}", document_path);
|
||||
|
@ -106,6 +107,21 @@ pub fn get_coverage(document_path: &std::path::PathBuf) -> Option<FileCoverage>
|
|||
}
|
||||
}
|
||||
|
||||
fn find_coverage_file() -> Option<std::path::PathBuf> {
|
||||
if let Some(coverage_path) = std::env::var("HELIX_COVERAGE_FILE").ok() {
|
||||
return Some(std::path::PathBuf::from(coverage_path));
|
||||
}
|
||||
for entry in walkdir::WalkDir::new(".")
|
||||
.into_iter()
|
||||
.filter_map(|e| e.ok())
|
||||
{
|
||||
if entry.file_name() == "coverage.xml" || entry.file_name() == "cobertura.xml" {
|
||||
return Some(entry.path().to_path_buf());
|
||||
}
|
||||
}
|
||||
return None;
|
||||
}
|
||||
|
||||
fn read_cobertura_coverage(path: &std::path::PathBuf) -> Option<Coverage> {
|
||||
let file = File::open(path).ok()?;
|
||||
let metadata = file.metadata().ok()?;
|
||||
|
|
Loading…
Reference in New Issue