2021-10-15 21:06:21 +00:00
|
|
|
mod utils;
|
|
|
|
|
2021-11-02 21:39:06 +00:00
|
|
|
use clap::{App, Arg, Error, ErrorKind};
|
2021-10-15 21:06:21 +00:00
|
|
|
|
|
|
|
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)
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Also do versioning for private crates (will not be published)"),
|
2021-10-15 21:06:21 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("exact")
|
|
|
|
.long("exact")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Specify inter dependency version numbers exactly with `=`"),
|
2021-10-15 21:06:21 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("no_git_commit")
|
|
|
|
.long("no-git-commit")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not commit version changes"),
|
2021-10-15 21:06:21 +00:00
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::new("no_git_push")
|
|
|
|
.long("no-git-push")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("Do not push generated commit and tags to git remote"),
|
2021-10-15 21:06:21 +00:00
|
|
|
);
|
|
|
|
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));
|
|
|
|
}
|