2023-03-20 13:51:19 +00:00
|
|
|
use crate::common::util::TestScenario;
|
2020-05-02 14:54:29 +00:00
|
|
|
use std::env;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get_all() {
|
|
|
|
let key = "KEY";
|
|
|
|
env::set_var(key, "VALUE");
|
|
|
|
assert_eq!(env::var(key), Ok("VALUE".to_string()));
|
|
|
|
|
2021-04-17 23:28:06 +00:00
|
|
|
TestScenario::new(util_name!())
|
2023-01-25 02:40:39 +00:00
|
|
|
.ucmd()
|
|
|
|
.keep_env()
|
2021-04-17 23:28:06 +00:00
|
|
|
.succeeds()
|
|
|
|
.stdout_contains("HOME=")
|
|
|
|
.stdout_contains("KEY=VALUE");
|
2020-05-02 14:54:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get_var() {
|
|
|
|
let key = "KEY";
|
|
|
|
env::set_var(key, "VALUE");
|
|
|
|
assert_eq!(env::var(key), Ok("VALUE".to_string()));
|
|
|
|
|
|
|
|
let result = TestScenario::new(util_name!())
|
2023-01-25 02:40:39 +00:00
|
|
|
.ucmd()
|
|
|
|
.keep_env()
|
2020-05-02 14:54:29 +00:00
|
|
|
.arg("KEY")
|
2021-04-17 23:28:06 +00:00
|
|
|
.succeeds();
|
2020-05-02 14:54:29 +00:00
|
|
|
|
2021-04-17 23:28:06 +00:00
|
|
|
assert!(!result.stdout_str().is_empty());
|
2022-03-23 07:51:09 +00:00
|
|
|
assert_eq!(result.stdout_str().trim(), "VALUE");
|
2020-05-02 14:54:29 +00:00
|
|
|
}
|
2022-11-06 16:28:05 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_equal_var() {
|
|
|
|
let scene = TestScenario::new(util_name!());
|
|
|
|
// tested by gnu/tests/misc/printenv.sh
|
|
|
|
let result = scene.ucmd().env("a=b", "c").arg("a=b").fails();
|
|
|
|
|
|
|
|
assert!(result.stdout_str().is_empty());
|
|
|
|
}
|