diff --git a/tests/derive/groups.rs b/tests/derive/groups.rs index edc2d93c91c..b27d95981da 100644 --- a/tests/derive/groups.rs +++ b/tests/derive/groups.rs @@ -21,3 +21,29 @@ fn test_safely_nest_parser() { Opt::try_parse_from(&["test", "--foo"]).unwrap() ); } + +#[test] +#[should_panic = "'Compose' is already in use"] +fn skip_group_avoids_duplicate_ids() { + #[derive(Parser, Debug)] + struct Opt { + #[command(flatten)] + first: Compose, + #[command(flatten)] + second: Compose, + } + + #[derive(clap::Args, Debug)] + pub struct Compose { + #[clap(flatten)] + pub left: L, + #[clap(flatten)] + pub right: R, + } + + #[derive(clap::Args, Clone, Copy, Debug)] + pub struct Empty; + + use clap::CommandFactory; + Opt::command().debug_assert(); +}