You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The new option --document-tests is unstable and documented as such.
In order to use it is needed to add `--cfg test` and in case the tests
are not marked public to add `--document-private-items`.
The implementation hide the auto generate main test function and
constants.
Copy file name to clipboardexpand all lines: src/doc/rustdoc/src/unstable-features.md
+31
Original file line number
Diff line number
Diff line change
@@ -627,3 +627,34 @@ add the `--scrape-tests` flag.
627
627
628
628
This flag enables the generation of links in the source code pages which allow the reader
629
629
to jump to a type definition.
630
+
631
+
### `--document-tests`: show test items
632
+
633
+
Using this flag looks like this:
634
+
635
+
```bash
636
+
$ rustdoc src/lib.rs -Z unstable-options --cfg test --document-private-items --document-tests
637
+
```
638
+
639
+
By default, `rustdoc` does not document test items.
640
+
641
+
```rust
642
+
/// by default this test function would not be documented
643
+
#[test]
644
+
fntest_in_module() {
645
+
assert_eq!(2, 1+1);
646
+
}
647
+
/// by default this test module would not be documented
648
+
#[cfg(test)]
649
+
modtests {
650
+
/// by default this test function would not be documented
651
+
#[test]
652
+
fntest_in_a_test_module() {
653
+
assert_eq!(2, 1+1);
654
+
}
655
+
}
656
+
```
657
+
658
+
Note:
659
+
*`--cfg test` must be set because tests are guarded by #[cfg(test)].
660
+
*`--document-private-items` is typically required because it is standard practice to keep test items private. By enabling this option, you ensure that private items, including tests, are documented as needed while maintaining their non-public status.
0 commit comments