Skip to content

Commit

Permalink
Make wgpu_test::valid print errors it detects. (#6136)
Browse files Browse the repository at this point in the history
* Make `wgpu_test::valid` print errors it detects.

When a block passed to `wgpu_test::valid` actually raises validation
errors, include the full error in the panic message.

---------

Co-authored-by: Erich Gubler <[email protected]>
  • Loading branch information
jimblandy and ErichDonGubler committed Aug 23, 2024
1 parent 5b148f2 commit 15d64c3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ pub fn fail<T>(
}

/// Run some code in an error scope and assert that validation succeeds.
#[track_caller]
pub fn valid<T>(device: &wgpu::Device, callback: impl FnOnce() -> T) -> T {
device.push_error_scope(wgpu::ErrorFilter::Validation);
let result = callback();
assert!(pollster::block_on(device.pop_error_scope()).is_none());
if let Some(error) = pollster::block_on(device.pop_error_scope()) {
panic!(
"`valid` block at {} encountered wgpu error:\n{error}",
std::panic::Location::caller()
);
}

result
}
Expand Down

0 comments on commit 15d64c3

Please sign in to comment.