When a #[gpu_test] test fails, print its source location.

Use `std::panic::Location` to record the source location of each
`#[gpu_test]` test, and if it fails, include that in the error output.
This is not essential, but it should make working with failures a bit
more comfortable.
This commit is contained in:
Jim Blandy 2024-04-21 11:12:24 -07:00
parent 5fa537bfd9
commit e5201a7267
2 changed files with 8 additions and 2 deletions

View File

@ -1,4 +1,4 @@
use std::{future::Future, pin::Pin, sync::Arc};
use std::{future::Future, panic::Location, pin::Pin, sync::Arc};
use crate::{TestParameters, TestingContext};
@ -26,14 +26,17 @@ cfg_if::cfg_if! {
#[derive(Clone)]
pub struct GpuTestConfiguration {
pub(crate) name: String,
pub(crate) location: &'static Location<'static>,
pub(crate) params: TestParameters,
pub(crate) test: Option<RunTestAsync>,
}
impl GpuTestConfiguration {
#[track_caller]
pub fn new() -> Self {
Self {
name: String::new(),
location: Location::caller(),
params: TestParameters::default(),
test: None,
}

View File

@ -116,7 +116,10 @@ pub async fn execute_test(
// The call to matches_failure will log.
if expectations_match_failures(&test_info.failures, failures) == ExpectationMatchResult::Panic {
panic!();
panic!(
"{}: test {:?} did not behave as expected",
config.location, config.name
);
}
// Print the name of the test.
log::info!("TEST FINISHED: {}", config.name);