2021-11-30 15:36:53 +00:00
|
|
|
#![cfg(feature = "env")]
|
|
|
|
|
|
|
|
use crate::utils;
|
2019-12-06 09:48:32 +00:00
|
|
|
|
2021-07-13 17:50:55 +00:00
|
|
|
use clap::Parser;
|
2019-12-06 09:48:32 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn it_works() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(rename_all_env = "kebab")]
|
2019-12-06 09:48:32 +00:00
|
|
|
struct BehaviorModel {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(env)]
|
2019-12-06 09:48:32 +00:00
|
|
|
be_nice: String,
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:36:53 +00:00
|
|
|
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() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2019-12-06 09:48:32 +00:00
|
|
|
struct BehaviorModel {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(env)]
|
2019-12-06 09:48:32 +00:00
|
|
|
be_nice: String,
|
|
|
|
}
|
|
|
|
|
2021-11-30 15:36:53 +00:00
|
|
|
let help = utils::get_help::<BehaviorModel>();
|
2019-12-06 09:48:32 +00:00
|
|
|
assert!(help.contains("[env: BE_NICE=]"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn overridable() {
|
2021-07-13 17:50:55 +00:00
|
|
|
#[derive(Debug, PartialEq, Parser)]
|
2022-09-02 20:37:23 +00:00
|
|
|
#[command(rename_all_env = "kebab")]
|
2019-12-06 09:48:32 +00:00
|
|
|
struct BehaviorModel {
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(env)]
|
2019-12-06 09:48:32 +00:00
|
|
|
be_nice: String,
|
|
|
|
|
2022-09-02 20:37:23 +00:00
|
|
|
#[arg(rename_all_env = "pascal", env)]
|
2021-10-19 01:38:22 +00:00
|
|
|
be_aggressive: String,
|
2019-12-06 09:48:32 +00:00
|
|
|
}
|
|
|
|
|
2021-11-30 15:36:53 +00:00
|
|
|
let help = utils::get_help::<BehaviorModel>();
|
2019-12-06 09:48:32 +00:00
|
|
|
assert!(help.contains("[env: be-nice=]"));
|
2021-10-19 01:38:22 +00:00
|
|
|
assert!(help.contains("[env: BeAggressive=]"));
|
2019-12-06 09:48:32 +00:00
|
|
|
}
|