shrupl/src/test_util/mod.rs

26 lines
593 B
Rust
Raw Normal View History

#![cfg(test)]
pub mod data;
use std::{fmt, io::Write};
use tempfile::NamedTempFile;
pub fn check_trait<E, A>(expected: &E, actual: &A, tr: &'static str, ty: &'static str)
where
E: fmt::Debug + PartialEq<A>,
A: fmt::Debug,
{
assert_eq!(
expected, actual,
"`impl {tr} for {ty}` expected: {expected:?}, actual: {actual:?}",
);
}
/// Helper to create a temp file from `data`
pub fn create_file(data: &[u8]) -> NamedTempFile {
let mut tmp = NamedTempFile::new().expect("creating temp file");
tmp.write_all(data).expect("writing to tempfile");
tmp
}