#[cfg(unix)]
use anyhow::Result;
#[cfg(unix)]
use assert_fs::prelude::*;
#[cfg(unix)]
use std::process::Command;
#[cfg(unix)]
use uv_test::{get_bin, uv_snapshot};
#[test]
#[cfg(unix)]
fn cache_init_failure() -> Result<()> {
use uv_test::ReadOnlyDirectoryGuard;
let context = uv_test::test_context!("3.12");
let pyproject_toml = context.temp_dir.child("pyproject.toml");
pyproject_toml.write_str(
r#"
[project]
name = "project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["iniconfig"]
"#,
)?;
let cache_parent = context.temp_dir.child("cache_parent");
fs_err::create_dir(&cache_parent)?;
let _guard = ReadOnlyDirectoryGuard::new(cache_parent.path())?;
let cache_dir = cache_parent.child("cache");
let context = context
.with_filter((r"cache_parent/cache", "[CACHE_DIR]"))
.with_filter((
r"failed to create directory `.*`",
"failed to create directory `[CACHE_DIR]`",
));
let mut command = Command::new(get_bin!());
command
.arg("sync")
.arg("--cache-dir")
.arg(cache_dir.path())
.current_dir(context.temp_dir.path());
context.add_shared_env(&mut command, false);
uv_snapshot!(context.filters(), command, @"
success: false
exit_code: 2
----- stdout -----
----- stderr -----
error: Failed to initialize cache at `[CACHE_DIR]`
Caused by: failed to create directory `[CACHE_DIR]`: Permission denied (os error 13)
");
Ok(())
}