clap/tests/derive/rename_all_env.rs

48 lines
1,023 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)]
#[command(rename_all_env = "kebab")]
2019-12-06 09:48:32 +00:00
struct BehaviorModel {
#[arg(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 {
#[arg(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)]
#[command(rename_all_env = "kebab")]
2019-12-06 09:48:32 +00:00
struct BehaviorModel {
#[arg(env)]
2019-12-06 09:48:32 +00:00
be_nice: String,
#[arg(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
}