Skip to content

Commit

Permalink
When a #[gpu_test] test fails, print its source location.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jimblandy committed May 2, 2024
1 parent 5fa537b commit e5201a7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion tests/src/config.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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,
}
Expand Down
5 changes: 4 additions & 1 deletion tests/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit e5201a7

Please sign in to comment.