clap/tests/yaml.rs

39 lines
1.1 KiB
Rust
Raw Normal View History

2018-01-25 04:05:05 +00:00
#![cfg(feature = "yaml")]
2021-11-18 20:27:21 +00:00
#![allow(deprecated)]
2016-01-12 05:13:14 +00:00
2022-02-12 03:48:29 +00:00
use clap::{load_yaml, Command};
#[test]
2022-02-14 21:47:20 +00:00
fn create_cmd_from_yaml() {
let yml = load_yaml!("app.yml");
2022-02-12 03:48:29 +00:00
Command::from_yaml(yml);
2016-01-12 05:13:14 +00:00
}
#[test]
fn help_message() {
let yml = load_yaml!("app.yml");
2022-02-14 21:47:20 +00:00
let mut cmd = Command::from_yaml(yml);
// Generate the full help message!
2022-02-14 21:47:20 +00:00
let _ = cmd.get_matches_from_safe_borrow(Vec::<String>::new());
let mut help_buffer = Vec::new();
2022-02-14 21:47:20 +00:00
cmd.write_help(&mut help_buffer).unwrap();
let help_string = String::from_utf8(help_buffer).unwrap();
println!("{}", &help_string);
assert!(help_string.contains("tests positionals with exclusions\n"));
}
#[test]
fn author() {
let yml = load_yaml!("app.yml");
2022-02-14 21:47:20 +00:00
let mut cmd = Command::from_yaml(yml);
// Generate the full help message!
2022-02-14 21:47:20 +00:00
let _ = cmd.get_matches_from_safe_borrow(Vec::<String>::new());
let mut help_buffer = Vec::new();
2022-02-14 21:47:20 +00:00
cmd.write_help(&mut help_buffer).unwrap();
let help_string = String::from_utf8(help_buffer).unwrap();
println!("{}", &help_string);
2018-01-25 04:05:05 +00:00
assert!(help_string.contains("Kevin K. <kbknapp@gmail.com>"));
}