#![allow(dead_code)]
use std::ffi::OsStr;
use std::io::Write;
use std::path::PathBuf;
use std::process::{Child, Command, Stdio};
pub fn assert_pinned_env() {
let lc_all = std::env::var("LC_ALL").unwrap_or_default();
assert_eq!(
lc_all, "C.UTF-8",
"fixture byte-equality requires LC_ALL=C.UTF-8 (currently '{}'). \
Set via: LC_ALL=C.UTF-8 cargo test --release",
lc_all
);
}
pub fn with_tempdir() -> tempfile::TempDir {
tempfile::tempdir().expect("could not create test tempdir")
}
pub fn spawn_with_stdin<S, I>(program: S, args: I, stdin_bytes: &[u8]) -> std::io::Result<Child>
where
S: AsRef<OsStr>,
I: IntoIterator,
I::Item: AsRef<OsStr>,
{
let mut child = Command::new(program)
.args(args)
.stdin(Stdio::piped())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?;
if let Some(mut stdin) = child.stdin.take() {
stdin.write_all(stdin_bytes)?;
}
Ok(child)
}
pub fn fixture_path(category: &str, name: &str) -> PathBuf {
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
p.push("fixtures");
p.push(category);
p.push(name);
p
}