clap/tests/derive/app_name.rs

98 lines
2.1 KiB
Rust
Raw Normal View History

use clap::CommandFactory;
use clap::Parser;
#[test]
fn app_name_in_short_help_from_struct() {
#[derive(Parser)]
#[command(name = "my-cmd")]
struct MyApp {}
let mut help = Vec::new();
MyApp::command().write_help(&mut help).unwrap();
let help = String::from_utf8(help).unwrap();
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 mut help = Vec::new();
MyApp::command().write_long_help(&mut help).unwrap();
let help = String::from_utf8(help).unwrap();
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 mut help = Vec::new();
MyApp::command().write_help(&mut help).unwrap();
let help = String::from_utf8(help).unwrap();
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 mut help = Vec::new();
MyApp::command().write_long_help(&mut help).unwrap();
let help = String::from_utf8(help).unwrap();
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"));
}