mirror of
https://github.com/clap-rs/clap
synced 2024-12-14 14:52:33 +00:00
7e899cd340
This reverts commits 24cb8b1..d0abb37 from clap-rs/clap#1840 This is part of #16. clap-rs/clap#1840 wasn't the right call but we don't have time to make the decision now, so instead of having one option and changing it in 4.0, this reverts back to clap2 behavior.
59 lines
1.6 KiB
Rust
59 lines
1.6 KiB
Rust
mod utils;
|
|
|
|
use clap::{App, Arg, Error, ErrorKind};
|
|
|
|
fn compare_error(
|
|
err: Error,
|
|
expected_kind: ErrorKind,
|
|
expected_output: &str,
|
|
stderr: bool,
|
|
) -> bool {
|
|
let actual_output = err.to_string();
|
|
assert_eq!(
|
|
stderr,
|
|
err.use_stderr(),
|
|
"Should Use STDERR failed. Should be {} but is {}",
|
|
stderr,
|
|
err.use_stderr()
|
|
);
|
|
assert_eq!(expected_kind, err.kind);
|
|
utils::compare(expected_output, actual_output)
|
|
}
|
|
|
|
#[test]
|
|
fn app_error() {
|
|
static MESSAGE: &str = "error: Failed for mysterious reasons
|
|
|
|
USAGE:
|
|
test [OPTIONS] --all
|
|
|
|
For more information try --help
|
|
";
|
|
let app = App::new("test")
|
|
.arg(
|
|
Arg::new("all")
|
|
.short('a')
|
|
.long("all")
|
|
.required(true)
|
|
.help("Also do versioning for private crates (will not be published)"),
|
|
)
|
|
.arg(
|
|
Arg::new("exact")
|
|
.long("exact")
|
|
.help("Specify inter dependency version numbers exactly with `=`"),
|
|
)
|
|
.arg(
|
|
Arg::new("no_git_commit")
|
|
.long("no-git-commit")
|
|
.help("Do not commit version changes"),
|
|
)
|
|
.arg(
|
|
Arg::new("no_git_push")
|
|
.long("no-git-push")
|
|
.help("Do not push generated commit and tags to git remote"),
|
|
);
|
|
let mut app = app;
|
|
let expected_kind = ErrorKind::InvalidValue;
|
|
let err = app.error(expected_kind, "Failed for mysterious reasons");
|
|
assert!(compare_error(err, expected_kind, MESSAGE, true));
|
|
}
|