use std::collections::HashMap;
use std::fs;
use std::path::PathBuf;
pub use tempfile::TempDir;
pub fn loc_bin() -> PathBuf {
let mut path = std::env::current_exe()
.expect("current_exe")
.parent()
.expect("parent")
.to_path_buf();
if path.ends_with("deps") {
path.pop();
}
path.join("loc")
}
pub fn run_loc(args: &[&str]) -> std::process::Output {
std::process::Command::new(loc_bin())
.args(args)
.output()
.expect("Failed to execute loc binary")
}
#[allow(dead_code)]
pub fn run_loc_with_env(args: &[&str], env: &HashMap<&str, &str>) -> std::process::Output {
let mut cmd = std::process::Command::new(loc_bin());
cmd.args(args);
for key in &["AI_AGENT", "AGENT", "CLAUDECODE", "CLAUDE_CODE", "CODEX_SANDBOX",
"CRUSH", "CURSOR_TRACE_ID", "GEMINI_CLI", "GOOSE_TERMINAL"] {
cmd.env_remove(key);
}
for (k, v) in env {
cmd.env(k, v);
}
cmd.output().expect("Failed to execute loc binary")
}
pub fn make_fixture(files: &[(&str, &str)]) -> TempDir {
let dir = TempDir::new().expect("TempDir::new");
for (name, content) in files {
let path = dir.path().join(name);
if let Some(parent) = path.parent() {
fs::create_dir_all(parent).unwrap();
}
fs::write(&path, content).unwrap();
}
dir
}