Skip to content

Commit

Permalink
test(derive): Ensure we don't break compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Jun 2, 2022
1 parent 002d442 commit 5db6113
Show file tree
Hide file tree
Showing 33 changed files with 5,284 additions and 0 deletions.
97 changes: 97 additions & 0 deletions tests/derive/legacy/app_name.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
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"));
}
Loading

0 comments on commit 5db6113

Please sign in to comment.