2026-03-28 19:47:59 +00:00
|
|
|
//! Shared test utilities for I/O module tests.
|
|
|
|
|
//!
|
|
|
|
|
//! Import with `use crate::io::test_helpers::{create_test_files, setup_project};`
|
|
|
|
|
|
|
|
|
|
use std::fs;
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
use tempfile::TempDir;
|
|
|
|
|
|
2026-04-03 16:12:52 +01:00
|
|
|
/// Create a minimal huskies project directory structure under `dir`.
|
2026-03-28 19:47:59 +00:00
|
|
|
///
|
2026-04-03 16:12:52 +01:00
|
|
|
/// Creates `.huskies/specs/tech/` and `script/`, then returns the root path.
|
2026-03-28 19:47:59 +00:00
|
|
|
/// Used by onboarding and wizard tests.
|
|
|
|
|
pub(crate) fn setup_project(dir: &TempDir) -> PathBuf {
|
|
|
|
|
let root = dir.path().to_path_buf();
|
2026-04-03 16:12:52 +01:00
|
|
|
let sk = root.join(".huskies");
|
2026-03-28 19:47:59 +00:00
|
|
|
fs::create_dir_all(sk.join("specs").join("tech")).unwrap();
|
|
|
|
|
fs::create_dir_all(root.join("script")).unwrap();
|
|
|
|
|
root
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Write a set of files into `dir` at the given relative paths.
|
|
|
|
|
///
|
|
|
|
|
/// Parent directories are created automatically. Used by search tests.
|
|
|
|
|
pub(crate) fn create_test_files(dir: &TempDir, files: &[(&str, &str)]) {
|
|
|
|
|
for (path, content) in files {
|
|
|
|
|
let full = dir.path().join(path);
|
|
|
|
|
if let Some(parent) = full.parent() {
|
|
|
|
|
fs::create_dir_all(parent).unwrap();
|
|
|
|
|
}
|
|
|
|
|
fs::write(full, content).unwrap();
|
|
|
|
|
}
|
|
|
|
|
}
|