Skip to content

Commit 2ff10bf

Browse files
authored
Rollup merge of rust-lang#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...] ... ```
2 parents 41e7378 + 02fde86 commit 2ff10bf

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: test/src/cli.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ Test Attributes:
196196
pub fn parse_opts(args: &[String]) -> Option<OptRes> {
197197
// Parse matches.
198198
let opts = optgroups();
199+
let binary = args.get(0).map(|c| &**c).unwrap_or("...");
199200
let args = args.get(1..).unwrap_or(args);
200201
let matches = match opts.parse(args) {
201202
Ok(m) => m,
@@ -205,7 +206,7 @@ pub fn parse_opts(args: &[String]) -> Option<OptRes> {
205206
// Check if help was requested.
206207
if matches.opt_present("h") {
207208
// Show help and do nothing more.
208-
usage(&args[0], &opts);
209+
usage(binary, &opts);
209210
return None;
210211
}
211212

0 commit comments

Comments
 (0)