Skip to main content

gpu_tests

Macro gpu_tests 

Source
macro_rules! gpu_tests {
    (@acc [$($acc:tt)*]) => { ... };
    (@acc [$($acc:tt)*]
     #[host_only]
     $name:ident,
     $($rest:tt)*) => { ... };
    (@acc [$($acc:tt)*]
     #[should_panic(expected = $msg:literal)]
     $name:ident,
     $($rest:tt)*) => { ... };
    (@acc [$($acc:tt)*] $name:ident, $($rest:tt)*) => { ... };
    ($($rest:tt)*) => { ... };
}
Expand description

Declares a file’s GPU tests, and the catalog the harness runs them from.

The bodies are ordinary async fns declared in the file; this macro lists them so the harness can reach them by name. A name that has no body, or one that is not an async fn, is a compile error, so the list cannot drift out of step with the file.

A test that must panic carries #[should_panic(expected = "...")] in the list rather than on its body, because the attribute is what the runner compares a caught panic against and the body is not itself a test item.

A test only the host can run carries #[host_only] in the list instead of a target cfg around a second invocation of this macro, so one list stays the whole truth about what the file declares.

§Example

use unlit_wgpu_test_util::gpu_tests;

async fn draws_a_triangle() {
    assert_eq!(1 + 1, 2);
}

async fn rejects_an_empty_mesh() {
    panic!("rejected: a mesh needs at least one vertex");
}

gpu_tests! {
    draws_a_triangle,
    #[should_panic(expected = "rejected:")]
    rejects_an_empty_mesh,
}

assert_eq!(all_tests().len(), 2);
assert_eq!(all_tests()[1].expected_panic, Some("rejected:"));