2
0
Fork 0
mirror of https://github.com/uutils/coreutils synced 2024-12-24 20:13:17 +00:00
coreutils/test/env.rs

75 lines
1.9 KiB
Rust
Raw Normal View History

use std::process::Command;
use std::str;
static PROGNAME: &'static str = "./env";
#[test]
fn test_single_name_value_pair() {
let po = Command::new(PROGNAME)
.arg("FOO=bar")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert!(out.lines_any().any(|line| line == "FOO=bar"));
}
#[test]
fn test_multiple_name_value_pairs() {
let po = Command::new(PROGNAME)
.arg("FOO=bar")
.arg("ABC=xyz")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out.lines_any().filter(|&line| line == "FOO=bar" || line == "ABC=xyz").count(), 2);
}
#[test]
fn test_ignore_environment() {
let po = Command::new(PROGNAME)
.arg("-i")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "");
2015-05-26 21:49:50 +00:00
let po = Command::new(PROGNAME)
.arg("-")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "");
}
#[test]
fn test_null_delimiter() {
let po = Command::new(PROGNAME)
.arg("-i")
.arg("--null")
.arg("FOO=bar")
.arg("ABC=xyz")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out, "FOO=bar\0ABC=xyz\0");
}
#[test]
fn test_unset_variable() {
// This test depends on the HOME variable being pre-defined by the
// default shell
let po = Command::new(PROGNAME)
.arg("-u")
.arg("HOME")
.output()
.unwrap_or_else(|err| panic!("{}", err));
let out = str::from_utf8(&po.stdout[..]).unwrap();
assert_eq!(out.lines_any().any(|line| line.starts_with("HOME=")), false);
}