about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-07-10 11:52:16 +0200
committerGitHub <noreply@github.com>2022-07-10 11:52:16 +0200
commit76f968dadc75feb5580217a83d382ddb9ea15a8f (patch)
tree80976dceb68244e536c1addb245d898caa41283b
parentca51d325e8656d8bba1811f7bea6b2d82d87fb1c (diff)
parented542df9bc798bbdfe4d18308b9a6528bebf0461 (diff)
Rollup merge of #99100 - Smittyvb:test-cli-binary-name, r=thomcc
Fix binary name in help message for test binaries

Currently the help output for a test binary uses the first argument instead of the binary name in the help output:

```
$ cargo test -- --help
...
Usage: --help [OPTIONS] [FILTERS...]
...
```

This fixes it to use the name of the binary (or `...` if there is no binary name passed on argv):

```
$ cargo test -- --help
...
Usage: /tmp/x/target/debug/deps/x-80c11a15ad4e1bf3 [OPTIONS] [FILTERS...]
...
```
-rw-r--r--library/test/src/cli.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/test/src/cli.rs b/library/test/src/cli.rs
index 000f5fa3f58..f981b9c4954 100644
--- a/library/test/src/cli.rs
+++ b/library/test/src/cli.rs
@@ -196,6 +196,7 @@ Test Attributes:
 pub fn parse_opts(args: &[String]) -> Option<OptRes> {
     // Parse matches.
     let opts = optgroups();
+    let binary = args.get(0).map(|c| &**c).unwrap_or("...");
     let args = args.get(1..).unwrap_or(args);
     let matches = match opts.parse(args) {
         Ok(m) => m,
@@ -205,7 +206,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
     // Check if help was requested.
     if matches.opt_present("h") {
         // Show help and do nothing more.
-        usage(&args[0], &opts);
+        usage(binary, &opts);
         return None;
     }