test(asserts): Add test for self requires

Add a test that shows that clap doesn't complain when a flag requires
itself.

This test demonstrates existing broken behavior, ideally it should
panic.

It will be fixed in the next commit.

Signed-off-by: Omer Tuchfeld <omer@tuchfeld.dev>
This commit is contained in:
Omer Tuchfeld 2024-12-03 19:56:21 +01:00
parent bfca193556
commit 52aad0ea1a

View file

@ -1478,3 +1478,12 @@ For more information, try '--help'.
";
utils::assert_output(cmd, "test --require-first --second", EXPECTED, true);
}
#[test]
/// This test demonstrates existing broken behavior, ideally it should panic
fn requires_self() {
let result = Command::new("flag_required")
.arg(arg!(-f --flag "some flag").requires("flag"))
.try_get_matches_from(vec![""]);
assert!(result.is_ok());
}