Skip to content

Commit

Permalink
test(asserts): Add test for self requires
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
omertuc committed Dec 3, 2024
1 parent bfca193 commit 52aad0e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/builder/require.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

0 comments on commit 52aad0e

Please sign in to comment.