From 15d64c362eb623e87b2449dba5b893c0f3567c42 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Fri, 23 Aug 2024 07:17:28 -0700 Subject: [PATCH] Make `wgpu_test::valid` print errors it detects. (#6136) * 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 --- tests/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/src/lib.rs b/tests/src/lib.rs index fcc1615875..89f7e91c6e 100644 --- a/tests/src/lib.rs +++ b/tests/src/lib.rs @@ -54,10 +54,16 @@ pub fn fail( } /// Run some code in an error scope and assert that validation succeeds. +#[track_caller] pub fn valid(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 }