-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
In Naga, it's cumbersome to write tests that exercise front-end error checking and validation in Naga; in the naga/tests directory, see validation.rs and wgsl_errors.rs. This is probably one of the reasons that our test coverage for diagnostics is so weak. Creating a new test should be as easy as dropping some source code in a file in the appropriate directory and marking up the expected errors.
For inspiration: rustc's test suite lets you write error tests like the below:
fn main() {
let mut x = 0;
let mut add_to_x = |n| { x += n; x };
//~^ NOTE: closure cannot be moved more than once as it is not `Copy` due to moving the variable `x` out of its environment
//~| NOTE: calling `copy_of_add_to_x` requires mutable binding due to mutable borrow of `x`
let copy_of_add_to_x = add_to_x; // this moves, rather than copies
//~^ NOTE: value moved here
assert_eq!(add_to_x(copy_of_add_to_x(1)), 2); // error: use of moved value
//~^ ERROR: borrow of moved value: `add_to_x`
//~| NOTE: value borrowed here after move
//~^^^ ERROR: cannot borrow `copy_of_add_to_x` as mutable, as it is not declared as mutable
//~| NOTE: cannot borrow as mutable
}(This example is taken from the test suite for our book, which uses an extracted version of rustc's harness.)
The lines starting with //~ indicate the errors that are expected to appear on each line. The test harness parses those out and uses them to build expected values for the message+labels+notes style error reports that rustc produces. The details of the | and ^ and NOTE stuff are not too important.
Naga also produces similar reports (two flavors, I think), and it would be easy to write a harness that lets us write something like the above, adapted to Naga's error types.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status