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
@@ -660,3 +660,34 @@ Similar to cargo `build.rustc-wrapper` option, this flag takes a `rustc` wrapper
660
660
The first argument to the program will be the test builder program.
661
661
662
662
This flag can be passed multiple times to nest wrappers.
663
+
664
+
### `--document-tests`: show test items
665
+
666
+
Using this flag looks like this:
667
+
668
+
```bash
669
+
$ rustdoc src/lib.rs -Z unstable-options --cfg test --document-private-items --document-tests
670
+
```
671
+
672
+
By default, `rustdoc` does not document test items.
673
+
674
+
```rust
675
+
/// by default this test function would not be documented
676
+
#[test]
677
+
fntest_in_module() {
678
+
assert_eq!(2, 1+1);
679
+
}
680
+
/// by default this test module would not be documented
681
+
#[cfg(test)]
682
+
modtests {
683
+
/// by default this test function would not be documented
684
+
#[test]
685
+
fntest_in_a_test_module() {
686
+
assert_eq!(2, 1+1);
687
+
}
688
+
}
689
+
```
690
+
691
+
Note:
692
+
*`--cfg test` must be set because tests are guarded by #[cfg(test)].
693
+
*`--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