2021-08-14 21:25:22 +00:00
|
|
|
#![cfg(feature = "env")]
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
2022-07-26 00:17:01 +00:00
|
|
|
use clap::{Arg, ArgAction, Command};
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-06-07 21:21:12 +00:00
|
|
|
use super::utils;
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDE_ENV: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café.
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static SHOW_ENV: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDE_ENV_VALS: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR]
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static SHOW_ENV_VALS: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDE_ENV_FLAG: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café.
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static SHOW_ENV_FLAG: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static HIDE_ENV_VALS_FLAG: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR]
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-31 14:29:00 +00:00
|
|
|
static SHOW_ENV_VALS_FLAG: &str = "\
|
2022-09-07 16:03:55 +00:00
|
|
|
Usage: ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2022-08-26 14:40:23 +00:00
|
|
|
Options:
|
2022-09-07 20:29:15 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
2023-01-03 16:49:43 +00:00
|
|
|
-h, --help Print help
|
|
|
|
-V, --version Print version
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
|
|
|
.hide_env(true)
|
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", HIDE_ENV, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", SHOW_ENV, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_vals() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
|
|
|
.hide_env_values(true)
|
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", HIDE_ENV_VALS, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env_vals() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.value_name("FILE")
|
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café.")
|
2022-07-26 00:17:01 +00:00
|
|
|
.action(ArgAction::Set),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", SHOW_ENV_VALS, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
2022-08-05 18:31:33 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
2021-08-14 21:25:22 +00:00
|
|
|
.hide_env(true)
|
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café."),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", HIDE_ENV_FLAG, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
2022-08-05 18:31:33 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
2021-08-14 21:25:22 +00:00
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café."),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", SHOW_ENV_FLAG, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_vals_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
2022-08-05 18:31:33 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
2021-08-14 21:25:22 +00:00
|
|
|
.hide_env_values(true)
|
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café."),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", HIDE_ENV_VALS_FLAG, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env_vals_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
2022-02-14 21:47:20 +00:00
|
|
|
let cmd = Command::new("ctest").version("0.1").arg(
|
2021-08-14 21:25:22 +00:00
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
2022-08-05 18:31:33 +00:00
|
|
|
.action(ArgAction::SetTrue)
|
2021-08-14 21:25:22 +00:00
|
|
|
.env("ENVVAR")
|
2021-11-18 16:17:15 +00:00
|
|
|
.help("A coffeehouse, coffee shop, or café."),
|
2021-08-14 21:25:22 +00:00
|
|
|
);
|
|
|
|
|
2022-04-29 20:32:25 +00:00
|
|
|
utils::assert_output(cmd, "ctest --help", SHOW_ENV_VALS_FLAG, false);
|
2021-08-14 21:25:22 +00:00
|
|
|
}
|