2022-02-14 22:09:38 +00:00
|
|
|
use clap::CommandFactory;
|
2021-07-13 17:50:55 +00:00
|
|
|
use clap::Parser;
|
2021-02-22 13:54:15 +00:00
|
|
|
#[test]
|
|
|
|
fn app_name_in_short_help_from_struct() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
struct MyApp {}
|
|
|
|
|
|
|
|
let mut help = Vec::new();
|
2022-02-14 22:04:07 +00:00
|
|
|
MyApp::command().write_help(&mut help).unwrap();
|
2021-02-22 13:54:15 +00:00
|
|
|
let help = String::from_utf8(help).unwrap();
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(help.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_long_help_from_struct() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
struct MyApp {}
|
|
|
|
|
|
|
|
let mut help = Vec::new();
|
2022-02-14 22:04:07 +00:00
|
|
|
MyApp::command().write_long_help(&mut help).unwrap();
|
2021-02-22 13:54:15 +00:00
|
|
|
let help = String::from_utf8(help).unwrap();
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(help.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_short_help_from_enum() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
enum MyApp {}
|
|
|
|
|
|
|
|
let mut help = Vec::new();
|
2022-02-14 22:04:07 +00:00
|
|
|
MyApp::command().write_help(&mut help).unwrap();
|
2021-02-22 13:54:15 +00:00
|
|
|
let help = String::from_utf8(help).unwrap();
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(help.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_long_help_from_enum() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
enum MyApp {}
|
|
|
|
|
|
|
|
let mut help = Vec::new();
|
2022-02-14 22:04:07 +00:00
|
|
|
MyApp::command().write_long_help(&mut help).unwrap();
|
2021-02-22 13:54:15 +00:00
|
|
|
let help = String::from_utf8(help).unwrap();
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(help.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_short_version_from_struct() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
struct MyApp {}
|
|
|
|
|
2022-02-14 22:04:07 +00:00
|
|
|
let version = MyApp::command().render_version();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(version.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_long_version_from_struct() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
struct MyApp {}
|
|
|
|
|
2022-02-14 22:04:07 +00:00
|
|
|
let version = MyApp::command().render_long_version();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(version.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_short_version_from_enum() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
enum MyApp {}
|
|
|
|
|
2022-02-14 22:04:07 +00:00
|
|
|
let version = MyApp::command().render_version();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(version.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn app_name_in_long_version_from_enum() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Parser)]
|
2022-02-14 21:47:20 +00:00
|
|
|
#[clap(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
enum MyApp {}
|
|
|
|
|
2022-02-14 22:04:07 +00:00
|
|
|
let version = MyApp::command().render_long_version();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
assert!(version.contains("my-cmd"));
|
2021-02-22 13:54:15 +00:00
|
|
|
}
|