wgpu/naga/tests/example_wgsl.rs

56 lines
1.7 KiB
Rust
Raw Normal View History

#![cfg(feature = "wgsl-in")]
2021-03-25 18:46:35 +00:00
use naga::{front::wgsl, valid::Validator};
use std::{fs, path::PathBuf};
/// Runs through all example shaders and ensures they are valid wgsl.
#[test]
2023-10-19 16:06:42 +00:00
pub fn parse_example_wgsl() {
let read_dir = match PathBuf::from(env!("CARGO_MANIFEST_DIR"))
.join("examples")
.read_dir()
{
Ok(iter) => iter,
Err(e) => {
log::error!("Unable to open the examples folder: {:?}", e);
return;
}
};
for example_entry in read_dir {
let read_files = match example_entry {
Ok(dir_entry) => match dir_entry.path().read_dir() {
Ok(iter) => iter,
Err(_) => continue,
},
Err(e) => {
log::warn!("Skipping example: {:?}", e);
continue;
}
};
for file_entry in read_files {
let shader = match file_entry {
Ok(entry) => match entry.path().extension() {
2022-08-24 21:25:59 +00:00
Some(ostr) if ostr == "wgsl" => {
println!("Validating {:?}", entry.path());
fs::read_to_string(entry.path()).unwrap_or_default()
}
_ => continue,
},
Err(e) => {
log::warn!("Skipping file: {:?}", e);
continue;
}
};
let module = wgsl::parse_str(&shader).unwrap();
//TODO: re-use the validator
2021-05-14 04:15:11 +00:00
Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::all(),
)
.validate(&module)
.unwrap();
}
}
}