Skip to content

Commit 48be25d

Browse files
committed
libtest: Emit warnings when using deprecated options
1 parent 7ac2fa7 commit 48be25d

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/libtest/lib.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,8 @@ fn optgroups() -> Vec<getopts::OptGroup> {
316316
getopts::optflag("h", "help", "Display this message (longer with --help)"),
317317
getopts::optopt("", "logfile", "Write logs to the specified file instead \
318318
of stdout", "PATH"),
319-
getopts::optflag("", "no-capture", "don't capture stdout/stderr of each \
319+
getopts::optflag("", "nocapture", "Deprecated. Use --no-capture."),
320+
getopts::optflag("", "no-capture", "Don't capture stdout/stderr of each \
320321
task, allow printing directly"),
321322
getopts::optopt("", "color", "Configure coloring of output:
322323
auto = colorize if stdout is a tty and tests are run on serially (default);
@@ -386,6 +387,17 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
386387
no_capture = env::var("RUST_TEST_NO_CAPTURE").is_ok();
387388
}
388389

390+
// Warn on deprecated options but still accept them.
391+
if matches.opt_present("nocapture") {
392+
warn("--nocapture is deprecated. Use --no-capture instead.");
393+
no_capture = true;
394+
}
395+
396+
if env::var("RUST_TEST_NOCAPTURE").is_ok() {
397+
warn("RUST_TEST_NOCAPTURE is deprecated. Use RUST_TEST_NO_CAPTURE instead.");
398+
no_capture = true;
399+
}
400+
389401
let color = match matches.opt_str("color").as_ref().map(|s| &**s) {
390402
Some("auto") | None => AutoColor,
391403
Some("always") => AlwaysColor,
@@ -409,6 +421,11 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
409421
Some(Ok(test_opts))
410422
}
411423

424+
/// Writes a warning message to stderr.
425+
fn warn(message: &str) {
426+
writeln!(io::stderr(), "WARN: {}", message).unwrap();
427+
}
428+
412429
#[derive(Clone, PartialEq)]
413430
pub struct BenchSamples {
414431
ns_iter_summ: stats::Summary,

0 commit comments

Comments
 (0)