#![forbid(unsafe_code)]
use std::{
ffi::OsStr,
path::{Path, PathBuf},
process::Command,
};
#[allow(dead_code)] pub fn copy_executable(source: impl AsRef<Path>, destination: impl AsRef<Path>) {
let output = bounded("--copy-executable", 15)
.arg(source.as_ref())
.arg(destination.as_ref())
.env_clear()
.output()
.unwrap();
assert!(
output.status.success(),
"copy {:?} to {:?}: {output:?}",
source.as_ref(),
destination.as_ref(),
);
}
pub fn bounded(binary: impl AsRef<OsStr>, seconds: u32) -> Command {
assert!((1..=60).contains(&seconds));
let launcher = std::env::var_os("FASTMASH_TEST_PROCESS")
.map(PathBuf::from)
.unwrap_or_else(|| {
Path::new(env!("CARGO_BIN_EXE_fastmash")).with_file_name("fastmash-test-process")
});
assert!(
launcher.is_file(),
"prepare fastmash-test-process before native command tests"
);
let mut command = Command::new(launcher);
command.arg(seconds.to_string()).arg(binary);
command
}
#[allow(dead_code)] pub fn ignoring_file_size_signal(binary: impl AsRef<OsStr>, seconds: u32) -> Command {
let launcher = bounded(binary, seconds);
let mut command = Command::new("/bin/sh");
command
.args(["-c", r#"trap '' XFSZ && exec "$@""#, "fastmash-file-size"])
.arg(launcher.get_program())
.args(launcher.get_args());
command
}