From dfd5f134ee21e7ca6bd9f6ddb7ba976d51b58443 Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Wed, 15 Apr 2015 01:02:54 -0500 Subject: [PATCH 1/2] libtest: Rename test option --nocapture to --no-capture Rust's built-in unit testing framework supports not capturing the output of tests. The current flag `--nocapture` is inconsistent with the other long name options, i.e., they are written in spinal-case (a.k.a. kebab-case). Codegen options `no-prepopulate-passes`, `no-vectorize-loops`, `no-vectorize-slp`, `no-integrated-as`, and `no-redzone` are hyphenated between "no" and the name. Cargo has `--no-default-features` and `--no-deps`. This change renames the test option `--nocapture` to `--no-capture` to be consistent with Rust's naming of long name options. The ENV variable `RUST_TEST_NOCAPTURE` is also renamed to `RUST_TEST_NO_CAPTURE`. Because this is a public facing option, it is a [breaking-change]. --- man/rustc.1 | 4 ++-- src/compiletest/compiletest.rs | 2 +- src/compiletest/header.rs | 2 +- src/libtest/lib.rs | 24 ++++++++++++------------ 4 files changed, 16 insertions(+), 16 deletions(-) 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..3c5600faa44e1 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,7 @@ 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("", "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 +335,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 +381,9 @@ 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(); } let color = match matches.opt_str("color").as_ref().map(|s| &**s) { @@ -402,7 +402,7 @@ 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, }; @@ -929,7 +929,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 +948,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 +983,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())) } } From 70c705b44a1e129e574d88f2ca6f9cfe371c3a4a Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Tue, 28 Apr 2015 00:44:13 -0500 Subject: [PATCH 2/2] libtest: Emit warnings when using deprecated options --- src/libtest/lib.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 3c5600faa44e1..74b4acb3319aa 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -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("", "no-capture", "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); @@ -386,6 +387,17 @@ pub fn parse_opts(args: &[String]) -> Option { 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) { Some("auto") | None => AutoColor, Some("always") => AlwaysColor, @@ -409,6 +421,11 @@ pub fn parse_opts(args: &[String]) -> Option { 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,