diff --git a/man/rustc.1 b/man/rustc.1 index b15829db431df..d73bf258583ed 100644 --- a/man/rustc.1 +++ b/man/rustc.1 @@ -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 diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index 2ee391a937433..e64c7db72614f 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -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, } } diff --git a/src/compiletest/header.rs b/src/compiletest/header.rs index a648e51497e79..4c54862791cc4 100644 --- a/src/compiletest/header.rs +++ b/src/compiletest/header.rs @@ -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() { diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 9cbfe283cbddc..74b4acb3319aa 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -287,7 +287,7 @@ pub struct TestOpts { pub run_tests: bool, pub bench_benchmarks: bool, pub logfile: Option, - pub nocapture: bool, + pub no_capture: bool, pub color: ColorConfig, } @@ -300,7 +300,7 @@ impl TestOpts { run_tests: false, bench_benchmarks: false, logfile: None, - nocapture: false, + no_capture: false, color: AutoColor, } } @@ -316,7 +316,8 @@ fn optgroups() -> Vec { 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); @@ -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: @@ -381,9 +382,20 @@ pub fn parse_opts(args: &[String]) -> Option { 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) { @@ -402,13 +414,18 @@ pub fn parse_opts(args: &[String]) -> Option { 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, @@ -929,7 +946,7 @@ pub fn run_test(opts: &TestOpts, fn run_test_inner(desc: TestDesc, monitor_ch: Sender, - nocapture: bool, + no_capture: bool, testfn: Thunk<'static>) { struct Sink(Arc>>); impl Write for Sink { @@ -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)); } @@ -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())) } }