Skip to content

Commit b1ee320

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 19f9181 commit b1ee320

File tree

1 file changed

+12
-21
lines changed

1 file changed

+12
-21
lines changed

src/libtest/lib.rs

+12-21
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,11 @@ fn optgroups() -> Vec<getopts::OptGroup> {
320320
task, allow printing directly"))
321321
}
322322

323-
fn usage(binary: &str, helpstr: &str) {
323+
fn usage(binary: &str) {
324324
let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
325-
println!("{}", getopts::usage(message, optgroups().as_slice()));
326-
println!("");
327-
if helpstr == "help" {
328-
println!("{}", "\
329-
The FILTER regex is matched against the name of all tests to run, and
325+
println!(r"{usage}
326+
327+
The FILTER regex is tested against the name of all tests to run, and
330328
only those tests that match are run.
331329
332330
By default, all tests are run in parallel. This can be altered with the
@@ -338,18 +336,18 @@ environment variable. Logging is not captured by default.
338336
339337
Test Attributes:
340338
341-
#[test] - Indicates a function is a test to be run. This function
339+
\#[test] - Indicates a function is a test to be run. This function
342340
takes no arguments.
343-
#[bench] - Indicates a function is a benchmark to be run. This
341+
\#[bench] - Indicates a function is a benchmark to be run. This
344342
function takes one argument (test::Bencher).
345-
#[should_fail] - This function (also labeled with #[test]) will only pass if
343+
\#[should_fail] - This function (also labeled with \#[test]) will only pass if
346344
the code causes a failure (an assertion failure or fail!)
347-
#[ignore] - When applied to a function which is already attributed as a
345+
\#[ignore] - When applied to a function which is already attributed as a
348346
test, then the test runner will ignore these tests during
349347
normal test runs. Running with --ignored will run these
350-
tests. This may also be written as #[ignore(cfg(...))] to
351-
ignore the test on certain configurations.");
352-
}
348+
tests. This may also be written as \#[ignore(cfg(...))] to
349+
ignore the test on certain configurations.",
350+
usage = getopts::usage(message, optgroups().as_slice()));
353351
}
354352

355353
// Parses command line arguments into test options
@@ -365,14 +363,7 @@ pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
365363
Err(f) => return Some(Err(f.to_err_msg().to_strbuf()))
366364
};
367365

368-
if matches.opt_present("h") {
369-
usage(args[0].as_slice(), "h");
370-
return None;
371-
}
372-
if matches.opt_present("help") {
373-
usage(args[0].as_slice(), "help");
374-
return None;
375-
}
366+
if matches.opt_present("h") { usage(args[0].as_slice()); return None; }
376367

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

0 commit comments

Comments
 (0)