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 9e29733
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ on:
- main
- dev
schedule:
- cron: '0 1 * * *'
- cron: '0 2 * * *'
workflow_dispatch:

env:
Expand Down Expand Up @@ -113,12 +113,13 @@ jobs:
timeout-minutes: 60
container: alpine
steps:
- name: Install Rust
run: apk --no-cache add bash cargo git
shell: sh
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Install Rust
run: apk --no-cache add bash cargo
shell: sh
- run: git config --system --add safe.directory '*' # Workaround for https://github.com/actions/runner/issues/2033
- run: cargo test --workspace --all-features
- run: |
set -eEuxo pipefail
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
45 changes: 34 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,40 @@ 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 mut cmd = Command::new("git");
cmd.arg("ls-files").args(filters).current_dir(dir);
let output = cmd.output().with_context(|| format!("failed to run `{cmd:?}`"))?;
if !output.status.success() {
bail!(
"failed to run `{cmd:?}`:\nstdout:\n-------\n{}\n-------\nstderr:\n-------\n{}\n-------",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
}
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 9e29733

Please sign in to comment.