@@ -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]
650671fn validation_error_messages ( ) {
@@ -695,12 +716,7 @@ error: Entry point main at Compute is invalid
695716 ] ;
696717
697718 for ( source, expected_err) in cases {
698- let module = naga:: front:: wgsl:: parse_str ( source) . unwrap ( ) ;
699- let err = valid:: Validator :: new ( Default :: default ( ) , valid:: Capabilities :: all ( ) )
700- . validate ( & module)
701- . expect_err ( "module should be invalid" ) ;
702- println ! ( "{}" , err. emit_to_string( source) ) ;
703- assert_eq ! ( err. emit_to_string( source) , expected_err) ;
719+ assert_wgsl_validation_err ( source, expected_err)
704720 }
705721}
706722
0 commit comments