automatically find coverage file

pull/10758/head
Dustin Lagoy 2 weeks ago
parent 2d4dedec93
commit 258f5eddb9

5
Cargo.lock generated

@ -1526,6 +1526,7 @@ dependencies = [
"tokio-stream",
"toml",
"url",
"walkdir",
]
[[package]]
@ -2572,9 +2573,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "walkdir"
version = "2.4.0"
version = "2.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee"
checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b"
dependencies = [
"same-file",
"winapi-util",

@ -51,6 +51,7 @@ log = "~0.4"
parking_lot = "0.12.2"
quick-xml = { version = "0.31.0", features = ["serialize"] }
walkdir = "2.5.0"
[target.'cfg(windows)'.dependencies]

@ -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…
Cancel
Save