Skip to content

Commit

Permalink
Rollup merge of #99100 - Smittyvb:test-cli-binary-name, r=thomcc
Browse files Browse the repository at this point in the history
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...]
...
```
  • Loading branch information
matthiaskrgr authored Jul 10, 2022
2 parents ca51d32 + ed542df commit 76f968d
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/test/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}

Expand Down

0 comments on commit 76f968d

Please sign in to comment.