diff --git a/Cargo.lock b/Cargo.lock index b74f4a8e..cc823cef 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -706,6 +706,10 @@ dependencies = [ "ec-pgs", ] +[[package]] +name = "ec-testkit" +version = "0.1.0" + [[package]] name = "ec-truehd" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6c16817b..9bcb6768 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ ec-amr = { path = "crates/ec-amr", version = "0.1.0" } ec-av1 = { path = "crates/ec-av1", version = "0.1.0" } ec-av1-syntax = { path = "crates/ec-av1-syntax", version = "0.1.0" } ec-core = { path = "crates/ec-core", version = "0.1.0" } +ec-testkit = { path = "crates/ec-testkit" } ec-dvdsub = { path = "crates/ec-dvdsub", version = "0.1.0" } ec-dvbsub = { path = "crates/ec-dvbsub", version = "0.1.0" } ec-dsp = { path = "crates/ec-dsp", version = "0.1.0" } diff --git a/crates/ec-testkit/Cargo.toml b/crates/ec-testkit/Cargo.toml new file mode 100644 index 00000000..bd5f0abe --- /dev/null +++ b/crates/ec-testkit/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "ec-testkit" +description = "Dev-only test helpers: fixture paths and the pinned ffmpeg bundle." +version.workspace = true +edition.workspace = true +publish = false diff --git a/crates/ec-testkit/src/lib.rs b/crates/ec-testkit/src/lib.rs new file mode 100644 index 00000000..c2d62f0b --- /dev/null +++ b/crates/ec-testkit/src/lib.rs @@ -0,0 +1,53 @@ +use std::path::{Path, PathBuf}; +use std::process::Command; + +pub fn root() -> PathBuf { + match std::env::var_os("EC_FIXTURES") { + Some(dir) => PathBuf::from(dir), + None => Path::new(env!("CARGO_MANIFEST_DIR")).join("../../fixtures"), + } +} + +pub fn fixture(rel: &str) -> PathBuf { + let path = root().join(rel); + if !path.exists() { + panic!("missing fixture {rel}: run scripts/fixtures.sh"); + } + path +} + +pub fn fixtures(dir: &str, ext: &str) -> Vec { + let mut found: Vec = std::fs::read_dir(root().join(dir)) + .expect("fixture directory") + .map(|entry| entry.expect("fixture entry").path()) + .filter(|path| path.extension().is_some_and(|e| e == ext)) + .collect(); + found.sort(); + assert!(!found.is_empty(), "no .{ext} fixtures in {dir}"); + found +} + +pub fn ffmpeg_path() -> PathBuf { + let path = match std::env::var_os("EC_FFMPEG") { + Some(path) => PathBuf::from(path), + None => { + PathBuf::from(std::env::var_os("HOME").expect("HOME")).join(".cache/ec-ffmpeg/ffmpeg") + } + }; + if !path.is_file() { + panic!("ffmpeg not found at {}", path.display()); + } + path +} + +pub fn ffprobe_path() -> PathBuf { + ffmpeg_path().with_file_name("ffprobe") +} + +pub fn ffmpeg() -> Command { + Command::new(ffmpeg_path()) +} + +pub fn ffprobe() -> Command { + Command::new(ffprobe_path()) +}