Skip to content

Commit 6ca0e5e

Browse files
Add --nocapture option to rustdoc
1 parent 68511b5 commit 6ca0e5e

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

src/librustdoc/config.rs

+5
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ crate struct Options {
156156
crate run_check: bool,
157157
/// Whether doctests should emit unused externs
158158
crate json_unused_externs: bool,
159+
/// Whether to skip capturing stdout and stderr of tests.
160+
crate nocapture: bool,
159161
}
160162

161163
impl fmt::Debug for Options {
@@ -199,6 +201,7 @@ impl fmt::Debug for Options {
199201
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
200202
.field("run_check", &self.run_check)
201203
.field("no_run", &self.no_run)
204+
.field("nocapture", &self.nocapture)
202205
.finish()
203206
}
204207
}
@@ -627,6 +630,7 @@ impl Options {
627630
let run_check = matches.opt_present("check");
628631
let generate_redirect_map = matches.opt_present("generate-redirect-map");
629632
let show_type_layout = matches.opt_present("show-type-layout");
633+
let nocapture = matches.opt_present("nocapture");
630634

631635
let (lint_opts, describe_lints, lint_cap, _) =
632636
get_cmd_lint_options(matches, error_format, &debugging_opts);
@@ -665,6 +669,7 @@ impl Options {
665669
test_builder,
666670
run_check,
667671
no_run,
672+
nocapture,
668673
render_options: RenderOptions {
669674
output,
670675
external_html,

src/librustdoc/doctest.rs

+7
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
107107

108108
let mut test_args = options.test_args.clone();
109109
let display_warnings = options.display_warnings;
110+
let nocapture = options.nocapture;
110111
let externs = options.externs.clone();
111112
let json_unused_externs = options.json_unused_externs;
112113

@@ -166,6 +167,9 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
166167
};
167168

168169
test_args.insert(0, "rustdoctest".to_string());
170+
if nocapture {
171+
test_args.push("--nocapture".to_string());
172+
}
169173

170174
test::test_main(&test_args, tests, Some(test::Options::new().display_output(display_warnings)));
171175

@@ -463,6 +467,9 @@ fn run_test(
463467
return Err(TestFailure::UnexpectedRunPass);
464468
} else if !should_panic && !out.status.success() {
465469
return Err(TestFailure::ExecutionFailure(out));
470+
} else if options.nocapture {
471+
io::stdout().write_all(&out.stdout).expect("failed to write stdout");
472+
io::stderr().write_all(&out.stderr).expect("failed to write stderr");
466473
}
467474
}
468475
}

src/librustdoc/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,9 @@ fn opts() -> Vec<RustcOptGroup> {
604604
unstable("show-type-layout", |o| {
605605
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs")
606606
}),
607+
unstable("nocapture", |o| {
608+
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests")
609+
}),
607610
]
608611
}
609612

src/librustdoc/markdown.rs

+3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ crate fn test(mut options: Options) -> Result<(), String> {
136136
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);
137137

138138
options.test_args.insert(0, "rustdoctest".to_string());
139+
if options.nocapture {
140+
options.test_args.push("--nocapture".to_string());
141+
}
139142
test::test_main(
140143
&options.test_args,
141144
collector.tests,

0 commit comments

Comments
 (0)