#![allow(dead_code)]
use std::path::{Path, PathBuf};
use std::sync::atomic::{AtomicU64, Ordering};
pub struct Staged(PathBuf);
impl Staged {
pub fn new(project: &str) -> Self {
Self::stage(
"typescript",
project,
&["index.ts", "index.test.ts", "stryker.conf.json"],
true,
)
}
pub fn python(project: &str) -> Self {
Self::stage("python", project, &["calc.py", "calc_test.py"], false)
}
fn stage(lang: &str, project: &str, files: &[&str], link_node_modules: bool) -> Self {
static COUNTER: AtomicU64 = AtomicU64::new(0);
let fixtures = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("tests/fixtures/unit_mutation")
.join(lang);
let dst = std::env::temp_dir().join(format!(
"tc-mut-{}-{}-{}-{}",
lang,
project,
std::process::id(),
COUNTER.fetch_add(1, Ordering::Relaxed),
));
std::fs::create_dir_all(&dst).expect("create staged project dir");
for file in files {
std::fs::copy(fixtures.join(project).join(file), dst.join(file))
.unwrap_or_else(|e| panic!("copy fixture {lang}/{project}/{file}: {e}"));
}
if link_node_modules {
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);
}
}