Skip to content

Commit e5201a7

Browse files
committed
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.
1 parent 5fa537b commit e5201a7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

tests/src/config.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{future::Future, pin::Pin, sync::Arc};
1+
use std::{future::Future, panic::Location, pin::Pin, sync::Arc};
22

33
use crate::{TestParameters, TestingContext};
44

@@ -26,14 +26,17 @@ cfg_if::cfg_if! {
2626
#[derive(Clone)]
2727
pub struct GpuTestConfiguration {
2828
pub(crate) name: String,
29+
pub(crate) location: &'static Location<'static>,
2930
pub(crate) params: TestParameters,
3031
pub(crate) test: Option<RunTestAsync>,
3132
}
3233

3334
impl GpuTestConfiguration {
35+
#[track_caller]
3436
pub fn new() -> Self {
3537
Self {
3638
name: String::new(),
39+
location: Location::caller(),
3740
params: TestParameters::default(),
3841
test: None,
3942
}

tests/src/run.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,10 @@ pub async fn execute_test(
116116

117117
// The call to matches_failure will log.
118118
if expectations_match_failures(&test_info.failures, failures) == ExpectationMatchResult::Panic {
119-
panic!();
119+
panic!(
120+
"{}: test {:?} did not behave as expected",
121+
config.location, config.name
122+
);
120123
}
121124
// Print the name of the test.
122125
log::info!("TEST FINISHED: {}", config.name);

0 commit comments

Comments
 (0)