about summary refs log tree commit diff
path: root/src/libtest
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-05-05 22:44:07 +1000
committerHuon Wilson <dbau.pp+github@gmail.com>2014-05-15 23:04:09 +1000
commitb1ee3200b52a87ba788a6edf3b14db9466f2cb7d (patch)
tree497aff49c6226142b730220f84e0dd3e0192e461 /src/libtest
parent19f9181654ec71754c8528dd37075643d95947c4 (diff)
downloadrust-b1ee3200b52a87ba788a6edf3b14db9466f2cb7d.tar.gz
rust-b1ee3200b52a87ba788a6edf3b14db9466f2cb7d.zip
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.
Diffstat (limited to 'src/libtest')
-rw-r--r--src/libtest/lib.rs33
1 files changed, 12 insertions, 21 deletions
diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs
index 793657e7e88..3273e53ed8a 100644
--- a/src/libtest/lib.rs
+++ b/src/libtest/lib.rs
@@ -320,13 +320,11 @@ fn optgroups() -> Vec<getopts::OptGroup> {
                                          task, allow printing directly"))
 }
 
-fn usage(binary: &str, helpstr: &str) {
+fn usage(binary: &str) {
     let message = format!("Usage: {} [OPTIONS] [FILTER]", binary);
-    println!("{}", getopts::usage(message, optgroups().as_slice()));
-    println!("");
-    if helpstr == "help" {
-        println!("{}", "\
-The FILTER regex is matched against the name of all tests to run, and
+    println!(r"{usage}
+
+The FILTER regex is tested against the name of all tests to run, and
 only those tests that match are run.
 
 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.
 
 Test Attributes:
 
-    #[test]        - Indicates a function is a test to be run. This function
+    \#[test]        - Indicates a function is a test to be run. This function
                      takes no arguments.
-    #[bench]       - Indicates a function is a benchmark to be run. This
+    \#[bench]       - Indicates a function is a benchmark to be run. This
                      function takes one argument (test::Bencher).
-    #[should_fail] - This function (also labeled with #[test]) will only pass if
+    \#[should_fail] - This function (also labeled with \#[test]) will only pass if
                      the code causes a failure (an assertion failure or fail!)
-    #[ignore]      - When applied to a function which is already attributed as a
+    \#[ignore]      - When applied to a function which is already attributed as a
                      test, then the test runner will ignore these tests during
                      normal test runs. Running with --ignored will run these
-                     tests. This may also be written as #[ignore(cfg(...))] to
-                     ignore the test on certain configurations.");
-    }
+                     tests. This may also be written as \#[ignore(cfg(...))] to
+                     ignore the test on certain configurations.",
+             usage = getopts::usage(message, optgroups().as_slice()));
 }
 
 // Parses command line arguments into test options
@@ -365,14 +363,7 @@ pub fn parse_opts(args: &[StrBuf]) -> Option<OptRes> {
           Err(f) => return Some(Err(f.to_err_msg().to_strbuf()))
         };
 
-    if matches.opt_present("h") {
-        usage(args[0].as_slice(), "h");
-        return None;
-    }
-    if matches.opt_present("help") {
-        usage(args[0].as_slice(), "help");
-        return None;
-    }
+    if matches.opt_present("h") { usage(args[0].as_slice()); return None; }
 
     let filter = if matches.free.len() > 0 {
         let s = matches.free.get(0).as_slice();