#![allow(
dead_code,
reason = "each test binary uses a different subset of the helpers"
)]
pub(crate) mod child;
pub(crate) mod counting;
pub(crate) mod orders;
#[cfg(target_os = "linux")]
pub(crate) mod parallel;
pub(crate) mod program;
pub(crate) mod random;
pub(crate) mod rustc;
pub(crate) mod shapes;
use std::fs;
use std::path::{Path, PathBuf};
pub(crate) struct Scratch {
_owned: purrdf_testkit::TempDir,
base: PathBuf,
}
impl Scratch {
pub(crate) fn new() -> Self {
let owned = purrdf_testkit::TempDir::new_in(std::env::temp_dir())
.expect("create scratch directory");
Self {
base: fs::canonicalize(owned.path()).expect("canonicalise scratch directory"),
_owned: owned,
}
}
pub(crate) fn base(&self) -> &Path {
&self.base
}
pub(crate) fn path(&self, name: &str) -> PathBuf {
self.base.join(name)
}
pub(crate) fn dir(&self, name: &str) -> PathBuf {
let path = self.path(name);
fs::create_dir_all(&path).expect("create directory");
path
}
pub(crate) fn file(&self, name: &str, text: &str) -> PathBuf {
let path = self.path(name);
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).expect("create parent");
}
fs::write(&path, text).expect("write file");
path
}
#[cfg(unix)]
pub(crate) fn link(&self, name: &str, target: impl AsRef<Path>) -> PathBuf {
let path = self.path(name);
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).expect("create parent");
}
std::os::unix::fs::symlink(target, &path).expect("create symlink");
path
}
#[cfg(unix)]
pub(crate) fn fifo(&self, name: &str) -> PathBuf {
let path = self.path(name);
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).expect("create parent");
}
let status = std::process::Command::new("mkfifo")
.arg(&path)
.status()
.expect("run mkfifo");
assert!(status.success(), "mkfifo failed for {}", path.display());
path
}
}