]> git.lizzy.rs Git - rust.git/commitdiff
test: ensure that the extended usage description gets printed.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 5 May 2014 12:44:07 +0000 (22:44 +1000)
committerHuon Wilson <dbau.pp+github@gmail.com>
Thu, 15 May 2014 13:04:09 +0000 (23:04 +1000)
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.

src/libtest/lib.rs

index 793657e7e886312e67f81dcf4b1eba555ad5c276..3273e53ed8a0bad0a14e26a5474e43f9cfc57593 100644 (file)
@@ -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 @@ fn usage(binary: &str, helpstr: &str) {
 
 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();