2021-08-14 21:25:22 +00:00
|
|
|
#![cfg(feature = "env")]
|
|
|
|
|
|
|
|
use std::env;
|
|
|
|
|
|
|
|
use clap::{App, Arg};
|
|
|
|
|
|
|
|
mod utils;
|
|
|
|
|
|
|
|
static HIDE_ENV: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-09-24 15:58:39 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café.
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static SHOW_ENV: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-09-24 15:58:39 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static HIDE_ENV_VALS: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-09-24 15:58:39 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR]
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static SHOW_ENV_VALS: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
|
|
|
ctest [OPTIONS]
|
|
|
|
|
|
|
|
OPTIONS:
|
2021-09-24 15:58:39 +00:00
|
|
|
-c, --cafe <FILE> A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
2021-10-11 22:01:33 +00:00
|
|
|
-h, --help Print help information
|
|
|
|
-V, --version Print version information
|
2021-09-24 15:58:39 +00:00
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static HIDE_ENV_FLAG: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-08-14 21:25:22 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café.
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static SHOW_ENV_FLAG: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-08-14 21:25:22 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static HIDE_ENV_VALS_FLAG: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-08-14 21:25:22 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR]
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
static SHOW_ENV_VALS_FLAG: &str = "ctest 0.1
|
|
|
|
|
|
|
|
USAGE:
|
2021-10-11 22:01:33 +00:00
|
|
|
ctest [OPTIONS]
|
2021-08-14 21:25:22 +00:00
|
|
|
|
2021-10-11 22:01:33 +00:00
|
|
|
OPTIONS:
|
2021-08-14 21:25:22 +00:00
|
|
|
-c, --cafe A coffeehouse, coffee shop, or café. [env: ENVVAR=MYVAL]
|
|
|
|
-h, --help Print help information
|
2021-09-24 15:58:39 +00:00
|
|
|
-V, --version Print version information
|
|
|
|
";
|
2021-08-14 21:25:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
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é.")
|
2021-08-14 21:25:22 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(app, "ctest --help", HIDE_ENV, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
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é.")
|
2021-08-14 21:25:22 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(app, "ctest --help", SHOW_ENV, false));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_vals() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
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é.")
|
2021-08-14 21:25:22 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"ctest --help",
|
|
|
|
HIDE_ENV_VALS,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env_vals() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
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é.")
|
2021-08-14 21:25:22 +00:00
|
|
|
.takes_value(true),
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"ctest --help",
|
|
|
|
SHOW_ENV_VALS,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.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
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"ctest --help",
|
|
|
|
HIDE_ENV_FLAG,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.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
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"ctest --help",
|
|
|
|
SHOW_ENV_FLAG,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn hide_env_vals_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.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
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"ctest --help",
|
|
|
|
HIDE_ENV_VALS_FLAG,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn show_env_vals_flag() {
|
|
|
|
env::set_var("ENVVAR", "MYVAL");
|
|
|
|
|
|
|
|
let app = App::new("ctest").version("0.1").arg(
|
|
|
|
Arg::new("cafe")
|
|
|
|
.short('c')
|
|
|
|
.long("cafe")
|
|
|
|
.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
|
|
|
);
|
|
|
|
|
|
|
|
assert!(utils::compare_output(
|
|
|
|
app,
|
|
|
|
"ctest --help",
|
|
|
|
SHOW_ENV_VALS_FLAG,
|
|
|
|
false
|
|
|
|
));
|
|
|
|
}
|