From 7a94bbf4bcd9f0bf793efdd09f045625bb6a19af Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Fri, 27 Oct 2023 14:54:54 +1100 Subject: [PATCH] Add basic integration tests --- .gitignore | 1 - brro-compressor/src/main.rs | 3 +- brro-compressor/tests/integration_test.rs | 64 +++++++++++++++++++++ brro-compressor/tests/wavs/memory_used.wav | Bin 0 -> 18476 bytes brro-compressor/tests/wavs/uptime.wav | Bin 0 -> 18476 bytes 5 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 brro-compressor/tests/integration_test.rs create mode 100644 brro-compressor/tests/wavs/memory_used.wav create mode 100644 brro-compressor/tests/wavs/uptime.wav diff --git a/.gitignore b/.gitignore index e2c60ce..d54cb23 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /target -*.wav *.flac .vscode/settings.json diff --git a/brro-compressor/src/main.rs b/brro-compressor/src/main.rs index 452f7e0..5675bab 100644 --- a/brro-compressor/src/main.rs +++ b/brro-compressor/src/main.rs @@ -7,7 +7,7 @@ use brro_compressor::utils::writers::wav_writer; use clap::{arg, command, Parser}; use log::{debug, error}; use std::error::Error; -use std::path::{PathBuf, Path}; +use std::path::{Path, PathBuf}; /// Processes the given input based on the provided arguments. fn process_args(arguments: &Args) -> Result<(), Box> { @@ -197,5 +197,6 @@ fn main() { if let Err(e) = process_args(&arguments) { error!("{}", e); + std::process::exit(1); } } diff --git a/brro-compressor/tests/integration_test.rs b/brro-compressor/tests/integration_test.rs new file mode 100644 index 0000000..fed7878 --- /dev/null +++ b/brro-compressor/tests/integration_test.rs @@ -0,0 +1,64 @@ +use tempfile::tempdir; + +#[test] +fn test_noop() { + test_suite("noop"); +} + +#[test] +fn test_constant() { + test_suite("constant"); +} + +#[test] +fn test_fft() { + test_suite("fft"); +} + +fn test_suite(compressor: &str) { + compress_dir(compressor); + compress_file(compressor); +} + +fn compress_dir(compressor: &str) { + let tmp_dir = tempdir().unwrap(); + let input = tmp_dir.path().join("input"); + let output = tmp_dir.path().join("input-compressed"); + std::fs::create_dir(&input).unwrap(); + std::fs::copy("tests/wavs/memory_used.wav", input.join("1.wav")).unwrap(); + std::fs::copy("tests/wavs/uptime.wav", input.join("2.wav")).unwrap(); + + run_compressor(&[input.to_str().unwrap(), "--compressor", compressor]); + assert!(output.join("1.bro").is_file()); + assert!(output.join("2.bro").is_file()); +} + +fn compress_file(compressor: &str) { + let tmp_dir = tempdir().unwrap(); + let path = tmp_dir.path(); + std::fs::copy("tests/wavs/memory_used.wav", path.join("1.wav")).unwrap(); + + run_compressor(&[ + path.join("1.wav").to_str().unwrap(), + "--compressor", + compressor, + ]); + assert!(path.join("1.bro").is_file()); +} + +fn run_compressor(args: &[&str]) { + // path to binary set by cargo: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates + let command = std::env!("CARGO_BIN_EXE_brro-compressor"); + + let status = std::process::Command::new(command) + .args(args) + .status() + .unwrap(); + + if !status.success() { + panic!( + "Failed to run command {} {:?}, exited with {:?}", + command, args, status + ); + } +} diff --git a/brro-compressor/tests/wavs/memory_used.wav b/brro-compressor/tests/wavs/memory_used.wav new file mode 100644 index 0000000000000000000000000000000000000000..cd4cc7f60b2a87986cd43cf631095175a9f6902e GIT binary patch literal 18476 zcmY-1dE5r`6cI)u+6=OV8h(CvWNF9}QB!0q43ZvCbgUsB!()k*DYAr&CHry^ zWgknjm2;;gkx7IUCn}NU*ZsM!&w0ImfAo5H^}X-;T;FBRJ?C)uY_ld!9(ckq+BRs@ z_@!R`txASr+_;(7a7zF4FINpCzhN3B{`sfKKV`0e{xSafci%9U7`0~fd9h3XE@ztJ zKgP)=(;MXc+m65gpYh0g@8|sYjP3p-wQ5uzh?@FGcA=(D)(zA&YFlJR&h@A@tO05o z{XSU6>A|s5tKs~$sHw64GHM!+syh??s?q#&sA)XlyIB~gD{H-jT6Jo zjgO{docbTs$9!q{Wn0u4|9n?!HR_N;O~Vr9KEV7`=jT?asn_yLtOvCQ-i7(nu>Q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5 literal 0 HcmV?d00001 diff --git a/brro-compressor/tests/wavs/uptime.wav b/brro-compressor/tests/wavs/uptime.wav new file mode 100644 index 0000000000000000000000000000000000000000..e0cf75c3349971cc4cb85aee6606bd96b3d1f579 GIT binary patch literal 18476 zcmeIyAre7R6b9hmjG&QJf?x?6f`=-Q-;B`&Gj9R*VFy+w$^tI7Ab#Q8``;VSobzqg zRW({AyZLr;I5xv^lIN?P*`S0+(n&ATk08=VWV A9{>OV literal 0 HcmV?d00001