use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
pub struct Staged(PathBuf);
impl Staged {
pub fn new(project: &str) -> Self {
static COUNTER: AtomicU64 = AtomicU64::new(0);
let fixtures = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/unit_mutation/typescript");
let dst = std::env::temp_dir().join(format!(
"tc-mut-ts-{}-{}-{}",
project,
std::process::id(),
COUNTER.fetch_add(1, Ordering::Relaxed),
));
std::fs::create_dir_all(&dst).expect("create staged project dir");
for file in ["index.ts", "index.test.ts", "stryker.conf.json"] {
std::fs::copy(fixtures.join(project).join(file), dst.join(file))
.unwrap_or_else(|e| panic!("copy fixture {project}/{file}: {e}"));
}
std::os::unix::fs::symlink(fixtures.join("node_modules"), dst.join("node_modules"))
.expect("symlink node_modules");
Staged(dst)
}
pub fn path(&self) -> &Path {
&self.0
}
}
impl Drop for Staged {
fn drop(&mut self) {
let _ = std::fs::remove_file(self.0.join("node_modules"));
let _ = std::fs::remove_dir_all(&self.0);
}
}