diff --git a/Cargo.lock b/Cargo.lock index f35a75a634..89de382267 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5823,6 +5823,7 @@ dependencies = [ "serde", "serial_test", "tracing", + "walkdir 2.3.2", ] [[package]] diff --git a/common/assets/Cargo.toml b/common/assets/Cargo.toml index 4eb316a64c..b0897b8a5c 100644 --- a/common/assets/Cargo.toml +++ b/common/assets/Cargo.toml @@ -17,5 +17,8 @@ tracing = "0.1" serde = {version = "1.0", features = ["derive"], optional = true} serial_test = {version = "0.5", optional = true} +[dev-dependencies] +walkdir = "2.3.2" + [features] asset_tweak = ["serial_test", "serde"] diff --git a/common/assets/src/lib.rs b/common/assets/src/lib.rs index bed643fc77..3534fdcf11 100644 --- a/common/assets/src/lib.rs +++ b/common/assets/src/lib.rs @@ -248,6 +248,36 @@ pub fn path_of(specifier: &str, ext: &str) -> PathBuf { .path_of(source::DirEntry::File(specifier, ext)) } +#[cfg(test)] +mod tests { + + use std::{ffi::OsStr, fs::File}; + use walkdir::WalkDir; + + /// Fail unless all `.ron` asset files successfully parse to `ron::Value`. + #[test] + fn parse_all_ron_files_to_value() { + let ext = OsStr::new("ron"); + WalkDir::new(crate::ASSETS_PATH.as_path()) + .into_iter() + .map(|ent| ent.unwrap().into_path()) + .filter(|path| path.is_file()) + .filter(|path| { + path.extension() + .map(|e| ext == e.to_ascii_lowercase()) + .unwrap_or(false) + }) + .for_each(|path| { + let file = File::open(&path).unwrap(); + if let Err(err) = ron::de::from_reader::<_, ron::Value>(file) { + println!("{:?}", path); + println!("{:#?}", err); + panic!("Parse failed"); + } + }); + } +} + #[warn(clippy::pedantic)] #[cfg(feature = "asset_tweak")] pub mod asset_tweak {