clap/tests/derive/rename_all_env.rs

48 lines
1,021 B
Rust
Raw Normal View History

#![cfg(feature = "env")]
use crate::utils;
2019-12-06 09:48:32 +00:00
use clap::Parser;
2019-12-06 09:48:32 +00:00
#[test]
fn it_works() {
#[derive(Debug, PartialEq, Parser)]
2019-12-06 09:48:32 +00:00
#[clap(rename_all_env = "kebab")]
struct BehaviorModel {
#[clap(env)]
2019-12-06 09:48:32 +00:00
be_nice: String,
}
let help = utils::get_help::<BehaviorModel>();
2019-12-06 09:48:32 +00:00
assert!(help.contains("[env: be-nice=]"));
}
#[test]
fn default_is_screaming() {
#[derive(Debug, PartialEq, Parser)]
2019-12-06 09:48:32 +00:00
struct BehaviorModel {
#[clap(env)]
2019-12-06 09:48:32 +00:00
be_nice: String,
}
let help = utils::get_help::<BehaviorModel>();
2019-12-06 09:48:32 +00:00
assert!(help.contains("[env: BE_NICE=]"));
}
#[test]
fn overridable() {
#[derive(Debug, PartialEq, Parser)]
2019-12-06 09:48:32 +00:00
#[clap(rename_all_env = "kebab")]
struct BehaviorModel {
#[clap(env)]
2019-12-06 09:48:32 +00:00
be_nice: String,
#[clap(rename_all_env = "pascal", env)]
be_aggressive: String,
2019-12-06 09:48:32 +00:00
}
let help = utils::get_help::<BehaviorModel>();
2019-12-06 09:48:32 +00:00
assert!(help.contains("[env: be-nice=]"));
assert!(help.contains("[env: BeAggressive=]"));
2019-12-06 09:48:32 +00:00
}