#[cfg(unix)]
use super::super::glob_paths;
#[cfg(unix)]
use anyhow::{Context, Result, ensure};
#[cfg(unix)]
use camino::Utf8Path;
#[cfg(unix)]
use tempfile::{Builder, tempdir};
#[cfg(unix)]
use test_support::fs as test_fs;
#[cfg(unix)]
#[test]
fn glob_paths_relative_base_is_not_doubled() -> Result<()> {
let cwd = std::env::current_dir().context("read the process working directory")?;
let temp = Builder::new()
.prefix("f1-relative-base-")
.tempdir_in(&cwd)
.context("create a temporary directory under the working directory")?;
let base = temp
.path()
.strip_prefix(&cwd)
.context("the temporary directory must live under the working directory")?;
test_fs::write(temp.path().join("a.txt"), "a")?;
let results = glob_paths(
"*.txt",
Some(Utf8Path::from_path(base).expect("temp paths are UTF-8")),
)?;
ensure!(
results == vec!["a.txt".to_owned()],
"a relative base must not be doubled, got {results:?}"
);
Ok(())
}
#[cfg(unix)]
#[test]
fn glob_paths_follows_a_symlinked_base() -> Result<()> {
let temp = tempdir()?;
let target = temp.path().join("target");
test_fs::create_dir(&target)?;
test_fs::write(target.join("a.txt"), "a")?;
let link = temp.path().join("link");
test_fs::symlink("target", &link)?;
let results = glob_paths(
"*.txt",
Some(Utf8Path::from_path(&link).expect("temp paths are UTF-8")),
)?;
ensure!(
results == vec!["a.txt".to_owned()],
"expected the match relative to the symlinked base, got {results:?}"
);
Ok(())
}