clap/tests/derive/app_name.rs

94 lines
1.8 KiB
Rust
Raw Normal View History

use clap::CommandFactory;
use clap::Parser;
use crate::utils::get_help;
use crate::utils::get_long_help;
#[test]
fn app_name_in_short_help_from_struct() {
#[derive(Parser)]
#[command(name = "my-cmd")]
struct MyApp {}
let help = get_help::<MyApp>();
2022-02-14 21:47:20 +00:00
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_long_help_from_struct() {
#[derive(Parser)]
#[command(name = "my-cmd")]
struct MyApp {}
let help = get_help::<MyApp>();
2022-02-14 21:47:20 +00:00
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_short_help_from_enum() {
#[derive(Parser)]
#[command(name = "my-cmd")]
enum MyApp {}
let help = get_help::<MyApp>();
2022-02-14 21:47:20 +00:00
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_long_help_from_enum() {
#[derive(Parser)]
#[command(name = "my-cmd")]
enum MyApp {}
let help = get_long_help::<MyApp>();
2022-02-14 21:47:20 +00:00
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_short_version_from_struct() {
#[derive(Parser)]
#[command(name = "my-cmd")]
struct MyApp {}
let version = MyApp::command().render_version();
2022-02-14 21:47:20 +00:00
assert!(version.contains("my-cmd"));
}
#[test]
fn app_name_in_long_version_from_struct() {
#[derive(Parser)]
#[command(name = "my-cmd")]
struct MyApp {}
let version = MyApp::command().render_long_version();
2022-02-14 21:47:20 +00:00
assert!(version.contains("my-cmd"));
}
#[test]
fn app_name_in_short_version_from_enum() {
#[derive(Parser)]
#[command(name = "my-cmd")]
enum MyApp {}
let version = MyApp::command().render_version();
2022-02-14 21:47:20 +00:00
assert!(version.contains("my-cmd"));
}
#[test]
fn app_name_in_long_version_from_enum() {
#[derive(Parser)]
#[command(name = "my-cmd")]
enum MyApp {}
let version = MyApp::command().render_long_version();
2022-02-14 21:47:20 +00:00
assert!(version.contains("my-cmd"));
}