coreutils/tests/by-util/test_printenv.rs

31 lines
690 B
Rust
Raw Normal View History

use crate::common::util::*;
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!())
.ucmd_keepenv()
.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!())
.ucmd_keepenv()
.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());
assert!(result.stdout_str().trim() == "VALUE");
2020-05-02 14:54:29 +00:00
}