Skip to content

Commit 7c2436a

Browse files
authored
Rollup merge of #87372 - GuillaumeGomez:move-test_main-calls, r=jyn514
Move calls to test_main into one function Fixes #86254. cc ``@jyn514`` r? ``@camelid``
2 parents a247257 + ef953b0 commit 7c2436a

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/librustdoc/doctest.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
105105
registry: rustc_driver::diagnostics_registry(),
106106
};
107107

108-
let mut test_args = options.test_args.clone();
108+
let test_args = options.test_args.clone();
109109
let display_warnings = options.display_warnings;
110110
let nocapture = options.nocapture;
111111
let externs = options.externs.clone();
@@ -166,12 +166,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
166166
Err(ErrorReported) => return Err(ErrorReported),
167167
};
168168

169-
test_args.insert(0, "rustdoctest".to_string());
170-
if nocapture {
171-
test_args.push("--nocapture".to_string());
172-
}
173-
174-
test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings)));
169+
run_tests(test_args, nocapture, display_warnings, tests);
175170

176171
// Collect and warn about unused externs, but only if we've gotten
177172
// reports for each doctest
@@ -214,6 +209,19 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
214209
Ok(())
215210
}
216211

212+
crate fn run_tests(
213+
mut test_args: Vec<String>,
214+
nocapture: bool,
215+
display_warnings: bool,
216+
tests: Vec<test::TestDescAndFn>,
217+
) {
218+
test_args.insert(0, "rustdoctest".to_string());
219+
if nocapture {
220+
test_args.push("--nocapture".to_string());
221+
}
222+
test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings)));
223+
}
224+
217225
// Look for `#![doc(test(no_crate_inject))]`, used by crates in the std facade.
218226
fn scrape_test_config(attrs: &[ast::Attribute]) -> TestOptions {
219227
use rustc_ast_pretty::pprust;

src/librustdoc/markdown.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ crate fn render<P: AsRef<Path>>(
115115
}
116116

117117
/// Runs any tests/code examples in the markdown file `input`.
118-
crate fn test(mut options: Options) -> Result<(), String> {
118+
crate fn test(options: Options) -> Result<(), String> {
119119
let input_str = read_to_string(&options.input)
120120
.map_err(|err| format!("{}: {}", options.input.display(), err))?;
121121
let mut opts = TestOptions::default();
@@ -135,14 +135,11 @@ crate fn test(mut options: Options) -> Result<(), String> {
135135

136136
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
137137

138-
options.test_args.insert(0, "rustdoctest".to_string());
139-
if options.nocapture {
140-
options.test_args.push("--nocapture".to_string());
141-
}
142-
test::test_main(
143-
&options.test_args,
138+
crate::doctest::run_tests(
139+
options.test_args,
140+
options.nocapture,
141+
options.display_warnings,
144142
collector.tests,
145-
Some(test::Options::new().display_output(options.display_warnings)),
146143
);
147144
Ok(())
148145
}

0 commit comments

Comments
 (0)