Add a snapshot for parsing spirv input

This commit is contained in:
Dzmitry Malyshau
2021-02-08 12:30:21 -05:00
committed by Dzmitry Malyshau
parent cf0a86afd4
commit 5b94ecd9b2
5 changed files with 1175 additions and 25 deletions

View File

@@ -16,8 +16,6 @@ mod error;
mod flow;
mod function;
mod image;
#[cfg(all(test, feature = "serialize"))]
mod rosetta;
use convert::*;
use error::Error;

View File

@@ -1,23 +0,0 @@
use std::{fs, path::Path};
const TEST_PATH: &str = "test-data";
fn rosetta_test(file_name: &str) {
if true {
return; //TODO: fix this test
}
let file_path = Path::new(TEST_PATH).join(file_name);
let input = fs::read(&file_path).unwrap();
let module = super::parse_u8_slice(&input, &Default::default()).unwrap();
let output = ron::ser::to_string_pretty(&module, Default::default()).unwrap();
let expected = fs::read_to_string(file_path.with_extension("expected.ron")).unwrap();
difference::assert_diff!(output.as_str(), expected.as_str(), "", 0);
}
#[test]
fn simple() {
rosetta_test("simple/simple.spv")
}

BIN
tests/in/shadow.spv Normal file

Binary file not shown.

1150
tests/out/shadow.ron.snap Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -208,3 +208,28 @@ fn convert_wgsl_shadow() {
fn convert_wgsl_texture_array() {
convert_wgsl("texture-array", Language::SPIRV);
}
#[cfg(feature = "spv-in")]
fn convert_spv(name: &str) {
let module = naga::front::spv::parse_u8_slice(
&std::fs::read(format!("tests/in/{}{}", name, ".spv")).expect("Couldn't find spv file"),
&Default::default(),
)
.unwrap();
naga::proc::Validator::new().validate(&module).unwrap();
#[cfg(feature = "serialize")]
{
let config = ron::ser::PrettyConfig::default();
let output = ron::ser::to_string_pretty(&module, config).unwrap();
with_snapshot_settings(|| {
insta::assert_snapshot!(format!("{}.ron", name), output);
});
}
}
#[cfg(feature = "spv-in")]
#[test]
fn convert_spv_shadow() {
convert_spv("shadow");
}