fix(env tests): fixes the env tests to allow multi-threaded test runs

This commit is contained in:
Kevin K 2018-10-19 23:31:38 -04:00
parent 03333800fe
commit a7e87d619c

View file

@ -22,10 +22,10 @@ fn env() {
#[test] #[test]
fn env_os() { fn env_os() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_OS", "env");
let r = App::new("df") let r = App::new("df")
.arg(Arg::from("[arg] 'some opt'").env_os(OsStr::new("CLP_TEST_ENV"))) .arg(Arg::from("[arg] 'some opt'").env_os(OsStr::new("CLP_TEST_ENV_OS")))
.try_get_matches_from(vec![""]); .try_get_matches_from(vec![""]);
assert!(r.is_ok()); assert!(r.is_ok());
@ -54,12 +54,12 @@ fn no_env() {
#[test] #[test]
fn with_default() { fn with_default() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_WD", "env");
let r = App::new("df") let r = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_WD")
.default_value("default"), .default_value("default"),
) )
.try_get_matches_from(vec![""]); .try_get_matches_from(vec![""]);
@ -73,10 +73,10 @@ fn with_default() {
#[test] #[test]
fn opt_user_override() { fn opt_user_override() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_OR", "env");
let r = App::new("df") let r = App::new("df")
.arg(Arg::from("--arg [FILE] 'some arg'").env("CLP_TEST_ENV")) .arg(Arg::from("--arg [FILE] 'some arg'").env("CLP_TEST_ENV_OR"))
.try_get_matches_from(vec!["", "--arg", "opt"]); .try_get_matches_from(vec!["", "--arg", "opt"]);
assert!(r.is_ok()); assert!(r.is_ok());
@ -88,10 +88,10 @@ fn opt_user_override() {
#[test] #[test]
fn positionals() { fn positionals() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_P", "env");
let r = App::new("df") let r = App::new("df")
.arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV")) .arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV_P"))
.try_get_matches_from(vec![""]); .try_get_matches_from(vec![""]);
assert!(r.is_ok()); assert!(r.is_ok());
@ -103,10 +103,10 @@ fn positionals() {
#[test] #[test]
fn positionals_user_override() { fn positionals_user_override() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_POR", "env");
let r = App::new("df") let r = App::new("df")
.arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV")) .arg(Arg::from("[arg] 'some opt'").env("CLP_TEST_ENV_POR"))
.try_get_matches_from(vec!["", "opt"]); .try_get_matches_from(vec!["", "opt"]);
assert!(r.is_ok()); assert!(r.is_ok());
@ -118,12 +118,12 @@ fn positionals_user_override() {
#[test] #[test]
fn multiple_one() { fn multiple_one() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_MO", "env");
let r = App::new("df") let r = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_MO")
.use_delimiter(true) .use_delimiter(true)
.multiple(true), .multiple(true),
) )
@ -183,12 +183,12 @@ fn multiple_no_delimiter() {
#[test] #[test]
fn possible_value() { fn possible_value() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_PV", "env");
let r = App::new("df") let r = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_PV")
.possible_value("env"), .possible_value("env"),
) )
.try_get_matches_from(vec![""]); .try_get_matches_from(vec![""]);
@ -202,12 +202,12 @@ fn possible_value() {
#[test] #[test]
fn not_possible_value() { fn not_possible_value() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_NPV", "env");
let r = App::new("df") let r = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_NPV")
.possible_value("never"), .possible_value("never"),
) )
.try_get_matches_from(vec![""]); .try_get_matches_from(vec![""]);
@ -217,12 +217,12 @@ fn not_possible_value() {
#[test] #[test]
fn validator() { fn validator() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_VDOR", "env");
let r = App::new("df") let r = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_VDOR")
.validator(|s| { .validator(|s| {
if s == "env" { if s == "env" {
Ok(()) Ok(())
@ -242,12 +242,12 @@ fn validator() {
#[test] #[test]
fn validator_output() { fn validator_output() {
env::set_var("CLP_TEST_ENV", "42"); env::set_var("CLP_TEST_ENV_VO", "42");
let m = App::new("df") let m = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_VO")
.validator(|s| s.parse::<i32>()), .validator(|s| s.parse::<i32>()),
) )
.get_matches_from(vec![""]); .get_matches_from(vec![""]);
@ -257,12 +257,12 @@ fn validator_output() {
#[test] #[test]
fn validator_invalid() { fn validator_invalid() {
env::set_var("CLP_TEST_ENV", "env"); env::set_var("CLP_TEST_ENV_IV", "env");
let r = App::new("df") let r = App::new("df")
.arg( .arg(
Arg::from("[arg] 'some opt'") Arg::from("[arg] 'some opt'")
.env("CLP_TEST_ENV") .env("CLP_TEST_ENV_IV")
.validator(|s| { .validator(|s| {
if s != "env" { if s != "env" {
Ok(()) Ok(())