From 15f43f871aeb686987f6768203042b110a2d974b Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Feb 2022 09:03:18 -0600 Subject: [PATCH 1/2] refactor(ci): Move ui tests to Makefile --- .github/workflows/ci.yml | 2 +- Makefile | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fe3f3f4280..a224a3c4b6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -125,7 +125,7 @@ jobs: override: true - uses: Swatinem/rust-cache@v1 - name: UI Tests - run: cargo test --test derive_ui --features derive + run: make test-ui docs: name: Docs runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index e001b23f3fd..35f188b37fa 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,8 @@ ifneq (${TOOLCHAIN_TARGET},) ARGS+=--target ${TOOLCHAIN_TARGET} endif +MSRV?=1.54.0 + _FEATURES = minimal default wasm full debug release _FEATURES_minimal = --no-default-features --features "std" _FEATURES_default = @@ -29,3 +31,6 @@ test-%: clippy-%: cargo clippy ${_FEATURES_${@:clippy-%=%}} ${ARGS} --all-targets -- -D warnings -A deprecated + +test-ui: + cargo +${MSRV} test --test derive_ui --features derive From cb937641fa5aee12b2b566e5d52eab7019638936 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 23 Feb 2022 09:22:42 -0600 Subject: [PATCH 2/2] fix(derive): Allow other attributes with subcommand that has subcommands This was overlooked when we added support for `#[clap(subcommand)]` to variants. Fixes #3504 --- clap_derive/src/attrs.rs | 8 +------- tests/derive/subcommands.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/clap_derive/src/attrs.rs b/clap_derive/src/attrs.rs index b51eeaad866..9a7bb7e7b29 100644 --- a/clap_derive/src/attrs.rs +++ b/clap_derive/src/attrs.rs @@ -127,15 +127,9 @@ impl Attrs { "parse attribute is not allowed for subcommand" ); } - if res.has_explicit_methods() { - abort!( - res.kind.span(), - "methods in attributes are not allowed for subcommand" - ); - } + use syn::Fields::*; use syn::FieldsUnnamed; - let field_ty = match variant.fields { Named(_) => { abort!(variant.span(), "structs are not allowed for subcommand"); diff --git a/tests/derive/subcommands.rs b/tests/derive/subcommands.rs index 3d122c85056..0986df574cf 100644 --- a/tests/derive/subcommands.rs +++ b/tests/derive/subcommands.rs @@ -296,7 +296,9 @@ fn external_subcommand_optional() { fn enum_in_enum_subsubcommand() { #[derive(Parser, Debug, PartialEq)] pub enum Opt { - #[clap(subcommand)] + #[clap(alias = "l")] + List, + #[clap(subcommand, alias = "d")] Daemon(DaemonCommand), } @@ -309,11 +311,20 @@ fn enum_in_enum_subsubcommand() { let result = Opt::try_parse_from(&["test"]); assert!(result.is_err()); + let result = Opt::try_parse_from(&["test", "list"]).unwrap(); + assert_eq!(Opt::List, result); + + let result = Opt::try_parse_from(&["test", "l"]).unwrap(); + assert_eq!(Opt::List, result); + let result = Opt::try_parse_from(&["test", "daemon"]); assert!(result.is_err()); let result = Opt::try_parse_from(&["test", "daemon", "start"]).unwrap(); assert_eq!(Opt::Daemon(DaemonCommand::Start), result); + + let result = Opt::try_parse_from(&["test", "d", "start"]).unwrap(); + assert_eq!(Opt::Daemon(DaemonCommand::Start), result); } #[test]