mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
Merge #1932
1932: fix(errors): ensure that validation failure error message includes a newline r=CreepySkeleton a=pmarks Co-authored-by: Patrick Marks <patrick@10xgenomics.com>
This commit is contained in:
commit
e747ec11ab
2 changed files with 20 additions and 0 deletions
|
@ -851,6 +851,7 @@ impl Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
c.none(&format!(": {}", err))?;
|
c.none(&format!(": {}", err))?;
|
||||||
|
try_help(&mut c)?;
|
||||||
|
|
||||||
Ok(Error {
|
Ok(Error {
|
||||||
cause: format!(
|
cause: format!(
|
||||||
|
|
|
@ -17,3 +17,22 @@ fn both_validator_and_validator_os() {
|
||||||
)
|
)
|
||||||
.try_get_matches_from(&["app", "1"]);
|
.try_get_matches_from(&["app", "1"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_validator_msg_newline() {
|
||||||
|
let res = App::new("test")
|
||||||
|
.arg(Arg::new("test").validator(|val| val.parse::<u32>().map_err(|e| e.to_string())))
|
||||||
|
.try_get_matches_from(&["app", "f"]);
|
||||||
|
|
||||||
|
assert!(res.is_err());
|
||||||
|
let err = res.unwrap_err();
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
err.cause,
|
||||||
|
"Invalid value for \'<test>\': invalid digit found in string"
|
||||||
|
);
|
||||||
|
|
||||||
|
// This message is the only thing that gets printed -- make sure it ends with a newline
|
||||||
|
let msg = format!("{}", err);
|
||||||
|
assert!(msg.ends_with('\n'));
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue