test(parser): Reproduce suggestion

This commit is contained in:
Ed Page 2023-07-21 14:21:45 -05:00
parent 55923ca947
commit 76b891db41

View file

@ -187,3 +187,26 @@ For more information, try '--help'.
";
assert_error(err, expected_kind, MESSAGE, true);
}
#[test]
#[cfg(feature = "error-context")]
#[cfg(feature = "suggestions")]
fn cant_use_trailing_subcommand() {
let cmd = Command::new("test").subcommand(Command::new("bar"));
let res = cmd.try_get_matches_from(["test", "baz"]);
assert!(res.is_err());
let err = res.unwrap_err();
let expected_kind = ErrorKind::InvalidSubcommand;
static MESSAGE: &str = "\
error: unrecognized subcommand 'baz'
tip: a similar subcommand exists: 'bar'
tip: to pass 'baz' as a value, use 'test -- baz'
Usage: test [COMMAND]
For more information, try '--help'.
";
assert_error(err, expected_kind, MESSAGE, true);
}