diff --git a/Cargo.lock b/Cargo.lock index 4cdd0de23..5bc02ac38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,18 +19,48 @@ dependencies = [ "version_check", ] +[[package]] +name = "aho-corasick" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +dependencies = [ + "memchr", +] + [[package]] name = "allocator-api2" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +[[package]] +name = "anstyle" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" + [[package]] name = "arraydeque" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d902e3d592a523def97af8f317b08ce16b7ab854c1985a0c671e6f15cebc236" +[[package]] +name = "assert_fs" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7efdb1fdb47602827a342857666feb372712cbc64b414172bd6b167a02927674" +dependencies = [ + "anstyle", + "doc-comment", + "globwalk", + "predicates", + "predicates-core", + "predicates-tree", + "tempfile", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -52,6 +82,16 @@ dependencies = [ "generic-array", ] +[[package]] +name = "bstr" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40723b8fb387abc38f4f4a37c09073622e41dd12327033091ef8950659e6dc0c" +dependencies = [ + "memchr", + "serde", +] + [[package]] name = "byteorder" version = "1.5.0" @@ -82,6 +122,31 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam-deque" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +dependencies = [ + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b82ac4a3c2ca9c3460964f020e1402edd5753411d7737aa39c3714ad1b5420e" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" + [[package]] name = "crypto-common" version = "0.1.6" @@ -96,17 +161,25 @@ dependencies = [ name = "dekoder" version = "0.0.1" dependencies = [ + "assert_fs", "float-cmp", "glob", "hashbrown", "lz4_flex", "ndarray", "ndarray-npy", + "predicates", "tar", "thiserror", "yaml-rust2", ] +[[package]] +name = "difflib" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" + [[package]] name = "digest" version = "0.10.7" @@ -117,6 +190,12 @@ dependencies = [ "crypto-common", ] +[[package]] +name = "doc-comment" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" + [[package]] name = "eko" version = "0.0.1" @@ -153,6 +232,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + [[package]] name = "filetime" version = "0.2.24" @@ -200,6 +285,30 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +[[package]] +name = "globset" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57da3b9b5b85bd66f31093f8c408b90a74431672542466497dcbdfdc02034be1" +dependencies = [ + "aho-corasick", + "bstr", + "log", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "globwalk" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf760ebf69878d9fd8f110c89703d90ce35095324d1f1edcb595c63945ee757" +dependencies = [ + "bitflags", + "ignore", + "walkdir", +] + [[package]] name = "hashbrown" version = "0.14.0" @@ -219,6 +328,22 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "ignore" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46810df39e66e925525d6e38ce1e7f6e1d208f72dc39757880fcb66e2c58af1" +dependencies = [ + "crossbeam-deque", + "globset", + "log", + "memchr", + "regex-automata", + "same-file", + "walkdir", + "winapi-util", +] + [[package]] name = "libc" version = "0.2.155" @@ -242,6 +367,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "log" +version = "0.4.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" + [[package]] name = "lz4_flex" version = "0.9.5" @@ -303,6 +434,12 @@ dependencies = [ "zip", ] +[[package]] +name = "normalize-line-endings" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be" + [[package]] name = "num" version = "0.4.1" @@ -430,6 +567,36 @@ dependencies = [ "sha2", ] +[[package]] +name = "predicates" +version = "3.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e9086cc7640c29a356d1a29fd134380bee9d8f79a17410aa76e7ad295f42c97" +dependencies = [ + "anstyle", + "difflib", + "float-cmp", + "normalize-line-endings", + "predicates-core", + "regex", +] + +[[package]] +name = "predicates-core" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae8177bee8e75d6846599c6b9ff679ed51e882816914eec639944d7c9aa11931" + +[[package]] +name = "predicates-tree" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b740d195ed3166cd147c8047ec98db0e22ec019eb8eeb76d343b795304fb13" +dependencies = [ + "predicates-core", + "termtree", +] + [[package]] name = "proc-macro2" version = "1.0.86" @@ -476,6 +643,35 @@ dependencies = [ "bitflags", ] +[[package]] +name = "regex" +version = "1.10.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" + [[package]] name = "rustix" version = "0.38.34" @@ -489,6 +685,35 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "serde" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff085d2cb684faa248efb494c39b68e522822ac0de72ccf08109abde717cfb2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.208" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24008e81ff7613ed8e5ba0cfaf24e2c2f1e5b8a0495711e44fcd4882fca62bcf" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "sha2" version = "0.10.8" @@ -528,6 +753,24 @@ dependencies = [ "xattr", ] +[[package]] +name = "tempfile" +version = "3.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" +dependencies = [ + "cfg-if", + "fastrand", + "rustix", + "windows-sys 0.52.0", +] + +[[package]] +name = "termtree" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3369f5ac52d5eb6ab48c6b4ffdc8efbcad6b89c765749064ba298f2c68a16a76" + [[package]] name = "thiserror" version = "1.0.63" @@ -582,6 +825,25 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "winapi-util" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +dependencies = [ + "windows-sys 0.59.0", +] + [[package]] name = "windows-sys" version = "0.52.0" diff --git a/crates/dekoder/Cargo.toml b/crates/dekoder/Cargo.toml index 5f3555e93..605e79473 100644 --- a/crates/dekoder/Cargo.toml +++ b/crates/dekoder/Cargo.toml @@ -25,3 +25,7 @@ lz4_flex = "0.9.2" ndarray = "0.15.4" ndarray-npy = "0.8.1" thiserror = "1.0.63" + +[dev-dependencies] +assert_fs = "1.1.2" +predicates = "3.1.2" diff --git a/crates/dekoder/tests/test_load.rs b/crates/dekoder/tests/test_load.rs index bb999ddb9..560ef9ca9 100644 --- a/crates/dekoder/tests/test_load.rs +++ b/crates/dekoder/tests/test_load.rs @@ -1,55 +1,34 @@ -use dekoder::{EvolutionPoint, Operator, EKO}; -use std::fs::{remove_dir_all, remove_file}; +use assert_fs::prelude::*; +use predicates::prelude::*; use std::path::PathBuf; -#[test] -fn save_as_other() { +use dekoder::{EvolutionPoint, Operator, EKO}; + +/// Get v0.15 test object +fn v015tar() -> PathBuf { let base: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect(); let src = base.join("data").join("v0.15.tar"); - assert!(src.try_exists().is_ok_and(|x| x)); - let dst = base.join("target").join("v0.15a"); - // get rid of previous runs if needed - let dst_exists = dst.try_exists().is_ok_and(|x| x); - if dst_exists { - remove_dir_all(dst.to_owned()).unwrap(); - } + assert!(predicate::path::exists().eval(&src)); + src +} + +#[test] +fn save_as_other() { + let src = v015tar(); + let dst = assert_fs::TempDir::new().unwrap(); // open let mut eko = EKO::edit(src.to_owned(), dst.to_owned()).unwrap(); - let dst_exists = dst.try_exists().is_ok_and(|x| x); - assert!(dst_exists); - // set a different output - let tarb = base.join("target").join("v0.15b.tar"); - let tarb_exists = tarb.try_exists().is_ok_and(|x| x); - if tarb_exists { - remove_file(tarb.to_owned()).unwrap(); - } + // write to somewhere else + let tarb = assert_fs::NamedTempFile::new("v0.15b.tar").unwrap(); eko.set_tar_path(tarb.to_owned()); - // close eko.close(true).unwrap(); - let tarb_exists = tarb.try_exists().is_ok_and(|x| x); - assert!(tarb_exists); - let dst_exists = dst.try_exists().is_ok_and(|x| x); - assert!(!dst_exists); - // clean up - if tarb_exists { - remove_file(tarb.to_owned()).unwrap(); - } - if dst_exists { - remove_dir_all(dst.to_str().unwrap()).unwrap(); - } + tarb.assert(predicate::path::exists()); } #[test] fn has_operator() { - let base: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect(); - let src = base.join("data").join("v0.15.tar"); - assert!(src.try_exists().is_ok_and(|x| x)); - let dst = base.join("target").join("v0.15b"); - // get rid of previous runs if needed - let dst_exists = dst.try_exists().is_ok_and(|x| x); - if dst_exists { - remove_dir_all(dst.to_owned()).unwrap(); - } + let src = v015tar(); + let dst = assert_fs::TempDir::new().unwrap(); // open let eko = EKO::read(src.to_owned(), dst.to_owned()).unwrap(); // check there is only one: @@ -67,17 +46,11 @@ fn has_operator() { #[test] fn load_operator() { - let base: PathBuf = [env!("CARGO_MANIFEST_DIR"), "tests"].iter().collect(); - let src = base.join("data").join("v0.15.tar"); - assert!(src.try_exists().is_ok_and(|x| x)); - let dst = base.join("target").join("v0.15c"); - // get rid of previous runs if needed - let dst_exists = dst.try_exists().is_ok_and(|x| x); - if dst_exists { - remove_dir_all(dst.to_owned()).unwrap(); - } + let src = v015tar(); + let dst = assert_fs::TempDir::new().unwrap(); // open let mut eko = EKO::read(src.to_owned(), dst.to_owned()).unwrap(); + // load let ep = EvolutionPoint { scale: 10000., nf: 4,