I have a codebase where some information about the test cases is included in the doc strings, like so:
/// This describes the add function
pub fn add(left: usize, right: usize) -> usize {
left + right
}
#[cfg(test)]
mod tests {
use super::*;
/// This describes the test
#[test]
fn it_works() {
let result = add(2, 2);
assert_eq!(result, 4);
}
/// This function resides inside the `tests` module, but it is not a test itself
fn some_helper_function() {}
}
I want to use rustdoc to extract the doc strings, but unfortunately I could not manage to get rustdoc to output anything about functions annotated with the #[test] macro
I am using cargo rustdoc -- --document-private-items --cfg test , which adds the tests module and tests.some_helper_function to the output, but tests.it_works is not present.
On Stack Overflow, someone suggested swapping out #[test] for #[cfg_attr(not(doc), test)] a couple of years ago, I would like to avoid modifying the source code though. Do you have any idea how to do this?
i mean, rustdoc calls into a rust parser, so it's not unreasonable to think it might be able to do something like this. unfortunatly it seems it's not so.
Hi @binarycat, thanks for your answers. That was really helpful!
I tried setting RUSTFLAGS to --test, but that seems to fail in another place
error: output of --print=file-names missing when learning about target-specific information from rustc
Oh thanks, I didn't know tree-sitter until now. I did not know it until now, but I took some time to check it out today. I think I understand the basic principle - still, I don't understand one thing: When using the playground, I was not able to produce a tree with any doc_comment element, not even with an example from the test suite: