2022-02-14 22:09:38 +00:00
|
|
|
use clap::CommandFactory;
|
2021-07-13 17:50:55 +00:00
|
|
|
use clap::Parser;
|
2022-09-22 14:39:24 +00:00
|
|
|
|
|
|
|
use crate::utils::get_help;
|
|
|
|
use crate::utils::get_long_help;
|
|
|
|
|
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-09-02 20:37:23 +00:00
|
|
|
#[command(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
struct MyApp {}
|
|
|
|
|
2022-09-22 14:39:24 +00:00
|
|
|
let help = get_help::<MyApp>();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
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-09-02 20:37:23 +00:00
|
|
|
#[command(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
struct MyApp {}
|
|
|
|
|
2022-09-22 14:39:24 +00:00
|
|
|
let help = get_help::<MyApp>();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
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-09-02 20:37:23 +00:00
|
|
|
#[command(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
enum MyApp {}
|
|
|
|
|
2022-09-22 14:39:24 +00:00
|
|
|
let help = get_help::<MyApp>();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
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-09-02 20:37:23 +00:00
|
|
|
#[command(name = "my-cmd")]
|
2021-02-22 13:54:15 +00:00
|
|
|
enum MyApp {}
|
|
|
|
|
2022-09-22 14:39:24 +00:00
|
|
|
let help = get_long_help::<MyApp>();
|
2021-02-22 13:54:15 +00:00
|
|
|
|
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-09-02 20:37:23 +00:00
|
|
|
#[command(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-09-02 20:37:23 +00:00
|
|
|
#[command(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-09-02 20:37:23 +00:00
|
|
|
#[command(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-09-02 20:37:23 +00:00
|
|
|
#[command(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
|
|
|
}
|