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
@@ -830,3 +830,34 @@ will be split as follows:
830
830
"you today?",
831
831
]
832
832
```
833
+
834
+
### `--document-tests`: show test items
835
+
836
+
Using this flag looks like this:
837
+
838
+
```bash
839
+
$ rustdoc src/lib.rs -Z unstable-options --cfg test --document-private-items --document-tests
840
+
```
841
+
842
+
By default, `rustdoc` does not document test items.
843
+
844
+
```rust
845
+
/// by default this test function would not be documented
846
+
#[test]
847
+
fntest_in_module() {
848
+
assert_eq!(2, 1+1);
849
+
}
850
+
/// by default this test module would not be documented
851
+
#[cfg(test)]
852
+
modtests {
853
+
/// by default this test function would not be documented
854
+
#[test]
855
+
fntest_in_a_test_module() {
856
+
assert_eq!(2, 1+1);
857
+
}
858
+
}
859
+
```
860
+
861
+
Note:
862
+
*`--cfg test` must be set because tests are guarded by #[cfg(test)].
863
+
*`--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