2020-01-18 12:10:07 +00:00
|
|
|
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
|
|
|
|
// Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
|
|
|
|
// Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
//
|
|
|
|
// This work was derived from Structopt (https://github.com/TeXitoi/structopt)
|
|
|
|
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
|
|
|
|
// MIT/Apache 2.0 license.
|
|
|
|
|
|
|
|
mod utils;
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
use clap::{Args, Parser, Subcommand};
|
2020-01-18 12:10:07 +00:00
|
|
|
use utils::*;
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-01-18 12:10:07 +00:00
|
|
|
enum Opt {
|
|
|
|
/// Fetch stuff from GitHub
|
|
|
|
Fetch {
|
|
|
|
#[clap(long)]
|
|
|
|
all: bool,
|
|
|
|
#[clap(short, long)]
|
|
|
|
/// Overwrite local branches.
|
|
|
|
force: bool,
|
|
|
|
repo: String,
|
|
|
|
},
|
|
|
|
|
|
|
|
Add {
|
|
|
|
#[clap(short, long)]
|
|
|
|
interactive: bool,
|
|
|
|
#[clap(short, long)]
|
|
|
|
verbose: bool,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fetch() {
|
|
|
|
assert_eq!(
|
|
|
|
Opt::Fetch {
|
|
|
|
all: true,
|
|
|
|
force: false,
|
|
|
|
repo: "origin".to_string()
|
|
|
|
},
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "fetch", "--all", "origin"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
Opt::Fetch {
|
|
|
|
all: false,
|
|
|
|
force: true,
|
|
|
|
repo: "origin".to_string()
|
|
|
|
},
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "fetch", "-f", "origin"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_add() {
|
|
|
|
assert_eq!(
|
|
|
|
Opt::Add {
|
|
|
|
interactive: false,
|
|
|
|
verbose: false
|
|
|
|
},
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "add"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
|
|
|
assert_eq!(
|
|
|
|
Opt::Add {
|
|
|
|
interactive: true,
|
|
|
|
verbose: true
|
|
|
|
},
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "add", "-i", "-v"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_no_parse() {
|
|
|
|
let result = Opt::try_parse_from(&["test", "badcmd", "-i", "-v"]);
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
|
|
|
let result = Opt::try_parse_from(&["test", "add", "--badoption"]);
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
|
|
|
let result = Opt::try_parse_from(&["test"]);
|
|
|
|
assert!(result.is_err());
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-01-18 12:10:07 +00:00
|
|
|
enum Opt2 {
|
|
|
|
DoSomething { arg: String },
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
/// This test is specifically to make sure that hyphenated subcommands get
|
|
|
|
/// processed correctly.
|
|
|
|
fn test_hyphenated_subcommands() {
|
|
|
|
assert_eq!(
|
|
|
|
Opt2::DoSomething {
|
|
|
|
arg: "blah".to_string()
|
|
|
|
},
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt2::try_parse_from(&["test", "do-something", "blah"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-01-18 12:10:07 +00:00
|
|
|
enum Opt3 {
|
|
|
|
Add,
|
|
|
|
Init,
|
|
|
|
Fetch,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_null_commands() {
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(Opt3::Add, Opt3::try_parse_from(&["test", "add"]).unwrap());
|
|
|
|
assert_eq!(Opt3::Init, Opt3::try_parse_from(&["test", "init"]).unwrap());
|
|
|
|
assert_eq!(
|
|
|
|
Opt3::Fetch,
|
|
|
|
Opt3::try_parse_from(&["test", "fetch"]).unwrap()
|
|
|
|
);
|
2020-01-18 12:10:07 +00:00
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-01-18 12:10:07 +00:00
|
|
|
#[clap(about = "Not shown")]
|
|
|
|
struct Add {
|
|
|
|
file: String,
|
|
|
|
}
|
|
|
|
/// Not shown
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-01-18 12:10:07 +00:00
|
|
|
struct Fetch {
|
|
|
|
remote: String,
|
|
|
|
}
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2020-01-18 12:10:07 +00:00
|
|
|
enum Opt4 {
|
|
|
|
// Not shown
|
|
|
|
/// Add a file
|
|
|
|
Add(Add),
|
|
|
|
Init,
|
|
|
|
/// download history from remote
|
|
|
|
Fetch(Fetch),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_tuple_commands() {
|
|
|
|
assert_eq!(
|
|
|
|
Opt4::Add(Add {
|
|
|
|
file: "f".to_string()
|
|
|
|
}),
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt4::try_parse_from(&["test", "add", "f"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(Opt4::Init, Opt4::try_parse_from(&["test", "init"]).unwrap());
|
2020-01-18 12:10:07 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt4::Fetch(Fetch {
|
|
|
|
remote: "origin".to_string()
|
|
|
|
}),
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt4::try_parse_from(&["test", "fetch", "origin"]).unwrap()
|
2020-01-18 12:10:07 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
let output = get_long_help::<Opt4>();
|
|
|
|
|
|
|
|
assert!(output.contains("download history from remote"));
|
|
|
|
assert!(output.contains("Add a file"));
|
|
|
|
assert!(!output.contains("Not shown"));
|
|
|
|
}
|
|
|
|
|
2020-04-30 17:20:21 +00:00
|
|
|
#[test]
|
2021-05-18 20:35:49 +00:00
|
|
|
fn global_passed_down() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2020-04-30 17:20:21 +00:00
|
|
|
struct Opt {
|
2020-07-19 20:31:59 +00:00
|
|
|
#[clap(global = true, long)]
|
2021-05-19 18:42:39 +00:00
|
|
|
other: bool,
|
2020-04-30 17:20:21 +00:00
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: Subcommands,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Debug, PartialEq, Subcommand)]
|
2020-04-30 17:20:21 +00:00
|
|
|
enum Subcommands {
|
2020-05-01 12:33:36 +00:00
|
|
|
Add,
|
2020-07-19 20:31:59 +00:00
|
|
|
Global(GlobalCmd),
|
2020-04-30 17:20:21 +00:00
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Debug, PartialEq, Args)]
|
2020-07-19 20:31:59 +00:00
|
|
|
struct GlobalCmd {
|
|
|
|
#[clap(from_global)]
|
2021-05-19 18:42:39 +00:00
|
|
|
other: bool,
|
2020-07-19 20:31:59 +00:00
|
|
|
}
|
|
|
|
|
2020-05-01 12:33:36 +00:00
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "global"]).unwrap(),
|
2020-05-01 12:33:36 +00:00
|
|
|
Opt {
|
2021-05-19 18:42:39 +00:00
|
|
|
other: false,
|
|
|
|
sub: Subcommands::Global(GlobalCmd { other: false })
|
2020-05-01 12:33:36 +00:00
|
|
|
}
|
|
|
|
);
|
2020-04-30 17:20:21 +00:00
|
|
|
|
2020-05-01 12:33:36 +00:00
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "global", "--other"]).unwrap(),
|
2020-05-01 12:33:36 +00:00
|
|
|
Opt {
|
2021-05-19 18:42:39 +00:00
|
|
|
other: true,
|
|
|
|
sub: Subcommands::Global(GlobalCmd { other: true })
|
2020-05-01 12:33:36 +00:00
|
|
|
}
|
|
|
|
);
|
2021-05-18 20:35:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_subcommand() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2021-05-18 20:35:49 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: Subcommands,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Debug, PartialEq, Subcommand)]
|
2021-05-18 20:35:49 +00:00
|
|
|
enum Subcommands {
|
|
|
|
Add,
|
|
|
|
Remove,
|
|
|
|
#[clap(external_subcommand)]
|
|
|
|
Other(Vec<String>),
|
|
|
|
}
|
2020-04-30 17:20:21 +00:00
|
|
|
|
2020-07-19 20:31:59 +00:00
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "add"]).unwrap(),
|
2020-07-19 20:31:59 +00:00
|
|
|
Opt {
|
2021-05-18 20:35:49 +00:00
|
|
|
sub: Subcommands::Add
|
2020-07-19 20:31:59 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "remove"]).unwrap(),
|
2020-07-19 20:31:59 +00:00
|
|
|
Opt {
|
2021-05-18 20:35:49 +00:00
|
|
|
sub: Subcommands::Remove
|
2020-07-19 20:31:59 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2020-04-30 17:20:21 +00:00
|
|
|
assert!(Opt::try_parse_from(&["test"]).is_err());
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "git", "status"]).unwrap(),
|
|
|
|
Opt {
|
|
|
|
sub: Subcommands::Other(vec!["git".into(), "status".into()])
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_subcommand_os_string() {
|
|
|
|
use std::ffi::OsString;
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2020-04-30 17:20:21 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: Subcommands,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Debug, PartialEq, Subcommand)]
|
2020-04-30 17:20:21 +00:00
|
|
|
enum Subcommands {
|
|
|
|
#[clap(external_subcommand)]
|
|
|
|
Other(Vec<OsString>),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "git", "status"]).unwrap(),
|
|
|
|
Opt {
|
|
|
|
sub: Subcommands::Other(vec!["git".into(), "status".into()])
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(Opt::try_parse_from(&["test"]).is_err());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn external_subcommand_optional() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2020-04-30 17:20:21 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: Option<Subcommands>,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Debug, PartialEq, Subcommand)]
|
2020-04-30 17:20:21 +00:00
|
|
|
enum Subcommands {
|
|
|
|
#[clap(external_subcommand)]
|
|
|
|
Other(Vec<String>),
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "git", "status"]).unwrap(),
|
|
|
|
Opt {
|
|
|
|
sub: Some(Subcommands::Other(vec!["git".into(), "status".into()]))
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(Opt::try_parse_from(&["test"]).unwrap(), Opt { sub: None });
|
|
|
|
}
|
|
|
|
|
2021-07-09 17:37:09 +00:00
|
|
|
#[test]
|
|
|
|
fn enum_in_enum_subsubcommand() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, Debug, PartialEq)]
|
2021-07-09 17:37:09 +00:00
|
|
|
pub enum Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
Daemon(DaemonCommand),
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Subcommand, Debug, PartialEq)]
|
2021-07-09 17:37:09 +00:00
|
|
|
pub enum DaemonCommand {
|
|
|
|
Start,
|
|
|
|
Stop,
|
|
|
|
}
|
|
|
|
|
|
|
|
let result = Opt::try_parse_from(&["test"]);
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
|
|
|
let result = Opt::try_parse_from(&["test", "daemon"]);
|
|
|
|
assert!(result.is_err());
|
|
|
|
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
let result = Opt::try_parse_from(&["test", "daemon", "start"]).unwrap();
|
2021-07-09 17:37:09 +00:00
|
|
|
assert_eq!(Opt::Daemon(DaemonCommand::Start), result);
|
|
|
|
}
|
2021-07-15 17:35:20 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn update_subcommands() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2021-07-15 17:35:20 +00:00
|
|
|
enum Opt {
|
|
|
|
Command1(Command1),
|
|
|
|
Command2(Command2),
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2021-07-15 17:35:20 +00:00
|
|
|
struct Command1 {
|
|
|
|
arg1: i32,
|
|
|
|
arg2: i32,
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2021-07-15 17:35:20 +00:00
|
|
|
struct Command2 {
|
|
|
|
arg2: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Full subcommand update
|
|
|
|
let mut opt = Opt::Command1(Command1 { arg1: 12, arg2: 14 });
|
|
|
|
opt.try_update_from(&["test", "command1", "42", "44"])
|
|
|
|
.unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "command1", "42", "44"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-07-15 17:35:20 +00:00
|
|
|
|
|
|
|
// Partial subcommand update
|
|
|
|
let mut opt = Opt::Command1(Command1 { arg1: 12, arg2: 14 });
|
|
|
|
opt.try_update_from(&["test", "command1", "42"]).unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "command1", "42", "14"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-07-15 17:35:20 +00:00
|
|
|
|
|
|
|
// Change subcommand
|
|
|
|
let mut opt = Opt::Command1(Command1 { arg1: 12, arg2: 14 });
|
|
|
|
opt.try_update_from(&["test", "command2", "43"]).unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "command2", "43"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-07-15 17:35:20 +00:00
|
|
|
}
|
2021-07-19 18:42:07 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn update_sub_subcommands() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2021-07-19 18:42:07 +00:00
|
|
|
enum Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
Child1(Child1),
|
|
|
|
#[clap(subcommand)]
|
|
|
|
Child2(Child2),
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Subcommand, PartialEq, Debug)]
|
2021-07-19 18:42:07 +00:00
|
|
|
enum Child1 {
|
|
|
|
Command1(Command1),
|
|
|
|
Command2(Command2),
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Subcommand, PartialEq, Debug)]
|
2021-07-19 18:42:07 +00:00
|
|
|
enum Child2 {
|
|
|
|
Command1(Command1),
|
|
|
|
Command2(Command2),
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Args, PartialEq, Debug)]
|
2021-07-19 18:42:07 +00:00
|
|
|
struct Command1 {
|
|
|
|
arg1: i32,
|
|
|
|
arg2: i32,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Args, PartialEq, Debug)]
|
2021-07-19 18:42:07 +00:00
|
|
|
struct Command2 {
|
|
|
|
arg2: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Full subcommand update
|
|
|
|
let mut opt = Opt::Child1(Child1::Command1(Command1 { arg1: 12, arg2: 14 }));
|
|
|
|
opt.try_update_from(&["test", "child1", "command1", "42", "44"])
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "child1", "command1", "42", "44"]).unwrap(),
|
2021-07-19 18:42:07 +00:00
|
|
|
opt
|
|
|
|
);
|
|
|
|
|
|
|
|
// Partial subcommand update
|
|
|
|
let mut opt = Opt::Child1(Child1::Command1(Command1 { arg1: 12, arg2: 14 }));
|
|
|
|
opt.try_update_from(&["test", "child1", "command1", "42"])
|
|
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "child1", "command1", "42", "14"]).unwrap(),
|
2021-07-19 18:42:07 +00:00
|
|
|
opt
|
|
|
|
);
|
|
|
|
|
|
|
|
// Partial subcommand update
|
|
|
|
let mut opt = Opt::Child1(Child1::Command1(Command1 { arg1: 12, arg2: 14 }));
|
|
|
|
opt.try_update_from(&["test", "child1", "command2", "43"])
|
|
|
|
.unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "child1", "command2", "43"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-07-19 18:42:07 +00:00
|
|
|
|
|
|
|
// Change subcommand
|
|
|
|
let mut opt = Opt::Child1(Child1::Command1(Command1 { arg1: 12, arg2: 14 }));
|
|
|
|
opt.try_update_from(&["test", "child2", "command2", "43"])
|
|
|
|
.unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "child2", "command2", "43"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-07-19 18:42:07 +00:00
|
|
|
}
|
2021-08-13 17:33:10 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn update_ext_subcommand() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2021-08-13 17:33:10 +00:00
|
|
|
enum Opt {
|
|
|
|
Command1(Command1),
|
|
|
|
Command2(Command2),
|
|
|
|
#[clap(external_subcommand)]
|
|
|
|
Ext(Vec<String>),
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Args, PartialEq, Debug)]
|
2021-08-13 17:33:10 +00:00
|
|
|
struct Command1 {
|
|
|
|
arg1: i32,
|
|
|
|
arg2: i32,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Args, PartialEq, Debug)]
|
2021-08-13 17:33:10 +00:00
|
|
|
struct Command2 {
|
|
|
|
arg2: i32,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Full subcommand update
|
|
|
|
let mut opt = Opt::Ext(vec!["12".into(), "14".into()]);
|
|
|
|
opt.try_update_from(&["test", "ext", "42", "44"]).unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "ext", "42", "44"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-08-13 17:33:10 +00:00
|
|
|
|
|
|
|
// No partial subcommand update
|
|
|
|
let mut opt = Opt::Ext(vec!["12".into(), "14".into()]);
|
|
|
|
opt.try_update_from(&["test", "ext", "42"]).unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(Opt::try_parse_from(&["test", "ext", "42"]).unwrap(), opt);
|
2021-08-13 17:33:10 +00:00
|
|
|
|
|
|
|
// Change subcommand
|
|
|
|
let mut opt = Opt::Ext(vec!["12".into(), "14".into()]);
|
|
|
|
opt.try_update_from(&["test", "command2", "43"]).unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "command2", "43"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-08-13 17:33:10 +00:00
|
|
|
|
|
|
|
let mut opt = Opt::Command1(Command1 { arg1: 12, arg2: 14 });
|
|
|
|
opt.try_update_from(&["test", "ext", "42", "44"]).unwrap();
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
assert_eq!(
|
|
|
|
Opt::try_parse_from(&["test", "ext", "42", "44"]).unwrap(),
|
|
|
|
opt
|
|
|
|
);
|
2021-08-13 17:33:10 +00:00
|
|
|
}
|
2021-09-03 16:00:22 +00:00
|
|
|
#[test]
|
|
|
|
fn subcommand_name_not_literal() {
|
|
|
|
fn get_name() -> &'static str {
|
|
|
|
"renamed"
|
|
|
|
}
|
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser, PartialEq, Debug)]
|
2021-09-03 16:00:22 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
subcmd: SubCmd,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Subcommand, PartialEq, Debug)]
|
2021-09-03 16:00:22 +00:00
|
|
|
enum SubCmd {
|
|
|
|
#[clap(name = get_name())]
|
|
|
|
SubCmd1,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert!(Opt::try_parse_from(&["test", "renamed"]).is_ok());
|
|
|
|
}
|
2021-10-06 18:52:02 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn skip_subcommand() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2021-10-06 18:52:02 +00:00
|
|
|
struct Opt {
|
|
|
|
#[clap(subcommand)]
|
|
|
|
sub: Subcommands,
|
|
|
|
}
|
|
|
|
|
2021-10-11 19:48:13 +00:00
|
|
|
#[derive(Debug, PartialEq, Subcommand)]
|
2021-10-06 18:52:02 +00:00
|
|
|
enum Subcommands {
|
|
|
|
Add,
|
|
|
|
Remove,
|
|
|
|
|
|
|
|
#[allow(dead_code)]
|
|
|
|
#[clap(skip)]
|
|
|
|
Skip,
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "add"]).unwrap(),
|
2021-10-06 18:52:02 +00:00
|
|
|
Opt {
|
|
|
|
sub: Subcommands::Add
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
assert_eq!(
|
test(derive): Provide better error info
`Parser::parse_from` will call `exit` on failure and we don't just lose
backtrace information but we don't even know which of the tests running
in parallel panicked. I ran into this when experimenting with
`clap_derive` and I couldn't tell what actually failed.
So let's switch to `Parse::try_parse_from`.
Errors went from:
```
test option_option ... ok
error: Found argument 'bar' which wasn't expected, or isn't valid in this context
USAGE:
clap_derive [OPTIONS]
For more information try --help
error: test failed, to rerun pass '--test arg_enum'
```
To:
```
test option_option ... ok
test variant_with_defined_casing ... ok
test skip_variant ... ok
test default_value ... ok
test vector ... FAILED
test option_vector ... ok
failures:
---- vector stdout ----
thread 'vector' panicked at 'called `Result::unwrap()` on an `Err` value: Error { message: Formatted(Colorizer { use_stderr: true, color_when: Auto
, pieces: [("error:", Some(Red)), (" ", None), ("Found argument '", None), ("bar", Some(Yellow)), ("' which wasn't expected, or isn't valid in this
context", None), ("\n\n", None), ("USAGE:\n clap_derive [OPTIONS]", None), ("\n\nFor more information try ", None), ("--help", Some(Green)), ("
\n", None)] }), kind: UnknownArgument, info: ["bar"], source: None, backtrace: Backtrace }', clap_derive/tests/arg_enum.rs:388:56
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
failures:
vector
test result: FAILED. 15 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s
error: test failed, to rerun pass '--test arg_enum'
```
2021-10-30 14:55:50 +00:00
|
|
|
Opt::try_parse_from(&["test", "remove"]).unwrap(),
|
2021-10-06 18:52:02 +00:00
|
|
|
Opt {
|
|
|
|
sub: Subcommands::Remove
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
let res = Opt::try_parse_from(&["test", "skip"]);
|
|
|
|
assert!(
|
|
|
|
matches!(
|
|
|
|
res,
|
|
|
|
Err(clap::Error {
|
|
|
|
kind: clap::ErrorKind::UnknownArgument,
|
|
|
|
..
|
|
|
|
})
|
|
|
|
),
|
|
|
|
"Unexpected result: {:?}",
|
|
|
|
res
|
|
|
|
);
|
|
|
|
}
|