Skip to content

Rename test option --nocapture to --no-capture #24451

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions man/rustc.1
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ The test framework Rust provides executes tests in parallel. This variable sets
the maximum number of threads used for this purpose.

.TP
\fBRUST_TEST_NOCAPTURE\fR
A synonym for the --nocapture flag.
\fBRUST_TEST_NO_CAPTURE\fR
A synonym for the --no-capture flag.

.TP
\fBRUST_MIN_STACK\fR
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
logfile: config.logfile.clone(),
run_tests: true,
bench_benchmarks: true,
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
no_capture: env::var("RUST_TEST_NO_CAPTURE").is_ok(),
color: test::AutoColor,
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
true
});

for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
for key in vec!["RUST_TEST_NO_CAPTURE", "RUST_TEST_THREADS"] {
match env::var(key) {
Ok(val) =>
if exec_env.iter().find(|&&(ref x, _)| *x == key.to_string()).is_none() {
Expand Down
41 changes: 29 additions & 12 deletions src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub struct TestOpts {
pub run_tests: bool,
pub bench_benchmarks: bool,
pub logfile: Option<PathBuf>,
pub nocapture: bool,
pub no_capture: bool,
pub color: ColorConfig,
}

Expand All @@ -300,7 +300,7 @@ impl TestOpts {
run_tests: false,
bench_benchmarks: false,
logfile: None,
nocapture: false,
no_capture: false,
color: AutoColor,
}
}
Expand All @@ -316,7 +316,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
getopts::optflag("h", "help", "Display this message (longer with --help)"),
getopts::optopt("", "logfile", "Write logs to the specified file instead \
of stdout", "PATH"),
getopts::optflag("", "nocapture", "don't capture stdout/stderr of each \
getopts::optflag("", "nocapture", "Deprecated. Use --no-capture."),
getopts::optflag("", "no-capture", "Don't capture stdout/stderr of each \
task, allow printing directly"),
getopts::optopt("", "color", "Configure coloring of output:
auto = colorize if stdout is a tty and tests are run on serially (default);
Expand All @@ -335,7 +336,7 @@ By default, all tests are run in parallel. This can be altered with the
RUST_TEST_THREADS environment variable when running tests (set it to 1).

All tests have their standard output and standard error captured by default.
This can be overridden with the --nocapture flag or the RUST_TEST_NOCAPTURE=1
This can be overridden with the --no-capture flag or the RUST_TEST_NO_CAPTURE=1
environment variable. Logging is not captured by default.

Test Attributes:
Expand Down Expand Up @@ -381,9 +382,20 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
let run_tests = ! bench_benchmarks ||
matches.opt_present("test");

let mut nocapture = matches.opt_present("nocapture");
if !nocapture {
nocapture = env::var("RUST_TEST_NOCAPTURE").is_ok();
let mut no_capture = matches.opt_present("no-capture");
if !no_capture {
no_capture = env::var("RUST_TEST_NO_CAPTURE").is_ok();
}

// Warn on deprecated options but still accept them.
if matches.opt_present("nocapture") {
warn("--nocapture is deprecated. Use --no-capture instead.");
no_capture = true;
}

if env::var("RUST_TEST_NOCAPTURE").is_ok() {
warn("RUST_TEST_NOCAPTURE is deprecated. Use RUST_TEST_NO_CAPTURE instead.");
no_capture = true;
}

let color = match matches.opt_str("color").as_ref().map(|s| &**s) {
Expand All @@ -402,13 +414,18 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
run_tests: run_tests,
bench_benchmarks: bench_benchmarks,
logfile: logfile,
nocapture: nocapture,
no_capture: no_capture,
color: color,
};

Some(Ok(test_opts))
}

/// Writes a warning message to stderr.
fn warn(message: &str) {
writeln!(io::stderr(), "WARN: {}", message).unwrap();
}

#[derive(Clone, PartialEq)]
pub struct BenchSamples {
ns_iter_summ: stats::Summary,
Expand Down Expand Up @@ -929,7 +946,7 @@ pub fn run_test(opts: &TestOpts,

fn run_test_inner(desc: TestDesc,
monitor_ch: Sender<MonitorMsg>,
nocapture: bool,
no_capture: bool,
testfn: Thunk<'static>) {
struct Sink(Arc<Mutex<Vec<u8>>>);
impl Write for Sink {
Expand All @@ -948,7 +965,7 @@ pub fn run_test(opts: &TestOpts,
});

let result_guard = cfg.spawn(move || {
if !nocapture {
if !no_capture {
io::set_print(box Sink(data2.clone()));
io::set_panic(box Sink(data2));
}
Expand Down Expand Up @@ -983,8 +1000,8 @@ pub fn run_test(opts: &TestOpts,
monitor_ch.send((desc, TrMetrics(mm), Vec::new())).unwrap();
return;
}
DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f),
StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture,
DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.no_capture, f),
StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.no_capture,
Box::new(move|| f()))
}
}
Expand Down