Merge branch '1158-parse-all-rons-to-value' into 'master'

Fix #1158 - Add a test that all the `.ron` manifests parse

Closes #1158

See merge request veloren/veloren!2533
This commit is contained in:
Marcel 2021-07-03 18:11:04 +00:00
commit 3ebc5428bd
3 changed files with 34 additions and 0 deletions

1
Cargo.lock generated
View File

@ -5823,6 +5823,7 @@ dependencies = [
"serde",
"serial_test",
"tracing",
"walkdir 2.3.2",
]
[[package]]

View File

@ -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"]

View File

@ -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 {