Skip to content

Commit dfd5f13

Browse files
committed
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].
1 parent 26933a6 commit dfd5f13

File tree

4 files changed

+16
-16
lines changed

4 files changed

+16
-16
lines changed

man/rustc.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ The test framework Rust provides executes tests in parallel. This variable sets
253253
the maximum number of threads used for this purpose.
254254

255255
.TP
256-
\fBRUST_TEST_NOCAPTURE\fR
257-
A synonym for the --nocapture flag.
256+
\fBRUST_TEST_NO_CAPTURE\fR
257+
A synonym for the --no-capture flag.
258258

259259
.TP
260260
\fBRUST_MIN_STACK\fR

src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
270270
logfile: config.logfile.clone(),
271271
run_tests: true,
272272
bench_benchmarks: true,
273-
nocapture: env::var("RUST_TEST_NOCAPTURE").is_ok(),
273+
no_capture: env::var("RUST_TEST_NO_CAPTURE").is_ok(),
274274
color: test::AutoColor,
275275
}
276276
}

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn load_props(testfile: &Path) -> TestProps {
131131
true
132132
});
133133

134-
for key in vec!["RUST_TEST_NOCAPTURE", "RUST_TEST_THREADS"] {
134+
for key in vec!["RUST_TEST_NO_CAPTURE", "RUST_TEST_THREADS"] {
135135
match env::var(key) {
136136
Ok(val) =>
137137
if exec_env.iter().find(|&&(ref x, _)| *x == key.to_string()).is_none() {

src/libtest/lib.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ pub struct TestOpts {
287287
pub run_tests: bool,
288288
pub bench_benchmarks: bool,
289289
pub logfile: Option<PathBuf>,
290-
pub nocapture: bool,
290+
pub no_capture: bool,
291291
pub color: ColorConfig,
292292
}
293293

@@ -300,7 +300,7 @@ impl TestOpts {
300300
run_tests: false,
301301
bench_benchmarks: false,
302302
logfile: None,
303-
nocapture: false,
303+
no_capture: false,
304304
color: AutoColor,
305305
}
306306
}
@@ -316,7 +316,7 @@ 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("", "nocapture", "don't capture stdout/stderr of each \
319+
getopts::optflag("", "no-capture", "don't capture stdout/stderr of each \
320320
task, allow printing directly"),
321321
getopts::optopt("", "color", "Configure coloring of output:
322322
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
335335
RUST_TEST_THREADS environment variable when running tests (set it to 1).
336336
337337
All tests have their standard output and standard error captured by default.
338-
This can be overridden with the --nocapture flag or the RUST_TEST_NOCAPTURE=1
338+
This can be overridden with the --no-capture flag or the RUST_TEST_NO_CAPTURE=1
339339
environment variable. Logging is not captured by default.
340340
341341
Test Attributes:
@@ -381,9 +381,9 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
381381
let run_tests = ! bench_benchmarks ||
382382
matches.opt_present("test");
383383

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

389389
let color = match matches.opt_str("color").as_ref().map(|s| &**s) {
@@ -402,7 +402,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
402402
run_tests: run_tests,
403403
bench_benchmarks: bench_benchmarks,
404404
logfile: logfile,
405-
nocapture: nocapture,
405+
no_capture: no_capture,
406406
color: color,
407407
};
408408

@@ -929,7 +929,7 @@ pub fn run_test(opts: &TestOpts,
929929

930930
fn run_test_inner(desc: TestDesc,
931931
monitor_ch: Sender<MonitorMsg>,
932-
nocapture: bool,
932+
no_capture: bool,
933933
testfn: Thunk<'static>) {
934934
struct Sink(Arc<Mutex<Vec<u8>>>);
935935
impl Write for Sink {
@@ -948,7 +948,7 @@ pub fn run_test(opts: &TestOpts,
948948
});
949949

950950
let result_guard = cfg.spawn(move || {
951-
if !nocapture {
951+
if !no_capture {
952952
io::set_print(box Sink(data2.clone()));
953953
io::set_panic(box Sink(data2));
954954
}
@@ -983,8 +983,8 @@ pub fn run_test(opts: &TestOpts,
983983
monitor_ch.send((desc, TrMetrics(mm), Vec::new())).unwrap();
984984
return;
985985
}
986-
DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture, f),
987-
StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.nocapture,
986+
DynTestFn(f) => run_test_inner(desc, monitor_ch, opts.no_capture, f),
987+
StaticTestFn(f) => run_test_inner(desc, monitor_ch, opts.no_capture,
988988
Box::new(move|| f()))
989989
}
990990
}

0 commit comments

Comments
 (0)