diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..0ea25e0 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,55 @@ +name: ci + +on: + push: + branches: + - master + + pull_request: + branches: + - master + + schedule: + - cron: 00 4 * * * + +jobs: + build: + strategy: + fail-fast: false + matrix: + rust: + # https://github.com/unicode-rs/unicode-width/commit/afab363383557c39942706c9441a5670e321b4a0 + # added a call to `wrapping_add_signed`, added in 1.66.0. + - 1.66.0 + - stable + - beta + - nightly + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + components: clippy,rustfmt + toolchain: ${{ matrix.rust }} + - uses: Swatinem/rust-cache@v2 + - uses: taiki-e/install-action@v2 + with: + tool: taplo-cli + - run: taplo fmt --check + - run: cargo fmt --all -- --check + # Only exercise none/all feature sets; else we'd run the builder out of disk space. + - run: cargo build + - run: cargo build --all-features + # See https://github.com/dtolnay/trybuild/commit/4fc90bf70f4744a250dfb8804479f88c188de41b. + # + # Cannot build tests below 1.70.0. + - run: cargo clippy --all-targets --workspace -- --deny warnings --allow dead_code # TODO: remove? + if: matrix.rust != '1.66.0' + - run: cargo clippy --all-targets --workspace --all-features -- --deny warnings --allow dead_code # TODO: remove? + if: matrix.rust != '1.66.0' + - run: cargo test --workspace --no-default-features + if: matrix.rust != '1.66.0' + - run: cargo test --workspace --all-features + if: matrix.rust != '1.66.0' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 7b4fcc9..0000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -if: type != push OR branch = master - -language: rust -matrix: - include: - - rust: stable - name: check if `cargo fmt --all` is applied - before_script: rustup component add rustfmt-preview - script: cargo fmt --all -- --check - - - language: node_js - node_js: node - name: check links - install: npm install -g markdown-link-check - script: - - markdown-link-check -c link-check-headers.json README.md - - markdown-link-check -c link-check-headers.json CHANGELOG.md - - markdown-link-check -c link-check-headers.json examples/README.md - - - rust: stable - name: clippy - before_script: rustup component add clippy - script: cargo clippy --all -- -D warnings - - - rust: 1.46.0 - - rust: stable - - rust: beta - - rust: nightly - -script: - - cargo test - -jobs: - allow_failures: - - name: clippy diff --git a/Cargo.toml b/Cargo.toml index fb77ef2..c64b1da 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,15 +17,12 @@ suggestions = ["clap/suggestions"] color = ["clap/color"] wrap_help = ["clap/wrap_help"] yaml = ["clap/yaml"] -lints = ["clap/lints"] +lints = [] debug = ["clap/debug"] no_cargo = ["clap/no_cargo"] doc = ["clap/doc"] paw = ["structopt-derive/paw", "paw_dep"] -[badges] -travis-ci = { repository = "TeXitoi/structopt" } - [dependencies] clap = { version = "2.33", default-features = false } structopt-derive = { path = "structopt-derive", version = "=0.4.18" } diff --git a/README.md b/README.md index 24068c5..27636e4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # StructOpt -[![Build status](https://travis-ci.com/TeXitoi/structopt.svg?branch=master)](https://app.travis-ci.com/github/TeXitoi/structopt) [![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt) [![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt) +[![Build status](../../actions/workflows/ci.yml/badge.svg)](../../actions) +[![](https://img.shields.io/crates/v/structopt.svg)](https://crates.io/crates/structopt) +[![](https://docs.rs/structopt/badge.svg)](https://docs.rs/structopt) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/) Parse command line arguments by defining a struct. It combines [clap](https://crates.io/crates/clap) with custom derive. @@ -15,7 +17,7 @@ See the [structopt -> clap migration guide](https://github.com/clap-rs/clap/blob ## Documentation -Find it on [Docs.rs](https://docs.rs/structopt). You can also check the [examples](https://github.com/TeXitoi/structopt/tree/master/examples) and the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md). +Find it on [Docs.rs](https://docs.rs/structopt). You can also check the [examples](examples) and the [changelog](CHANGELOG.md). ## Example @@ -139,7 +141,7 @@ Opt { ## StructOpt rustc version policy -- Minimum rustc version modification must be specified in the [changelog](https://github.com/TeXitoi/structopt/blob/master/CHANGELOG.md) and in the [travis configuration](https://github.com/TeXitoi/structopt/blob/master/.travis.yml). +- Minimum rustc version modification must be specified in the [changelog](CHANGELOG.md) and in the [CI configuration](.github/workflows/ci.yml). - Contributors can increment minimum rustc version without any justification if the new version is required by the latest version of one of StructOpt's dependencies (`cargo update` will not fail on StructOpt). - Contributors can increment minimum rustc version if the library user experience is improved. diff --git a/examples/enum_in_args_with_strum.rs b/examples/enum_in_args_with_strum.rs index 7893e78..58596a2 100644 --- a/examples/enum_in_args_with_strum.rs +++ b/examples/enum_in_args_with_strum.rs @@ -1,14 +1,14 @@ //! Running this example with --help prints this message: //! ----------------------------------------------------- //! structopt 0.3.25 -//! +//! //! USAGE: //! enum_in_args_with_strum [OPTIONS] -//! +//! //! FLAGS: //! -h, --help Prints help information //! -V, --version Prints version information -//! +//! //! OPTIONS: //! --format [default: txt] [possible values: txt, md, html] //! ----------------------------------------------------- diff --git a/examples/skip.rs b/examples/skip.rs index 1f44769..64f308a 100644 --- a/examples/skip.rs +++ b/examples/skip.rs @@ -19,18 +19,13 @@ pub struct Opt { s: String, } -#[derive(Debug, PartialEq)] +#[derive(Debug, Default, PartialEq)] enum Kind { A, + #[default] B, } -impl Default for Kind { - fn default() -> Self { - return Kind::B; - } -} - fn main() { assert_eq!( Opt::from_iter(&["test", "-n", "10"]), diff --git a/src/lib.rs b/src/lib.rs index 92d93ab..c3efada 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1089,6 +1089,7 @@ //! use std::{fmt, str::FromStr}; //! //! // a struct with single custom argument +//! #[cfg(not(feature = "paw"))] //! #[derive(StructOpt)] //! struct GenericArgs where ::Err: fmt::Display + fmt::Debug { //! generic_arg_1: String, @@ -1101,7 +1102,9 @@ //! //! ``` //! # use structopt::StructOpt; +//! //! // a struct with multiple custom arguments in a substructure +//! #[cfg(not(feature = "paw"))] //! #[derive(StructOpt)] //! struct GenericArgs { //! generic_arg_1: String, @@ -1202,7 +1205,7 @@ pub trait StructOptInternal: StructOpt { false } - fn from_subcommand<'a, 'b>(_sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option + fn from_subcommand<'a>(_sub: (&'a str, Option<&'a clap::ArgMatches<'_>>)) -> Option where Self: std::marker::Sized, { @@ -1227,7 +1230,7 @@ impl StructOptInternal for Box { } #[doc(hidden)] - fn from_subcommand<'a, 'b>(sub: (&'b str, Option<&'b clap::ArgMatches<'a>>)) -> Option { + fn from_subcommand<'a>(sub: (&'a str, Option<&'a clap::ArgMatches<'_>>)) -> Option { ::from_subcommand(sub).map(Box::new) } diff --git a/structopt-derive/Cargo.toml b/structopt-derive/Cargo.toml index 43628e0..904e6aa 100644 --- a/structopt-derive/Cargo.toml +++ b/structopt-derive/Cargo.toml @@ -10,11 +10,8 @@ keywords = ["clap", "cli", "derive", "docopt"] categories = ["command-line-interface"] license = "Apache-2.0/MIT" -[badges] -travis-ci = { repository = "TeXitoi/structopt" } - [dependencies] -syn = { version = "1", features = ["full"] } +syn = { version = "2", features = ["full"] } quote = "1" proc-macro2 = "1" heck = "0.4.0" diff --git a/structopt-derive/src/attrs.rs b/structopt-derive/src/attrs.rs index 95ed4a5..a894c87 100644 --- a/structopt-derive/src/attrs.rs +++ b/structopt-derive/src/attrs.rs @@ -16,7 +16,8 @@ use proc_macro2::{Span, TokenStream}; use proc_macro_error::abort; use quote::{quote, quote_spanned, ToTokens}; use syn::{ - self, ext::IdentExt, spanned::Spanned, Attribute, Expr, Ident, LitStr, MetaNameValue, Type, + self, ext::IdentExt, spanned::Spanned, Attribute, Expr, ExprLit, Ident, LitStr, MetaNameValue, + Type, }; #[derive(Clone)] @@ -382,14 +383,18 @@ impl Attrs { let comment_parts: Vec<_> = attrs .iter() - .filter(|attr| attr.path.is_ident("doc")) + .filter(|attr| attr.path().is_ident("doc")) .filter_map(|attr| { - if let Ok(NameValue(MetaNameValue { lit: Str(s), .. })) = attr.parse_meta() { - Some(s.value()) - } else { - // non #[doc = "..."] attributes are not our concern - // we leave them for rustc to handle - None + match &attr.meta { + NameValue(MetaNameValue { + value: Expr::Lit(ExprLit { lit: Str(s), .. }), + .. + }) => Some(s.value()), + _ => { + // non #[doc = "..."] attributes are not our concern + // we leave them for rustc to handle + None + } } }) .collect(); diff --git a/structopt-derive/src/doc_comments.rs b/structopt-derive/src/doc_comments.rs index 5592a1a..06e1b14 100644 --- a/structopt-derive/src/doc_comments.rs +++ b/structopt-derive/src/doc_comments.rs @@ -74,7 +74,7 @@ fn split_paragraphs(lines: &[&str]) -> Vec { let len = slice .iter() .position(|s| is_blank(s)) - .unwrap_or_else(|| slice.len()); + .unwrap_or(slice.len()); last_line += start + len; diff --git a/structopt-derive/src/lib.rs b/structopt-derive/src/lib.rs index 0838f50..9be2937 100644 --- a/structopt-derive/src/lib.rs +++ b/structopt-derive/src/lib.rs @@ -697,7 +697,7 @@ fn gen_from_subcommand( let sub_name = attrs.cased_name(); let variant_name = &variant.ident; let constructor_block = match variant.fields { - Named(ref fields) => gen_constructor(&fields.named, &attrs), + Named(ref fields) => gen_constructor(&fields.named, attrs), Unit => quote!(), Unnamed(ref fields) if fields.unnamed.len() == 1 => { let ty = &fields.unnamed[0]; @@ -776,13 +776,13 @@ fn gen_paw_impl(_: &ImplGenerics, _: &Ident, _: &TypeGenerics, _: &TokenStream) fn split_structopt_generics_for_impl( generics: &Generics, ) -> (ImplGenerics, TypeGenerics, TokenStream) { - use syn::{token::Add, TypeParamBound::Trait}; + use syn::{token::Plus, TypeParamBound::Trait}; fn path_ends_with(path: &Path, ident: &str) -> bool { path.segments.last().unwrap().ident == ident } - fn type_param_bounds_contains(bounds: &Punctuated, ident: &str) -> bool { + fn type_param_bounds_contains(bounds: &Punctuated, ident: &str) -> bool { for bound in bounds { if let Trait(bound) = bound { if path_ends_with(&bound.path, ident) { @@ -790,7 +790,7 @@ fn split_structopt_generics_for_impl( } } } - return false; + false } struct TraitBoundAmendments { @@ -874,7 +874,7 @@ fn impl_structopt_for_struct( attrs: &[Attribute], generics: &Generics, ) -> TokenStream { - let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(&generics); + let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(generics); let basic_clap_app_gen = gen_clap_struct(attrs); let augment_clap = gen_augment_clap(fields, &basic_clap_app_gen.attrs); @@ -931,7 +931,7 @@ fn impl_structopt_for_enum( attrs: &[Attribute], generics: &Generics, ) -> TokenStream { - let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(&generics); + let (impl_generics, ty_generics, where_clause) = split_structopt_generics_for_impl(generics); let basic_clap_app_gen = gen_clap_enum(attrs); let clap_tokens = basic_clap_app_gen.tokens; diff --git a/structopt-derive/src/parse.rs b/structopt-derive/src/parse.rs index 11511a1..2bfb609 100644 --- a/structopt-derive/src/parse.rs +++ b/structopt-derive/src/parse.rs @@ -1,6 +1,6 @@ use std::iter::FromIterator; -use proc_macro_error::{abort, ResultExt}; +use proc_macro_error::abort; use quote::ToTokens; use syn::{ self, parenthesized, @@ -53,7 +53,7 @@ impl Parse for StructOptAttr { if input.peek(Token![=]) { // `name = value` attributes. - let assign_token = input.parse::()?; // skip '=' + let _assign_token = input.parse::()?; // skip '=' if input.peek(LitStr) { let lit: LitStr = input.parse()?; @@ -102,19 +102,11 @@ impl Parse for StructOptAttr { _ => Ok(NameLitStr(name, lit)), } } else { - match input.parse::() { - Ok(expr) => { - if name_str == "skip" { - Ok(Skip(name, Some(expr))) - } else { - Ok(NameExpr(name, expr)) - } - } - - Err(_) => abort! { - assign_token, - "expected `string literal` or `expression` after `=`" - }, + let expr = input.parse::()?; + if name_str == "skip" { + Ok(Skip(name, Some(expr))) + } else { + Ok(NameExpr(name, expr)) } } } else if input.peek(syn::token::Paren) { @@ -125,7 +117,7 @@ impl Parse for StructOptAttr { match name_str.as_ref() { "parse" => { let parser_specs: Punctuated = - nested.parse_terminated(ParserSpec::parse)?; + Punctuated::parse_terminated_with(&nested, ParserSpec::parse)?; if parser_specs.len() == 1 { Ok(Parse(name, parser_specs[0].clone())) @@ -157,7 +149,7 @@ impl Parse for StructOptAttr { _ => { let method_args: Punctuated<_, Token![,]> = - nested.parse_terminated(Expr::parse)?; + Punctuated::parse_terminated_with(&nested, Expr::parse)?; Ok(MethodCall(name, Vec::from_iter(method_args))) } } @@ -174,8 +166,8 @@ impl Parse for StructOptAttr { "verbatim_doc_comment" => Ok(VerbatimDocComment(name)), "default_value" => Ok(DefaultValue(name, None)), - "about" => (Ok(About(name, None))), - "author" => (Ok(Author(name, None))), + "about" => Ok(About(name, None)), + "author" => Ok(Author(name, None)), "skip" => Ok(Skip(name, None)), @@ -263,10 +255,14 @@ fn raw_method_suggestion(ts: ParseBuffer) -> String { pub fn parse_structopt_attributes(all_attrs: &[Attribute]) -> Vec { all_attrs .iter() - .filter(|attr| attr.path.is_ident("structopt")) + .filter(|attr| attr.path().is_ident("structopt")) .flat_map(|attr| { - attr.parse_args_with(Punctuated::::parse_terminated) - .unwrap_or_abort() + match attr.parse_args_with(Punctuated::::parse_terminated) { + Ok(attrs) => attrs, + Err(err) => { + abort!(err.span(), err) + } + } }) .collect() } diff --git a/tests/argument_naming.rs b/tests/argument_naming.rs index 88b549d..78bfb69 100644 --- a/tests/argument_naming.rs +++ b/tests/argument_naming.rs @@ -9,7 +9,7 @@ fn test_single_word_enum_variant_is_default_renamed_into_kebab_case() { assert_eq!( Opt::Command { foo: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "command", "0"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "command", "0"])) ); } @@ -22,7 +22,7 @@ fn test_multi_word_enum_variant_is_renamed() { assert_eq!( Opt::FirstCommand { foo: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "first-command", "0"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "first-command", "0"])) ); } @@ -37,7 +37,7 @@ fn test_standalone_long_generates_kebab_case() { assert_eq!( Opt { FOO_OPTION: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo-option"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--foo-option"])) ); } @@ -51,7 +51,7 @@ fn test_custom_long_overwrites_default_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--foo"])) ); } @@ -65,7 +65,7 @@ fn test_standalone_long_uses_previous_defined_custom_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--foo"])) ); } @@ -79,7 +79,7 @@ fn test_standalone_long_ignores_afterwards_defined_custom_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo-option"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--foo-option"])) ); } @@ -94,7 +94,7 @@ fn test_standalone_short_generates_kebab_case() { assert_eq!( Opt { FOO_OPTION: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-f"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-f"])) ); } @@ -108,7 +108,7 @@ fn test_custom_short_overwrites_default_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-o"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-o"])) ); } @@ -122,7 +122,7 @@ fn test_standalone_short_uses_previous_defined_custom_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-o"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-o"])) ); } @@ -136,7 +136,7 @@ fn test_standalone_short_ignores_afterwards_defined_custom_name() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-f"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-f"])) ); } @@ -150,7 +150,7 @@ fn test_standalone_long_uses_previous_defined_casing() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--FOO_OPTION"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--FOO_OPTION"])) ); } @@ -164,7 +164,7 @@ fn test_standalone_short_uses_previous_defined_casing() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-F"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-F"])) ); } @@ -179,7 +179,7 @@ fn test_standalone_long_works_with_verbatim_casing() { assert_eq!( Opt { _fOO_oPtiON: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--_fOO_oPtiON"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--_fOO_oPtiON"])) ); } @@ -193,7 +193,7 @@ fn test_standalone_short_works_with_verbatim_casing() { assert_eq!( Opt { _foo: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-_"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-_"])) ); } @@ -208,7 +208,7 @@ fn test_rename_all_is_propagated_from_struct_to_fields() { assert_eq!( Opt { foo: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--FOO"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--FOO"])) ); } @@ -231,7 +231,7 @@ fn test_rename_all_is_not_propagated_from_struct_into_flattened() { Opt { foo: Foo { foo: true } }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foo"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--foo"])) ); } @@ -256,7 +256,7 @@ fn test_rename_all_is_not_propagated_from_struct_into_subcommand() { Opt { foo: Foo::Command { foo: true } }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "command", "--foo"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "command", "--foo"])) ); } @@ -274,12 +274,12 @@ fn test_rename_all_is_propagated_from_enum_to_variants_and_their_fields() { assert_eq!( Opt::FirstVariant, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "FIRST_VARIANT"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "FIRST_VARIANT"])) ); assert_eq!( Opt::SecondVariant { foo: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "SECOND_VARIANT", "--FOO"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "SECOND_VARIANT", "--FOO"])) ); } @@ -301,12 +301,12 @@ fn test_rename_all_is_propagation_can_be_overridden() { assert_eq!( Opt::FirstVariant { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "first-variant", "--foo-option"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "first-variant", "--foo-option"])) ); assert_eq!( Opt::SecondVariant { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "SECOND_VARIANT", "--foo-option"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "SECOND_VARIANT", "--foo-option"])) ); } @@ -320,7 +320,7 @@ fn test_lower_is_renamed() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--foooption"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--foooption"])) ); } @@ -334,6 +334,6 @@ fn test_upper_is_renamed() { assert_eq!( Opt { foo_option: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--FOOOPTION"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--FOOOPTION"])) ); } diff --git a/tests/arguments.rs b/tests/arguments.rs index 96a0938..0742516 100644 --- a/tests/arguments.rs +++ b/tests/arguments.rs @@ -16,9 +16,9 @@ fn required_argument() { arg: i32, } assert_eq!(Opt { arg: 42 }, Opt::from_iter(&["test", "42"])); - assert!(Opt::clap().get_matches_from_safe(&["test"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test"]).is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "42", "24"]) + .get_matches_from_safe(["test", "42", "24"]) .is_err()); } @@ -31,7 +31,7 @@ fn optional_argument() { assert_eq!(Opt { arg: Some(42) }, Opt::from_iter(&["test", "42"])); assert_eq!(Opt { arg: None }, Opt::from_iter(&["test"])); assert!(Opt::clap() - .get_matches_from_safe(&["test", "42", "24"]) + .get_matches_from_safe(["test", "42", "24"]) .is_err()); } @@ -45,7 +45,7 @@ fn argument_with_default() { assert_eq!(Opt { arg: 24 }, Opt::from_iter(&["test", "24"])); assert_eq!(Opt { arg: 42 }, Opt::from_iter(&["test"])); assert!(Opt::clap() - .get_matches_from_safe(&["test", "42", "24"]) + .get_matches_from_safe(["test", "42", "24"]) .is_err()); } diff --git a/tests/custom-string-parsers.rs b/tests/custom-string-parsers.rs index 8fe055b..07f123a 100644 --- a/tests/custom-string-parsers.rs +++ b/tests/custom-string-parsers.rs @@ -44,7 +44,7 @@ fn test_path_opt_simple() { option_path_1: None, option_path_2: Some(PathBuf::from("j.zip")), }, - PathOpt::from_clap(&PathOpt::clap().get_matches_from(&[ + PathOpt::from_clap(&PathOpt::clap().get_matches_from([ "test", "-p", "/usr/bin", "-v", "/a/b/c", "-v", "/d/e/f", "-v", "/g/h/i", "-q", "j.zip", ])) @@ -66,15 +66,15 @@ struct HexOpt { fn test_parse_hex() { assert_eq!( HexOpt { number: 5 }, - HexOpt::from_clap(&HexOpt::clap().get_matches_from(&["test", "-n", "5"])) + HexOpt::from_clap(&HexOpt::clap().get_matches_from(["test", "-n", "5"])) ); assert_eq!( HexOpt { number: 0xabcdef }, - HexOpt::from_clap(&HexOpt::clap().get_matches_from(&["test", "-n", "abcdef"])) + HexOpt::from_clap(&HexOpt::clap().get_matches_from(["test", "-n", "abcdef"])) ); let err = HexOpt::clap() - .get_matches_from_safe(&["test", "-n", "gg"]) + .get_matches_from_safe(["test", "-n", "gg"]) .unwrap_err(); assert!( err.message.contains("invalid digit found in string"), @@ -118,7 +118,7 @@ fn test_every_custom_parser() { d: "D" }, NoOpOpt::from_clap( - &NoOpOpt::clap().get_matches_from(&["test", "-a=?", "-b=?", "-c=?", "-d=?"]) + &NoOpOpt::clap().get_matches_from(["test", "-a=?", "-b=?", "-c=?", "-d=?"]) ) ); } @@ -147,7 +147,7 @@ fn test_parser_with_default_value() { integer: 9000, path: PathBuf::from("src/lib.rs"), }, - DefaultedOpt::from_clap(&DefaultedOpt::clap().get_matches_from(&[ + DefaultedOpt::from_clap(&DefaultedOpt::clap().get_matches_from([ "test", "-b", "E²=p²c²+m²c⁴", @@ -194,7 +194,7 @@ fn test_parser_occurrences() { little_unsigned: 4, custom: Foo(5), }, - Occurrences::from_clap(&Occurrences::clap().get_matches_from(&[ + Occurrences::from_clap(&Occurrences::clap().get_matches_from([ "test", "-s", "--signed", "--signed", "-l", "-rrrr", "-cccc", "--custom", ])) ); @@ -225,10 +225,10 @@ fn test_custom_bool() { bitset: Vec, } - assert!(Opt::clap().get_matches_from_safe(&["test"]).is_err()); - assert!(Opt::clap().get_matches_from_safe(&["test", "-d"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test", "-d"]).is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-dfoo"]) + .get_matches_from_safe(["test", "-dfoo"]) .is_err()); assert_eq!( Opt { @@ -302,9 +302,9 @@ fn test_cstring() { #[structopt(parse(try_from_str = CString::new))] c_string: CString, } - assert!(Opt::clap().get_matches_from_safe(&["test"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test"]).is_err()); assert_eq!(Opt::from_iter(&["test", "bla"]).c_string.to_bytes(), b"bla"); assert!(Opt::clap() - .get_matches_from_safe(&["test", "bla\0bla"]) + .get_matches_from_safe(["test", "bla\0bla"]) .is_err()); } diff --git a/tests/flags.rs b/tests/flags.rs index 39a5dc3..11d70a9 100644 --- a/tests/flags.rs +++ b/tests/flags.rs @@ -18,25 +18,25 @@ fn unique_flag() { assert_eq!( Opt { alice: false }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert_eq!( Opt { alice: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])) ); assert_eq!( Opt { alice: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--alice"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--alice"])) ); - assert!(Opt::clap().get_matches_from_safe(&["test", "-i"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test", "-i"]).is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a", "foo"]) + .get_matches_from_safe(["test", "-a", "foo"]) .is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a", "-a"]) + .get_matches_from_safe(["test", "-a", "-a"]) .is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a", "--alice"]) + .get_matches_from_safe(["test", "-a", "--alice"]) .is_err()); } @@ -52,27 +52,27 @@ fn multiple_flag() { assert_eq!( Opt { alice: 0, bob: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert_eq!( Opt { alice: 1, bob: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])) ); assert_eq!( Opt { alice: 2, bob: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "-a"])) ); assert_eq!( Opt { alice: 2, bob: 2 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "--alice", "-bb"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "--alice", "-bb"])) ); assert_eq!( Opt { alice: 3, bob: 1 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-aaa", "--bob"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-aaa", "--bob"])) ); - assert!(Opt::clap().get_matches_from_safe(&["test", "-i"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test", "-i"]).is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a", "foo"]) + .get_matches_from_safe(["test", "-a", "foo"]) .is_err()); } @@ -90,19 +90,19 @@ fn non_bool_flags() { bob: std::sync::atomic::AtomicBool, } - let falsey = Opt::from_clap(&Opt::clap().get_matches_from(&["test"])); + let falsey = Opt::from_clap(&Opt::clap().get_matches_from(["test"])); assert!(!falsey.alice.load(std::sync::atomic::Ordering::Relaxed)); assert!(!falsey.bob.load(std::sync::atomic::Ordering::Relaxed)); - let alice = Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])); + let alice = Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])); assert!(alice.alice.load(std::sync::atomic::Ordering::Relaxed)); assert!(!alice.bob.load(std::sync::atomic::Ordering::Relaxed)); - let bob = Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-b"])); + let bob = Opt::from_clap(&Opt::clap().get_matches_from(["test", "-b"])); assert!(!bob.alice.load(std::sync::atomic::Ordering::Relaxed)); assert!(bob.bob.load(std::sync::atomic::Ordering::Relaxed)); - let both = Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-b", "-a"])); + let both = Opt::from_clap(&Opt::clap().get_matches_from(["test", "-b", "-a"])); assert!(both.alice.load(std::sync::atomic::Ordering::Relaxed)); assert!(both.bob.load(std::sync::atomic::Ordering::Relaxed)); } @@ -122,41 +122,41 @@ fn combined_flags() { alice: false, bob: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert_eq!( Opt { alice: true, bob: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])) ); assert_eq!( Opt { alice: true, bob: 0 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])) ); assert_eq!( Opt { alice: false, bob: 1 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-b"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-b"])) ); assert_eq!( Opt { alice: true, bob: 1 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--alice", "--bob"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--alice", "--bob"])) ); assert_eq!( Opt { alice: true, bob: 4 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-bb", "-a", "-bb"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-bb", "-a", "-bb"])) ); } diff --git a/tests/flatten.rs b/tests/flatten.rs index 05de185..d1e4c8c 100644 --- a/tests/flatten.rs +++ b/tests/flatten.rs @@ -28,14 +28,18 @@ fn flatten() { }, Opt::from_iter(&["test", "42"]) ); - assert!(Opt::clap().get_matches_from_safe(&["test"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test"]).is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "42", "24"]) + .get_matches_from_safe(["test", "42", "24"]) .is_err()); } #[test] -#[should_panic] +#[cfg_attr( + not(debug_assertions), + ignore = "only panics in debug mode, else calls std::process::exit" +)] +#[should_panic = "Non-unique argument name: arg is already in use"] fn flatten_twice() { #[derive(StructOpt, PartialEq, Debug)] struct Common { diff --git a/tests/generics.rs b/tests/generics.rs index 0da349b..4101fc9 100644 --- a/tests/generics.rs +++ b/tests/generics.rs @@ -1,3 +1,22 @@ +// Produces compiler errors in the presence of paw, e.g.: +// +// error[E0107]: missing generics for struct `generic_struct_flatten::Outer` +// --> tests/generics.rs:11:12 +// | +// 11 | struct Outer { +// | ^^^^^ expected 1 generic argument +// | +// note: struct defined here, with 1 generic parameter: `T` +// --> tests/generics.rs:11:12 +// | +// 11 | struct Outer { +// | ^^^^^ - +// help: add missing generic argument +// | +// 11 | struct Outer { +// | +++ +#![cfg(not(feature = "paw"))] + use structopt::StructOpt; #[test] diff --git a/tests/issues.rs b/tests/issues.rs index 3f9e1af..ae26e12 100644 --- a/tests/issues.rs +++ b/tests/issues.rs @@ -24,18 +24,14 @@ fn issue_151() { a: Opt, } - assert!(Cli::clap().get_matches_from_safe(&["test"]).is_err()); + assert!(Cli::clap().get_matches_from_safe(["test"]).is_err()); + assert!(Cli::clap().get_matches_from_safe(["test", "--foo"]).is_ok()); + assert!(Cli::clap().get_matches_from_safe(["test", "--bar"]).is_ok()); assert!(Cli::clap() - .get_matches_from_safe(&["test", "--foo"]) - .is_ok()); - assert!(Cli::clap() - .get_matches_from_safe(&["test", "--bar"]) - .is_ok()); - assert!(Cli::clap() - .get_matches_from_safe(&["test", "--zebra"]) + .get_matches_from_safe(["test", "--zebra"]) .is_err()); assert!(Cli::clap() - .get_matches_from_safe(&["test", "--foo", "--bar"]) + .get_matches_from_safe(["test", "--foo", "--bar"]) .is_ok()); } @@ -57,16 +53,16 @@ fn issue_289() { } assert!(Args::clap() - .get_matches_from_safe(&["test", "some-command", "test-command"]) + .get_matches_from_safe(["test", "some-command", "test-command"]) .is_ok()); assert!(Args::clap() - .get_matches_from_safe(&["test", "some", "test-command"]) + .get_matches_from_safe(["test", "some", "test-command"]) .is_ok()); assert!(Args::clap() - .get_matches_from_safe(&["test", "some-command", "test"]) + .get_matches_from_safe(["test", "some-command", "test"]) .is_ok()); assert!(Args::clap() - .get_matches_from_safe(&["test", "some", "test"]) + .get_matches_from_safe(["test", "some", "test"]) .is_ok()); } diff --git a/tests/nested-subcommands.rs b/tests/nested-subcommands.rs index 1fbd166..da1ca13 100644 --- a/tests/nested-subcommands.rs +++ b/tests/nested-subcommands.rs @@ -36,7 +36,7 @@ struct Opt2 { #[test] fn test_no_cmd() { - let result = Opt::clap().get_matches_from_safe(&["test"]); + let result = Opt::clap().get_matches_from_safe(["test"]); assert!(result.is_err()); assert_eq!( @@ -45,7 +45,7 @@ fn test_no_cmd() { verbose: 0, cmd: None }, - Opt2::from_clap(&Opt2::clap().get_matches_from(&["test"])) + Opt2::from_clap(&Opt2::clap().get_matches_from(["test"])) ); } @@ -57,7 +57,7 @@ fn test_fetch() { verbose: 3, cmd: Sub::Fetch {} }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-vvv", "fetch"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-vvv", "fetch"])) ); assert_eq!( Opt { @@ -65,7 +65,7 @@ fn test_fetch() { verbose: 0, cmd: Sub::Fetch {} }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--force", "fetch"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--force", "fetch"])) ); } @@ -77,7 +77,7 @@ fn test_add() { verbose: 0, cmd: Sub::Add {} }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "add"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "add"])) ); assert_eq!( Opt { @@ -85,19 +85,19 @@ fn test_add() { verbose: 2, cmd: Sub::Add {} }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-vv", "add"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-vv", "add"])) ); } #[test] fn test_badinput() { - let result = Opt::clap().get_matches_from_safe(&["test", "badcmd"]); + let result = Opt::clap().get_matches_from_safe(["test", "badcmd"]); assert!(result.is_err()); - let result = Opt::clap().get_matches_from_safe(&["test", "add", "--verbose"]); + let result = Opt::clap().get_matches_from_safe(["test", "add", "--verbose"]); assert!(result.is_err()); - let result = Opt::clap().get_matches_from_safe(&["test", "--badopt", "add"]); + let result = Opt::clap().get_matches_from_safe(["test", "--badopt", "add"]); assert!(result.is_err()); - let result = Opt::clap().get_matches_from_safe(&["test", "add", "--badopt"]); + let result = Opt::clap().get_matches_from_safe(["test", "add", "--badopt"]); assert!(result.is_err()); } @@ -135,9 +135,7 @@ fn test_subsubcommand() { cmd: Sub3::Quux {} } }, - Opt3::from_clap( - &Opt3::clap().get_matches_from(&["test", "--all", "foo", "lib.rs", "quux"]) - ) + Opt3::from_clap(&Opt3::clap().get_matches_from(["test", "--all", "foo", "lib.rs", "quux"])) ); } diff --git a/tests/non_literal_attributes.rs b/tests/non_literal_attributes.rs index 4c3a442..8a8d7a3 100644 --- a/tests/non_literal_attributes.rs +++ b/tests/non_literal_attributes.rs @@ -43,7 +43,7 @@ fn test_slice() { files: Vec::new(), values: vec![], }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-l", "1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-l", "1"])) ); assert_eq!( Opt { @@ -52,7 +52,7 @@ fn test_slice() { files: Vec::new(), values: vec![], }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--level", "1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--level", "1"])) ); assert_eq!( Opt { @@ -61,7 +61,7 @@ fn test_slice() { files: Vec::new(), values: vec![], }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--set-level", "1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--set-level", "1"])) ); assert_eq!( Opt { @@ -70,7 +70,7 @@ fn test_slice() { files: Vec::new(), values: vec![], }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--lvl", "1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--lvl", "1"])) ); } @@ -83,7 +83,7 @@ fn test_multi_args() { files: vec!["file".to_string()], values: vec![], }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-l", "1", "file"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-l", "1", "file"])) ); assert_eq!( Opt { @@ -93,14 +93,14 @@ fn test_multi_args() { values: vec![1], }, Opt::from_clap( - &Opt::clap().get_matches_from(&["test", "-l", "1", "--values", "1", "--", "FILE"]), + &Opt::clap().get_matches_from(["test", "-l", "1", "--values", "1", "--", "FILE"]), ) ); } #[test] fn test_multi_args_fail() { - let result = Opt::clap().get_matches_from_safe(&["test", "-l", "1", "--", "FILE"]); + let result = Opt::clap().get_matches_from_safe(["test", "-l", "1", "--", "FILE"]); assert!(result.is_err()); } @@ -113,9 +113,9 @@ fn test_bool() { files: vec![], values: vec![], }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-l", "1", "--x=1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-l", "1", "--x=1"])) ); - let result = Opt::clap().get_matches_from_safe(&["test", "-l", "1", "--x", "1"]); + let result = Opt::clap().get_matches_from_safe(["test", "-l", "1", "--x", "1"]); assert!(result.is_err()); } @@ -133,15 +133,15 @@ struct HexOpt { fn test_parse_hex_function_path() { assert_eq!( HexOpt { number: 5 }, - HexOpt::from_clap(&HexOpt::clap().get_matches_from(&["test", "-n", "5"])) + HexOpt::from_clap(&HexOpt::clap().get_matches_from(["test", "-n", "5"])) ); assert_eq!( HexOpt { number: 0xabcdef }, - HexOpt::from_clap(&HexOpt::clap().get_matches_from(&["test", "-n", "abcdef"])) + HexOpt::from_clap(&HexOpt::clap().get_matches_from(["test", "-n", "abcdef"])) ); let err = HexOpt::clap() - .get_matches_from_safe(&["test", "-n", "gg"]) + .get_matches_from_safe(["test", "-n", "gg"]) .unwrap_err(); assert!( err.message.contains("invalid digit found in string"), diff --git a/tests/options.rs b/tests/options.rs index 5184134..7a3460a 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -17,19 +17,19 @@ fn required_option() { } assert_eq!( Opt { arg: 42 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a42"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a42"])) ); assert_eq!( Opt { arg: 42 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "42"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "42"])) ); assert_eq!( Opt { arg: 42 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--arg", "42"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--arg", "42"])) ); - assert!(Opt::clap().get_matches_from_safe(&["test"]).is_err()); + assert!(Opt::clap().get_matches_from_safe(["test"]).is_err()); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a42", "-a24"]) + .get_matches_from_safe(["test", "-a42", "-a24"]) .is_err()); } @@ -42,14 +42,14 @@ fn optional_option() { } assert_eq!( Opt { arg: Some(42) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a42"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a42"])) ); assert_eq!( Opt { arg: None }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a42", "-a24"]) + .get_matches_from_safe(["test", "-a42", "-a24"]) .is_err()); } @@ -62,14 +62,14 @@ fn option_with_default() { } assert_eq!( Opt { arg: 24 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a24"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a24"])) ); assert_eq!( Opt { arg: 42 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a42", "-a24"]) + .get_matches_from_safe(["test", "-a42", "-a24"]) .is_err()); } @@ -82,14 +82,14 @@ fn option_with_raw_default() { } assert_eq!( Opt { arg: 24 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a24"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a24"])) ); assert_eq!( Opt { arg: 42 }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a42", "-a24"]) + .get_matches_from_safe(["test", "-a42", "-a24"]) .is_err()); } @@ -102,15 +102,15 @@ fn options() { } assert_eq!( Opt { arg: vec![24] }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a24"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a24"])) ); assert_eq!( Opt { arg: vec![] }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert_eq!( Opt { arg: vec![24, 42] }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a24", "--arg", "42"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a24", "--arg", "42"])) ); } @@ -133,7 +133,7 @@ fn option_from_str() { #[derive(Debug, PartialEq)] struct A; - impl<'a> From<&'a str> for A { + impl From<&str> for A { fn from(_: &str) -> A { A } @@ -161,18 +161,18 @@ fn optional_argument_for_optional_option() { Opt { arg: Some(Some(42)) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a42"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a42"])) ); assert_eq!( Opt { arg: Some(None) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])) ); assert_eq!( Opt { arg: None }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); assert!(Opt::clap() - .get_matches_from_safe(&["test", "-a42", "-a24"]) + .get_matches_from_safe(["test", "-a42", "-a24"]) .is_err()); } @@ -192,42 +192,42 @@ fn two_option_options() { arg: Some(Some(42)), field: Some(Some("f".into())) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a42", "--field", "f"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a42", "--field", "f"])) ); assert_eq!( Opt { arg: Some(Some(42)), field: Some(None) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a42", "--field"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a42", "--field"])) ); assert_eq!( Opt { arg: Some(None), field: Some(None) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "--field"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "--field"])) ); assert_eq!( Opt { arg: Some(None), field: Some(Some("f".into())) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "--field", "f"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "--field", "f"])) ); assert_eq!( Opt { arg: None, field: Some(None) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "--field"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "--field"])) ); assert_eq!( Opt { arg: None, field: None }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); } @@ -240,57 +240,57 @@ fn optional_vec() { } assert_eq!( Opt { arg: Some(vec![1]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "1"])) ); assert_eq!( Opt { arg: Some(vec![1, 2]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a1", "-a2"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a1", "-a2"])) ); assert_eq!( Opt { arg: Some(vec![1, 2]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a1", "-a2", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a1", "-a2", "-a"])) ); assert_eq!( Opt { arg: Some(vec![1, 2]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a1", "-a", "-a2"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a1", "-a", "-a2"])) ); assert_eq!( Opt { arg: Some(vec![1, 2]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "1", "2"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "1", "2"])) ); assert_eq!( Opt { arg: Some(vec![1, 2, 3]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "1", "2", "-a", "3"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "1", "2", "-a", "3"])) ); assert_eq!( Opt { arg: Some(vec![]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a"])) ); assert_eq!( Opt { arg: Some(vec![]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "-a"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "-a"])) ); assert_eq!( Opt { arg: None }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); } @@ -310,7 +310,7 @@ fn two_optional_vecs() { arg: Some(vec![1]), b: Some(vec![]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "1", "-b"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "1", "-b"])) ); assert_eq!( @@ -318,7 +318,7 @@ fn two_optional_vecs() { arg: Some(vec![1]), b: Some(vec![]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a", "-b", "-a1"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a", "-b", "-a1"])) ); assert_eq!( @@ -326,11 +326,11 @@ fn two_optional_vecs() { arg: Some(vec![1, 2]), b: Some(vec![1, 2]) }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "-a1", "-a2", "-b1", "-b2"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "-a1", "-a2", "-b1", "-b2"])) ); assert_eq!( Opt { arg: None, b: None }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test"])) ); } diff --git a/tests/skip.rs b/tests/skip.rs index 47682d8..f9696e0 100644 --- a/tests/skip.rs +++ b/tests/skip.rs @@ -59,19 +59,14 @@ fn skip_2() { #[test] fn skip_enum() { - #[derive(Debug, PartialEq)] + #[derive(Debug, Default, PartialEq)] #[allow(unused)] enum Kind { A, + #[default] B, } - impl Default for Kind { - fn default() -> Self { - return Kind::B; - } - } - #[derive(StructOpt, Debug, PartialEq)] pub struct Opt { #[structopt(long, short)] diff --git a/tests/subcommands.rs b/tests/subcommands.rs index 4ee738b..f25b68f 100644 --- a/tests/subcommands.rs +++ b/tests/subcommands.rs @@ -39,7 +39,7 @@ fn test_fetch() { force: false, repo: "origin".to_string() }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "fetch", "--all", "origin"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "fetch", "--all", "origin"])) ); assert_eq!( Opt::Fetch { @@ -47,7 +47,7 @@ fn test_fetch() { force: true, repo: "origin".to_string() }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "fetch", "-f", "origin"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "fetch", "-f", "origin"])) ); } @@ -58,26 +58,26 @@ fn test_add() { interactive: false, verbose: false }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "add"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "add"])) ); assert_eq!( Opt::Add { interactive: true, verbose: true }, - Opt::from_clap(&Opt::clap().get_matches_from(&["test", "add", "-i", "-v"])) + Opt::from_clap(&Opt::clap().get_matches_from(["test", "add", "-i", "-v"])) ); } #[test] fn test_no_parse() { - let result = Opt::clap().get_matches_from_safe(&["test", "badcmd", "-i", "-v"]); + let result = Opt::clap().get_matches_from_safe(["test", "badcmd", "-i", "-v"]); assert!(result.is_err()); - let result = Opt::clap().get_matches_from_safe(&["test", "add", "--badoption"]); + let result = Opt::clap().get_matches_from_safe(["test", "add", "--badoption"]); assert!(result.is_err()); - let result = Opt::clap().get_matches_from_safe(&["test"]); + let result = Opt::clap().get_matches_from_safe(["test"]); assert!(result.is_err()); } @@ -94,7 +94,7 @@ fn test_hyphenated_subcommands() { Opt2::DoSomething { arg: "blah".to_string() }, - Opt2::from_clap(&Opt2::clap().get_matches_from(&["test", "do-something", "blah"])) + Opt2::from_clap(&Opt2::clap().get_matches_from(["test", "do-something", "blah"])) ); } @@ -109,15 +109,15 @@ enum Opt3 { fn test_null_commands() { assert_eq!( Opt3::Add, - Opt3::from_clap(&Opt3::clap().get_matches_from(&["test", "add"])) + Opt3::from_clap(&Opt3::clap().get_matches_from(["test", "add"])) ); assert_eq!( Opt3::Init, - Opt3::from_clap(&Opt3::clap().get_matches_from(&["test", "init"])) + Opt3::from_clap(&Opt3::clap().get_matches_from(["test", "init"])) ); assert_eq!( Opt3::Fetch, - Opt3::from_clap(&Opt3::clap().get_matches_from(&["test", "fetch"])) + Opt3::from_clap(&Opt3::clap().get_matches_from(["test", "fetch"])) ); } @@ -147,17 +147,17 @@ fn test_tuple_commands() { Opt4::Add(Add { file: "f".to_string() }), - Opt4::from_clap(&Opt4::clap().get_matches_from(&["test", "add", "f"])) + Opt4::from_clap(&Opt4::clap().get_matches_from(["test", "add", "f"])) ); assert_eq!( Opt4::Init, - Opt4::from_clap(&Opt4::clap().get_matches_from(&["test", "init"])) + Opt4::from_clap(&Opt4::clap().get_matches_from(["test", "init"])) ); assert_eq!( Opt4::Fetch(Fetch { remote: "origin".to_string() }), - Opt4::from_clap(&Opt4::clap().get_matches_from(&["test", "fetch", "origin"])) + Opt4::from_clap(&Opt4::clap().get_matches_from(["test", "fetch", "origin"])) ); let output = get_long_help::(); @@ -180,10 +180,10 @@ fn enum_in_enum_subsubcommand() { Stop, } - let result = Opt::clap().get_matches_from_safe(&["test"]); + let result = Opt::clap().get_matches_from_safe(["test"]); assert!(result.is_err()); - let result = Opt::clap().get_matches_from_safe(&["test", "daemon"]); + let result = Opt::clap().get_matches_from_safe(["test", "daemon"]); assert!(result.is_err()); let result = Opt::from_iter(&["test", "daemon", "start"]); diff --git a/tests/ui/external_subcommand_wrong_type.stderr b/tests/ui/external_subcommand_wrong_type.stderr index 73f12d2..0d525bd 100644 --- a/tests/ui/external_subcommand_wrong_type.stderr +++ b/tests/ui/external_subcommand_wrong_type.stderr @@ -1,8 +1,18 @@ error[E0308]: mismatched types --> $DIR/external_subcommand_wrong_type.rs:13:15 | -13 | Other(Vec) - | ^^^^^^^ expected struct `CString`, found struct `OsString` +11 | enum Command { + | ______- +12 | | #[structopt(external_subcommand)] +13 | | Other(Vec) + | | - ^^^^^^^ expected `Vec`, found `Vec` + | |_________| + | arguments to this enum variant are incorrect | = note: expected struct `Vec` found struct `Vec` +note: tuple variant defined here + --> $DIR/external_subcommand_wrong_type.rs:13:5 + | +13 | Other(Vec) + | ^^^^^ diff --git a/tests/ui/positional_bool.stderr b/tests/ui/positional_bool.stderr index c3ed1ad..7b88d2e 100644 --- a/tests/ui/positional_bool.stderr +++ b/tests/ui/positional_bool.stderr @@ -1,8 +1,8 @@ error: `bool` cannot be used as positional parameter with default parser - = help: if you want to create a flag add `long` or `short` - = help: If you really want a boolean parameter add an explicit parser, for example `parse(try_from_str)` - = note: see also https://github.com/TeXitoi/structopt/tree/master/examples/true_or_false.rs + = help: if you want to create a flag add `long` or `short` + = help: If you really want a boolean parameter add an explicit parser, for example `parse(try_from_str)` + = note: see also https://github.com/TeXitoi/structopt/tree/master/examples/true_or_false.rs --> $DIR/positional_bool.rs:5:14 | diff --git a/tests/ui/raw.stderr b/tests/ui/raw.stderr index 93b5e38..c988d8a 100644 --- a/tests/ui/raw.stderr +++ b/tests/ui/raw.stderr @@ -1,7 +1,7 @@ error: `#[structopt(raw(...))` attributes are removed in structopt 0.3, they are replaced with raw methods - = help: if you meant to call `clap::Arg::raw()` method you should use bool literal, like `raw(true)` or `raw(false)` - = note: if you need to call `clap::Arg/App::case_insensitive` method you can do it like this: #[structopt(case_insensitive = true)] + = help: if you meant to call `clap::Arg::raw()` method you should use bool literal, like `raw(true)` or `raw(false)` + = note: if you need to call `clap::Arg/App::case_insensitive` method you can do it like this: #[structopt(case_insensitive = true)] --> $DIR/raw.rs:13:17 | @@ -10,8 +10,8 @@ error: `#[structopt(raw(...))` attributes are removed in structopt 0.3, they are error: `#[structopt(raw(...))` attributes are removed in structopt 0.3, they are replaced with raw methods - = help: if you meant to call `clap::Arg::raw()` method you should use bool literal, like `raw(true)` or `raw(false)` - = note: if you need to call `clap::Arg/App::requires_if` method you can do it like this: #[structopt(requires_if("one", "two"))] + = help: if you meant to call `clap::Arg::raw()` method you should use bool literal, like `raw(true)` or `raw(false)` + = note: if you need to call `clap::Arg/App::requires_if` method you can do it like this: #[structopt(requires_if("one", "two"))] --> $DIR/raw.rs:19:17 | diff --git a/tests/ui/skip_without_default.stderr b/tests/ui/skip_without_default.stderr index d08be0c..6cbc182 100644 --- a/tests/ui/skip_without_default.stderr +++ b/tests/ui/skip_without_default.stderr @@ -1,7 +1,5 @@ error[E0277]: the trait bound `Kind: Default` is not satisfied - --> $DIR/skip_without_default.rs:22:17 - | -22 | #[structopt(skip)] - | ^^^^ the trait `Default` is not implemented for `Kind` - | -note: required by `std::default::Default::default` + --> $DIR/skip_without_default.rs:22:17 + | +22 | #[structopt(skip)] + | ^^^^ the trait `Default` is not implemented for `Kind` diff --git a/tests/ui/structopt_empty_attr.stderr b/tests/ui/structopt_empty_attr.stderr index bd3b3ed..7f4b00a 100644 --- a/tests/ui/structopt_empty_attr.stderr +++ b/tests/ui/structopt_empty_attr.stderr @@ -1,5 +1,5 @@ error: expected attribute arguments in parentheses: #[structopt(...)] - --> $DIR/structopt_empty_attr.rs:14:5 + --> $DIR/structopt_empty_attr.rs:14:7 | 14 | #[structopt] - | ^^^^^^^^^^^^ + | ^^^^^^^^^