Skip to content

Commit 489f41c

Browse files
committed
Add support to generate documentation for tests
1 parent d0ccb54 commit 489f41c

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

src/librustdoc/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ pub(crate) struct Options {
160160
/// the compiler will scrape examples and not generate documentation.
161161
pub(crate) scrape_examples_options: Option<ScrapeExamplesOptions>,
162162

163+
/// Whether to generate documentation for tests.
164+
pub(crate) document_tests: bool,
165+
163166
/// Note: this field is duplicated in `RenderOptions` because it's useful
164167
/// to have it in both places.
165168
pub(crate) unstable_features: rustc_feature::UnstableFeatures,
@@ -213,6 +216,7 @@ impl fmt::Debug for Options {
213216
.field("test_builder_wrappers", &self.test_builder_wrappers)
214217
.field("nocapture", &self.nocapture)
215218
.field("scrape_examples_options", &self.scrape_examples_options)
219+
.field("document_tests", &self.document_tests)
216220
.field("unstable_features", &self.unstable_features)
217221
.finish()
218222
}
@@ -732,6 +736,7 @@ impl Options {
732736
}
733737

734738
let scrape_examples_options = ScrapeExamplesOptions::new(matches, &dcx);
739+
let document_tests = matches.opt_present("document-tests");
735740
let with_examples = matches.opt_strs("with-examples");
736741
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &dcx);
737742

@@ -777,6 +782,7 @@ impl Options {
777782
output_format,
778783
json_unused_externs,
779784
scrape_examples_options,
785+
document_tests,
780786
unstable_features,
781787
expanded_args: args,
782788
};

src/librustdoc/core.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ pub(crate) fn create_config(
195195
describe_lints,
196196
lint_cap,
197197
scrape_examples_options,
198+
document_tests,
198199
expanded_args,
199200
..
200201
}: RustdocOptions,
@@ -227,7 +228,8 @@ pub(crate) fn create_config(
227228
if proc_macro_crate { vec![CrateType::ProcMacro] } else { vec![CrateType::Rlib] };
228229
let resolve_doc_links =
229230
if *document_private { ResolveDocLinks::All } else { ResolveDocLinks::Exported };
230-
let test = scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false);
231+
let test =
232+
scrape_examples_options.map(|opts| opts.scrape_tests).unwrap_or(false) || document_tests;
231233
// plays with error output here!
232234
let sessopts = config::Options {
233235
maybe_sysroot,

src/librustdoc/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ fn opts() -> Vec<RustcOptGroup> {
587587
unstable("scrape-tests", |o| {
588588
o.optflag("", "scrape-tests", "Include test code when scraping examples")
589589
}),
590+
unstable("document-tests", |o| {
591+
o.optflagmulti("", "document-tests", "Generate documentation for tests")
592+
}),
590593
unstable("with-examples", |o| {
591594
o.optmulti(
592595
"",

0 commit comments

Comments
 (0)