clap/tests/derive/app_name.rs
Ed Page ddac492302 fix: Rename IntoApp to CommandFactory
This is part of the `App` rename.

Previously, I was concerned about not being able to deprecate

For backwards compatibility, we still expose the `IntoApp` name.
2022-02-15 08:24:00 -06:00

97 lines
2.1 KiB
Rust

use clap::CommandFactory;
use clap::Parser;
#[test]
fn app_name_in_short_help_from_struct() {
#[derive(Parser)]
#[clap(name = "my-cmd")]
struct MyApp {}
let mut help = Vec::new();
MyApp::command().write_help(&mut help).unwrap();
let help = String::from_utf8(help).unwrap();
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_long_help_from_struct() {
#[derive(Parser)]
#[clap(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();
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_short_help_from_enum() {
#[derive(Parser)]
#[clap(name = "my-cmd")]
enum MyApp {}
let mut help = Vec::new();
MyApp::command().write_help(&mut help).unwrap();
let help = String::from_utf8(help).unwrap();
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_long_help_from_enum() {
#[derive(Parser)]
#[clap(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();
assert!(help.contains("my-cmd"));
}
#[test]
fn app_name_in_short_version_from_struct() {
#[derive(Parser)]
#[clap(name = "my-cmd")]
struct MyApp {}
let version = MyApp::command().render_version();
assert!(version.contains("my-cmd"));
}
#[test]
fn app_name_in_long_version_from_struct() {
#[derive(Parser)]
#[clap(name = "my-cmd")]
struct MyApp {}
let version = MyApp::command().render_long_version();
assert!(version.contains("my-cmd"));
}
#[test]
fn app_name_in_short_version_from_enum() {
#[derive(Parser)]
#[clap(name = "my-cmd")]
enum MyApp {}
let version = MyApp::command().render_version();
assert!(version.contains("my-cmd"));
}
#[test]
fn app_name_in_long_version_from_enum() {
#[derive(Parser)]
#[clap(name = "my-cmd")]
enum MyApp {}
let version = MyApp::command().render_long_version();
assert!(version.contains("my-cmd"));
}