Is there a way to name a Rust doctest?

134 Views Asked by At

Doctests commandeer the language identifier to allow you to add "attributes" that affect the behavior of the test.

However, there doesn't appear to be a way to add a name to a documentation test. Is there a way I can better identify them when looking at a long output from a test run?

I'd love to have something like

/// ```[construction_test]
/// # use my_crate::MyStruct;
/// MyStruct{ name: "jk".to_owned() };
/// ```
struct MyStruct{
    name: String,
}

that would result in the usual named output:

-> cargo test --doc

    Finished test [unoptimized + debuginfo] target(s) in 7.71s
   Doc-tests my_crate

running 1 test
test src/my_crate/lib.rs - my_crate::MyStruct::construction_test (line 10) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.45s

   Doc-tests my_crate
1

There are 1 best solutions below

0
Chayim Friedman On

No. However, 11 days ago (as of time of writing) an RFC for exactly that was submitted. So we can wait and see if it is accepted.