Skip to content

Commit

Permalink
tests: Remove dependency on ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Oct 10, 2023
1 parent c0aa8ce commit d6d9c0a
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ jobs:
with:
persist-credentials: false
- name: Install Rust
run: apk --no-cache add bash cargo
run: apk --no-cache add bash cargo git
shell: sh
- run: cargo test --workspace --all-features
- run: |
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ toml_edit = "0.20"
build-context = "0.1"
easy-ext = "1"
fs-err = "2"
ignore = "0.4"
tempfile = "3"

[profile.release]
Expand Down
44 changes: 33 additions & 11 deletions tests/auxiliary/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ use std::{
ffi::OsStr,
path::{Path, PathBuf},
process::{Command, ExitStatus},
str,
sync::OnceLock,
};

use anyhow::{Context as _, Result};
use anyhow::{bail, Context as _, Result};
pub use build_context::TARGET;
use easy_ext::ext;
use fs_err as fs;
Expand Down Expand Up @@ -240,18 +241,39 @@ fn test_project(model: &str) -> Result<(TempDir, PathBuf)> {
workspace_root = tmpdir_path.to_path_buf();
}

for entry in ignore::WalkBuilder::new(&model_path).hidden(false).build().filter_map(Result::ok)
{
let path = entry.path();
let tmp_path = &tmpdir_path.join(path.strip_prefix(&model_path)?);
if !tmp_path.exists() {
if path.is_dir() {
fs::create_dir_all(tmp_path)?;
} else {
fs::copy(path, tmp_path)?;
}
for (file_name, from) in git_ls_files(&model_path, &[])? {
let to = &tmpdir_path.join(file_name);
if !to.parent().unwrap().is_dir() {
fs::create_dir_all(to.parent().unwrap())?;
}
fs::copy(from, to)?;
}

Ok((tmpdir, workspace_root))
}

fn git_ls_files(dir: &Path, filters: &[&str]) -> Result<Vec<(String, PathBuf)>> {
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())
}

0 comments on commit d6d9c0a

Please sign in to comment.