aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2021-09-22 11:22:15 -0700
committerJoel Galenson <jgalenson@google.com>2021-09-22 11:22:15 -0700
commit3a84c421cd3018dfa0264eb5e43413aebdfa8a87 (patch)
tree67d12643bde23f5575ac43a9cfdcd606af977b83 /tests
parent236d4349c26f7f504a18a2966f33fcbe66144adf (diff)
downloadstructopt-3a84c421cd3018dfa0264eb5e43413aebdfa8a87.tar.gz
Upgrade rust/crates/structopt to 0.3.23
Test: make Change-Id: I4dba7f980033089367c7735fedcc21beee82e2b7
Diffstat (limited to 'tests')
-rw-r--r--tests/custom-string-parsers.rs6
-rw-r--r--tests/generics.rs118
-rw-r--r--tests/issues.rs29
-rw-r--r--tests/macro-errors.rs2
-rw-r--r--tests/non_literal_attributes.rs6
-rw-r--r--tests/special_types.rs2
-rw-r--r--tests/subcommands.rs46
-rw-r--r--tests/ui/non_existent_attr.stderr2
-rw-r--r--tests/ui/tuple_struct.stderr2
9 files changed, 152 insertions, 61 deletions
diff --git a/tests/custom-string-parsers.rs b/tests/custom-string-parsers.rs
index 89070ed..8fe055b 100644
--- a/tests/custom-string-parsers.rs
+++ b/tests/custom-string-parsers.rs
@@ -76,7 +76,11 @@ fn test_parse_hex() {
let err = HexOpt::clap()
.get_matches_from_safe(&["test", "-n", "gg"])
.unwrap_err();
- assert!(err.message.contains("invalid digit found in string"), err);
+ assert!(
+ err.message.contains("invalid digit found in string"),
+ "{}",
+ err
+ );
}
fn custom_parser_1(_: &str) -> &'static str {
diff --git a/tests/generics.rs b/tests/generics.rs
index 896f98a..0da349b 100644
--- a/tests/generics.rs
+++ b/tests/generics.rs
@@ -1,137 +1,145 @@
-
use structopt::StructOpt;
#[test]
fn generic_struct_flatten() {
-
- #[derive(StructOpt,PartialEq,Debug)]
- struct Inner{
- pub answer: isize
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Inner {
+ pub answer: isize,
}
- #[derive(StructOpt,PartialEq,Debug)]
- struct Outer<T:StructOpt>{
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Outer<T: StructOpt> {
#[structopt(flatten)]
- pub inner: T
+ pub inner: T,
}
assert_eq!(
- Outer{inner: Inner{ answer: 42 }},
- Outer::from_iter(&[ "--answer", "42" ])
+ Outer {
+ inner: Inner { answer: 42 }
+ },
+ Outer::from_iter(&["--answer", "42"])
)
}
#[test]
fn generic_struct_flatten_w_where_clause() {
-
- #[derive(StructOpt,PartialEq,Debug)]
- struct Inner{
- pub answer: isize
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Inner {
+ pub answer: isize,
}
- #[derive(StructOpt,PartialEq,Debug)]
- struct Outer<T> where T:StructOpt {
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Outer<T>
+ where
+ T: StructOpt,
+ {
#[structopt(flatten)]
- pub inner: T
+ pub inner: T,
}
assert_eq!(
- Outer{inner: Inner{ answer: 42 }},
- Outer::from_iter(&[ "--answer", "42" ])
+ Outer {
+ inner: Inner { answer: 42 }
+ },
+ Outer::from_iter(&["--answer", "42"])
)
}
#[test]
fn generic_enum() {
-
- #[derive(StructOpt,PartialEq,Debug)]
- struct Inner{
- pub answer: isize
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Inner {
+ pub answer: isize,
}
- #[derive(StructOpt,PartialEq,Debug)]
+ #[derive(StructOpt, PartialEq, Debug)]
enum GenericEnum<T: StructOpt> {
-
Start(T),
Stop,
}
assert_eq!(
- GenericEnum::Start(Inner{answer: 42}),
- GenericEnum::from_iter(&[ "test", "start", "42" ])
+ GenericEnum::Start(Inner { answer: 42 }),
+ GenericEnum::from_iter(&["test", "start", "42"])
)
-
}
#[test]
fn generic_enum_w_where_clause() {
-
- #[derive(StructOpt,PartialEq,Debug)]
- struct Inner{
- pub answer: isize
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Inner {
+ pub answer: isize,
}
- #[derive(StructOpt,PartialEq,Debug)]
- enum GenericEnum<T> where T: StructOpt {
-
+ #[derive(StructOpt, PartialEq, Debug)]
+ enum GenericEnum<T>
+ where
+ T: StructOpt,
+ {
Start(T),
Stop,
}
assert_eq!(
- GenericEnum::Start(Inner{answer: 42}),
- GenericEnum::from_iter(&[ "test", "start", "42" ])
+ GenericEnum::Start(Inner { answer: 42 }),
+ GenericEnum::from_iter(&["test", "start", "42"])
)
-
}
#[test]
fn generic_w_fromstr_trait_bound() {
-
use std::{fmt, str::FromStr};
- #[derive(StructOpt,PartialEq,Debug)]
- struct Opt<T> where T:FromStr, <T as FromStr>::Err: fmt::Debug + fmt::Display
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Opt<T>
+ where
+ T: FromStr,
+ <T as FromStr>::Err: fmt::Debug + fmt::Display,
{
- answer: T
+ answer: T,
}
assert_eq!(
- Opt::<isize>{answer:42},
- Opt::<isize>::from_iter([& "--answer", "42" ])
+ Opt::<isize> { answer: 42 },
+ Opt::<isize>::from_iter(&["--answer", "42"])
)
}
#[test]
fn generic_wo_trait_bound() {
-
use std::time::Duration;
- #[derive(StructOpt,PartialEq,Debug)]
+ #[derive(StructOpt, PartialEq, Debug)]
struct Opt<T> {
answer: isize,
#[structopt(skip)]
- took: Option<T>
+ took: Option<T>,
}
assert_eq!(
- Opt::<Duration>{answer:42,took:None},
- Opt::<Duration>::from_iter([& "--answer", "42" ])
+ Opt::<Duration> {
+ answer: 42,
+ took: None
+ },
+ Opt::<Duration>::from_iter(&["--answer", "42"])
)
}
#[test]
fn generic_where_clause_w_trailing_comma() {
-
use std::{fmt, str::FromStr};
- #[derive(StructOpt,PartialEq,Debug)]
- struct Opt<T> where T:FromStr, <T as FromStr>::Err: fmt::Debug + fmt::Display {
- pub answer: T
+ #[derive(StructOpt, PartialEq, Debug)]
+ struct Opt<T>
+ where
+ T: FromStr,
+ <T as FromStr>::Err: fmt::Debug + fmt::Display,
+ {
+ pub answer: T,
}
assert_eq!(
- Opt::<isize>{answer:42},
- Opt::<isize>::from_iter(&[ "--answer", "42" ])
+ Opt::<isize> { answer: 42 },
+ Opt::<isize>::from_iter(&["--answer", "42"])
)
}
diff --git a/tests/issues.rs b/tests/issues.rs
index 8b4ac4b..5860c49 100644
--- a/tests/issues.rs
+++ b/tests/issues.rs
@@ -115,3 +115,32 @@ fn issue_359() {
Opt::from_iter(&["test", "only_one_arg"])
);
}
+
+#[test]
+fn issue_490() {
+ use std::iter::FromIterator;
+ use std::str::FromStr;
+ use structopt::StructOpt;
+
+ struct U16ish;
+ impl FromStr for U16ish {
+ type Err = ();
+ fn from_str(_: &str) -> Result<Self, Self::Err> {
+ unimplemented!()
+ }
+ }
+ impl<'a> FromIterator<&'a U16ish> for Vec<u16> {
+ fn from_iter<T: IntoIterator<Item = &'a U16ish>>(_: T) -> Self {
+ unimplemented!()
+ }
+ }
+
+ #[derive(StructOpt, Debug)]
+ struct Opt {
+ opt_vec: Vec<u16>,
+ #[structopt(long)]
+ opt_opt_vec: Option<Vec<u16>>,
+ }
+
+ // Assert that it compiles
+}
diff --git a/tests/macro-errors.rs b/tests/macro-errors.rs
index 54b405a..74342f7 100644
--- a/tests/macro-errors.rs
+++ b/tests/macro-errors.rs
@@ -5,7 +5,7 @@
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
-#[rustversion::attr(any(not(stable), before(1.43)), ignore)]
+#[rustversion::attr(any(not(stable), before(1.54)), ignore)]
#[test]
fn ui() {
let t = trybuild::TestCases::new();
diff --git a/tests/non_literal_attributes.rs b/tests/non_literal_attributes.rs
index 75b6b71..4c3a442 100644
--- a/tests/non_literal_attributes.rs
+++ b/tests/non_literal_attributes.rs
@@ -143,5 +143,9 @@ fn test_parse_hex_function_path() {
let err = HexOpt::clap()
.get_matches_from_safe(&["test", "-n", "gg"])
.unwrap_err();
- assert!(err.message.contains("invalid digit found in string"), err);
+ assert!(
+ err.message.contains("invalid digit found in string"),
+ "{}",
+ err
+ );
}
diff --git a/tests/special_types.rs b/tests/special_types.rs
index ffed5e2..ac7d143 100644
--- a/tests/special_types.rs
+++ b/tests/special_types.rs
@@ -17,7 +17,7 @@ fn special_types_bool() {
Ok(self::bool(s.into()))
}
}
- };
+ }
#[derive(StructOpt, PartialEq, Debug)]
struct Opt {
diff --git a/tests/subcommands.rs b/tests/subcommands.rs
index 1fc8e76..4ee738b 100644
--- a/tests/subcommands.rs
+++ b/tests/subcommands.rs
@@ -301,3 +301,49 @@ fn external_subcommand_optional() {
assert_eq!(Opt::from_iter(&["test"]), Opt { sub: None });
}
+
+#[test]
+fn skip_subcommand() {
+ #[derive(Debug, PartialEq, StructOpt)]
+ struct Opt {
+ #[structopt(subcommand)]
+ sub: Subcommands,
+ }
+
+ #[derive(Debug, PartialEq, StructOpt)]
+ enum Subcommands {
+ Add,
+ Remove,
+
+ #[allow(dead_code)]
+ #[structopt(skip)]
+ Skip,
+ }
+
+ assert_eq!(
+ Opt::from_iter(&["test", "add"]),
+ Opt {
+ sub: Subcommands::Add
+ }
+ );
+
+ assert_eq!(
+ Opt::from_iter(&["test", "remove"]),
+ Opt {
+ sub: Subcommands::Remove
+ }
+ );
+
+ let res = Opt::from_iter_safe(&["test", "skip"]);
+ assert!(
+ matches!(
+ res,
+ Err(clap::Error {
+ kind: clap::ErrorKind::UnknownArgument,
+ ..
+ })
+ ),
+ "Unexpected result: {:?}",
+ res
+ );
+}
diff --git a/tests/ui/non_existent_attr.stderr b/tests/ui/non_existent_attr.stderr
index 61f784e..5765597 100644
--- a/tests/ui/non_existent_attr.stderr
+++ b/tests/ui/non_existent_attr.stderr
@@ -1,4 +1,4 @@
-error[E0599]: no method named `non_existing_attribute` found for struct `Arg<'_, '_>` in the current scope
+error[E0599]: no method named `non_existing_attribute` found for struct `Arg` in the current scope
--> $DIR/non_existent_attr.rs:14:24
|
14 | #[structopt(short, non_existing_attribute = 1)]
diff --git a/tests/ui/tuple_struct.stderr b/tests/ui/tuple_struct.stderr
index 31705c9..ad92385 100644
--- a/tests/ui/tuple_struct.stderr
+++ b/tests/ui/tuple_struct.stderr
@@ -4,4 +4,4 @@ error: structopt only supports non-tuple structs and enums
11 | #[derive(StructOpt, Debug)]
| ^^^^^^^^^
|
- = note: this error originates in a derive macro (in Nightly builds, run with -Z macro-backtrace for more info)
+ = note: this error originates in the derive macro `StructOpt` (in Nightly builds, run with -Z macro-backtrace for more info)