serde_hkx_features/verify/
file.rs

1use crate::{
2    diff,
3    error::{FailedReproduceFileSnafu, Result},
4};
5use serde_hkx::bytes::hexdump;
6use std::path::Path;
7
8use super::verify_inner;
9
10/// Check hkx reproduction.
11///
12/// # Errors
13/// If an error occurs, return a input hexdump diff.
14pub fn verify_file<I>(path: I, color: bool) -> Result<()>
15where
16    I: AsRef<Path>,
17{
18    let input = path.as_ref();
19
20    let (expected_bytes, actual_bytes) = verify_inner(input)?;
21
22    // Verify
23    if actual_bytes == expected_bytes {
24        #[cfg(feature = "tracing")]
25        tracing::info!("OK reproducible: {}", input.display());
26        return Ok(());
27    }
28
29    let actual = hexdump::to_string(&actual_bytes);
30    let expected = hexdump::to_string(&expected_bytes);
31    FailedReproduceFileSnafu {
32        path: input.to_path_buf(),
33        diff: diff::diff(expected, actual, color),
34    }
35    .fail()
36}
37
38// NOTE: We don't try it except local PC because MIRI makes an error. Therefore, leave it commented out.
39#[cfg(test)]
40mod tests {
41    use super::*;
42
43    #[ignore = "need templates"]
44    #[test]
45    #[quick_tracing::init(file = "../../tests/verify_file.log", stdio = false)]
46    fn test_verify_file() {
47        let input = "../../tests/input\\x86\\meshes\\actors\\ambient\\chicken\\animations\\idle_fulbody3.hkx";
48        // let input = "../../tests/input\\x86\\meshes\\actors\\ambient\\chicken\\animations\\idle_sitdpeck.hkx";
49        verify_file(input, true).unwrap_or_else(|err| panic!("{err}"));
50    }
51}