ScanMountGoat / wgsl_to_wgpu

Generate typesafe Rust bindings from WGSL shaders to wgpu
MIT License
45 stars 13 forks source link

Improve test maintainability #63

Open ScanMountGoat opened 4 months ago

ScanMountGoat commented 4 months ago

The current tests are difficult to edit when output needs to change. One approach is to place test input and output data in separate files for easier editing and syntax highlighting. The generated code can also be tested to see if it actually compiles.

9SMTM6 commented 3 months ago

Trying to collect some pros and cons for current process (inline quote!d reference) vs. some sort of snapshot testing.

I'll try to keep this up-to-date.

Pro:

Mixed:

Contra:

9SMTM6 commented 3 months ago

We should check the output of assert_eq on changes. Easiest way would probably be to simply test how a change surfaces in wgsl_bindgen .

FYI, these are the lints I currently disable in my application. A lot if this is probably caused by stricter than normal lint rules.

#[allow(
    unused,
    elided_lifetimes_in_paths,
    clippy::approx_constant,
    clippy::module_name_repetitions,
    clippy::pattern_type_mismatch,
    clippy::unreadable_literal,
)]
ScanMountGoat commented 3 months ago

this bloats the size of the source-code

This is pretty normal if there are a lot of unit tests. The public API is pretty minimal, so these tests wouldn't work as integration tests in the tests folder. I am looking into consolidating some of the unit tests to avoid some repetition.

this can be an arduous process that suppresses internal improvements or adjustments, because its too much work

Most required changes to the tests have been fairly minor from my experience. Please open an issue if something requires more work to change than feels reasonable.

diffs on github make it hard to differentiate between changes to the actual code and generated one

I've started separating out the large WGSL inputs and Rust outputs into separate files. This should make the process easier and give a nicer experience with formatting and syntax highlighting.

dependencies for 'snapshot-testing' might not be required

You can write out the current output to a file in tests temporarily using std::fs::write and the defined pretty printing functions. If all the tests cases pass, I don't see a reason to need to also include the actual output as a separate file from the expected output. I'll reassess if it's worth using snapshot testing after I finish reworking the test suite.