diff --git a/Cargo.toml b/Cargo.toml index a931aa76..98b3db11 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,6 @@ walkdir = "2.2.3" [dev-dependencies] easy-ext = "1" -ignore = "0.4" rustversion = "1" tempfile = "3" diff --git a/tests/auxiliary/mod.rs b/tests/auxiliary/mod.rs index 1565ded2..d969bd7b 100644 --- a/tests/auxiliary/mod.rs +++ b/tests/auxiliary/mod.rs @@ -7,10 +7,11 @@ use std::{ mem, path::{Path, PathBuf}, process::{Command, ExitStatus, Stdio}, + str, sync::OnceLock, }; -use anyhow::{Context as _, Result}; +use anyhow::{bail, Context as _, Result}; use camino::Utf8Path; use easy_ext::ext; use fs_err as fs; @@ -116,20 +117,43 @@ pub fn test_project(model: &str) -> Result { let workspace_root = tmpdir.path(); let model_path = fixtures_path().join("crates").join(model); - for entry in ignore::WalkBuilder::new(&model_path).hidden(false).build().filter_map(Result::ok) - { - let from = entry.path(); - let to = &workspace_root.join(from.strip_prefix(&model_path)?); - if from.is_dir() { - fs::create_dir_all(to)?; - } else { - fs::copy(from, to)?; + for (file_name, from) in git_ls_files(model_path.as_std_path(), &[])? { + let to = &workspace_root.join(file_name); + if !to.parent().unwrap().is_dir() { + fs::create_dir_all(to.parent().unwrap())?; } + fs::copy(from, to)?; } Ok(tmpdir) } +fn git_ls_files(dir: &Path, filters: &[&str]) -> Result> { + let output = Command::new("git") + .arg("ls-files") + .args(filters) + .current_dir(dir) + .output() + .with_context(|| format!("failed to run `git ls-files {filters:?}`"))?; + if !output.status.success() { + bail!("failed to run `git ls-files {filters:?}`"); + } + Ok(str::from_utf8(&output.stdout)? + .lines() + .map(str::trim) + .filter_map(|f| { + if f.is_empty() { + return None; + } + let p = dir.join(f); + if !p.exists() { + return None; + } + Some((f.to_owned(), p)) + }) + .collect()) +} + pub fn perturb_one_header(workspace_root: &Path) -> Result> { let target_dir = workspace_root.join("target").join("llvm-cov-target"); let path = fs::read_dir(target_dir)?.filter_map(Result::ok).find_map(|entry| { diff --git a/tests/test.rs b/tests/test.rs index b8e5b2fe..42bbdb84 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -3,6 +3,8 @@ #![warn(rust_2018_idioms)] #![cfg(not(miri))] // Miri doesn't support file with non-default mode: https://github.com/rust-lang/miri/pull/2720 +mod auxiliary; + use anyhow::Context as _; use auxiliary::{ assert_output, cargo_llvm_cov, fixtures_path, normalize_output, perturb_one_header, @@ -12,8 +14,6 @@ use camino::Utf8Path; use fs_err as fs; use tempfile::tempdir; -mod auxiliary; - const SUBCOMMANDS: &[&str] = &["", "run", "report", "clean", "show-env", "nextest"]; fn test_set() -> Vec<(&'static str, &'static [&'static str])> {