#![allow(dead_code)]
use par_term::config::Config;
use std::fs;
use std::path::PathBuf;
use tempfile::TempDir;
pub fn default_config_with_tmp_dir() -> (Config, TempDir) {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let config = Config::default();
(config, temp_dir)
}
pub fn config_with_shader_dir() -> (Config, TempDir) {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let shaders_dir = temp_dir.path().join("shaders");
fs::create_dir_all(&shaders_dir).expect("Failed to create shaders dir");
let shader_path = shaders_dir.join("test_shader.glsl");
fs::write(
&shader_path,
"void mainImage(out vec4 fragColor, in vec2 fragCoord) {\n fragColor = vec4(0.0);\n}\n",
)
.expect("Failed to write stub shader");
let mut config = Config::default();
config.custom_shader = Some(
shader_path
.to_str()
.expect("shader path is valid UTF-8")
.to_string(),
);
(config, temp_dir)
}
pub fn setup_config_dir() -> (TempDir, PathBuf) {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
let config_dir = temp_dir.path().join("par-term");
fs::create_dir_all(&config_dir).expect("Failed to create config dir");
(temp_dir, config_dir)
}
pub struct TestContext {
pub dir: TempDir,
pub config: Config,
}
impl TestContext {
pub fn new() -> Self {
let (config, dir) = default_config_with_tmp_dir();
Self { dir, config }
}
pub fn path(&self) -> &std::path::Path {
self.dir.path()
}
}
impl Default for TestContext {
fn default() -> Self {
Self::new()
}
}