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