Skip to content

Commit

Permalink
Add --nocapture option to rustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jul 18, 2021
1 parent 68511b5 commit 6ca0e5e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/librustdoc/config.rs
Expand Up @@ -156,6 +156,8 @@ crate struct Options {
crate run_check: bool,
/// Whether doctests should emit unused externs
crate json_unused_externs: bool,
/// Whether to skip capturing stdout and stderr of tests.
crate nocapture: bool,
}

impl fmt::Debug for Options {
Expand Down Expand Up @@ -199,6 +201,7 @@ impl fmt::Debug for Options {
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
.field("run_check", &self.run_check)
.field("no_run", &self.no_run)
.field("nocapture", &self.nocapture)
.finish()
}
}
Expand Down Expand Up @@ -627,6 +630,7 @@ impl Options {
let run_check = matches.opt_present("check");
let generate_redirect_map = matches.opt_present("generate-redirect-map");
let show_type_layout = matches.opt_present("show-type-layout");
let nocapture = matches.opt_present("nocapture");

let (lint_opts, describe_lints, lint_cap, _) =
get_cmd_lint_options(matches, error_format, &debugging_opts);
Expand Down Expand Up @@ -665,6 +669,7 @@ impl Options {
test_builder,
run_check,
no_run,
nocapture,
render_options: RenderOptions {
output,
external_html,
Expand Down
7 changes: 7 additions & 0 deletions src/librustdoc/doctest.rs
Expand Up @@ -107,6 +107,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {

let mut test_args = options.test_args.clone();
let display_warnings = options.display_warnings;
let nocapture = options.nocapture;
let externs = options.externs.clone();
let json_unused_externs = options.json_unused_externs;

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

test_args.insert(0, "rustdoctest".to_string());
if nocapture {
test_args.push("--nocapture".to_string());
}

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

Expand Down Expand Up @@ -463,6 +467,9 @@ fn run_test(
return Err(TestFailure::UnexpectedRunPass);
} else if !should_panic && !out.status.success() {
return Err(TestFailure::ExecutionFailure(out));
} else if options.nocapture {
io::stdout().write_all(&out.stdout).expect("failed to write stdout");
io::stderr().write_all(&out.stderr).expect("failed to write stderr");
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/lib.rs
Expand Up @@ -604,6 +604,9 @@ fn opts() -> Vec<RustcOptGroup> {
unstable("show-type-layout", |o| {
o.optflagmulti("", "show-type-layout", "Include the memory layout of types in the docs")
}),
unstable("nocapture", |o| {
o.optflag("", "nocapture", "Don't capture stdout and stderr of tests")
}),
]
}

Expand Down
3 changes: 3 additions & 0 deletions src/librustdoc/markdown.rs
Expand Up @@ -136,6 +136,9 @@ crate fn test(mut options: Options) -> Result<(), String> {
find_testable_code(&input_str, &mut collector, codes, options.enable_per_target_ignores, None);

options.test_args.insert(0, "rustdoctest".to_string());
if options.nocapture {
options.test_args.push("--nocapture".to_string());
}
test::test_main(
&options.test_args,
collector.tests,
Expand Down

0 comments on commit 6ca0e5e

Please sign in to comment.