Skip to content

Commit 65268a4

Browse files
committed
test: ensure that the extended usage description gets printed.
Previously the longer hand-written usage string was never being printed: theoretically it was trying to detect when precisely `--help` was passed (but not `-h`), but the getopts framework was considering a check for the presence of `-h` to be a check for that of `--help` too, i.e. the code was always going through the `-h` path. This changes it to print the extended usage for both `-h` and `--help`, meaning that it does actually appear correctly.
1 parent e76ca4b commit 65268a4

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

src/libtest/lib.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,13 +312,11 @@ fn optgroups() -> Vec<getopts::OptGroup> {
312312
task, allow printing directly"))
313313
}
314314

315-
fn usage(binary: &str, helpstr: &str) {
315+
fn usage(binary: &str) {
316316
let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
317-
println!("{}", getopts::usage(message, optgroups().as_slice()));
318-
println!("");
319-
if helpstr == "help" {
320-
println!("{}", "\
321-
The FILTER regex is matched against the name of all tests to run, and
317+
println!(r"{usage}
318+
319+
The FILTER regex is tested against the name of all tests to run, and
322320
only those tests that match are run.
323321
324322
By default, all tests are run in parallel. This can be altered with the
@@ -330,18 +328,18 @@ environment variable. Logging is not captured by default.
330328
331329
Test Attributes:
332330
333-
#[test] - Indicates a function is a test to be run. This function
331+
\#[test] - Indicates a function is a test to be run. This function
334332
takes no arguments.
335-
#[bench] - Indicates a function is a benchmark to be run. This
333+
\#[bench] - Indicates a function is a benchmark to be run. This
336334
function takes one argument (test::Bencher).
337-
#[should_fail] - This function (also labeled with #[test]) will only pass if
335+
\#[should_fail] - This function (also labeled with \#[test]) will only pass if
338336
the code causes a failure (an assertion failure or fail!)
339-
#[ignore] - When applied to a function which is already attributed as a
337+
\#[ignore] - When applied to a function which is already attributed as a
340338
test, then the test runner will ignore these tests during
341339
normal test runs. Running with --ignored will run these
342-
tests. This may also be written as #[ignore(cfg(...))] to
343-
ignore the test on certain configurations.");
344-
}
340+
tests. This may also be written as \#[ignore(cfg(...))] to
341+
ignore the test on certain configurations.",
342+
usage = getopts::usage(message, optgroups().as_slice()));
345343
}
346344

347345
// Parses command line arguments into test options
@@ -353,8 +351,7 @@ pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
353351
Err(f) => return Some(Err(f.to_err_msg()))
354352
};
355353

356-
if matches.opt_present("h") { usage(args[0], "h"); return None; }
357-
if matches.opt_present("help") { usage(args[0], "help"); return None; }
354+
if matches.opt_present("h") { usage(args[0]); return None; }
358355

359356
let filter = if matches.free.len() > 0 {
360357
let s = matches.free.get(0).as_slice();

0 commit comments

Comments
 (0)