#![forbid(unsafe_code)]
use std::path::PathBuf;
use std::process::Command;
fn example(name: &str) -> PathBuf {
let mut path = std::env::current_exe().expect("the test binary has a path");
path.pop(); path.pop(); path.push("examples");
path.push(format!("{name}{}", std::env::consts::EXE_SUFFIX));
assert!(
path.is_file(),
"example binary not found at {}, run plain `cargo test`, which builds the examples",
path.display()
);
path
}
fn run(name: &str) -> String {
let path = example(name);
let output = Command::new(&path)
.output()
.unwrap_or_else(|error| panic!("could not run {}: {error}", path.display()));
assert!(
output.status.success(),
"{name} exited with {:?}\nstdout:\n{}stderr:\n{}",
output.status.code(),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
);
String::from_utf8(output.stdout).expect("example output is UTF-8")
}
#[test]
fn the_whole_file_example_runs_and_holds_its_count_guarantee() {
let stdout = run("decode_whole_file");
assert!(
stdout.contains("input: 2 channel(s) at 44100 Hz, 4410 frames"),
"probe line missing from:\n{stdout}"
);
assert!(
stdout.contains("mono f32 at 16000 Hz"),
"output line missing from:\n{stdout}"
);
assert!(
stdout.contains("identity-rate decode holds exactly 4410 frames"),
"identity count line missing from:\n{stdout}"
);
}
#[test]
fn the_streaming_example_runs_and_matches_the_whole_file_path() {
let stdout = run("decode_stream");
assert!(
stdout.contains("mono f32 at 16000 Hz"),
"output line missing from:\n{stdout}"
);
assert!(
stdout.contains("streamed output is bit-identical to the whole-file path"),
"agreement line missing from:\n{stdout}"
);
}