Skip to content

Commit d2dbbbb

Browse files
WIP: test(naga): emit diff-ish output for validation_error_messages failures
1 parent 17c6df3 commit d2dbbbb

1 file changed

Lines changed: 22 additions & 6 deletions

File tree

naga/tests/naga/validation.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,27 @@ fn binding_arrays_cannot_hold_scalars() {
645645
assert!(t.validator.validate(&t.module).is_err());
646646
}
647647

648+
#[cfg(feature = "wgsl-in")]
649+
#[track_caller]
650+
fn assert_wgsl_validation_err(input: &str, snapshot: &str) {
651+
let module = naga::front::wgsl::parse_str(input)
652+
.expect("expected parsed WGSL module, but WGSL parse failed");
653+
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
654+
.validate(&module)
655+
.expect_err("module should be invalid");
656+
let output = err.emit_to_string(input);
657+
if output != snapshot {
658+
for diff in diff::lines(snapshot, &output) {
659+
match diff {
660+
diff::Result::Left(l) => println!("-{l}"),
661+
diff::Result::Both(l, _) => println!(" {l}"),
662+
diff::Result::Right(r) => println!("+{r}"),
663+
}
664+
}
665+
panic!("Error snapshot failed");
666+
}
667+
}
668+
648669
#[cfg(feature = "wgsl-in")]
649670
#[test]
650671
fn validation_error_messages() {
@@ -715,12 +736,7 @@ error: Entry point main at Compute is invalid
715736
];
716737

717738
for (source, expected_err) in cases {
718-
let module = naga::front::wgsl::parse_str(source).unwrap();
719-
let err = valid::Validator::new(Default::default(), valid::Capabilities::all())
720-
.validate(&module)
721-
.expect_err("module should be invalid");
722-
eprintln!("{}", err.emit_to_string(source));
723-
assert_eq!(err.emit_to_string(source), expected_err);
739+
assert_wgsl_validation_err(source, expected_err)
724740
}
725741
}
726742

0 commit comments

Comments
 (0)