2015-11-16 05:25:01 +00:00
|
|
|
use common::util::*;
|
|
|
|
|
2017-10-28 14:32:50 +00:00
|
|
|
#[test]
|
|
|
|
fn test_env_help() {
|
2019-05-13 11:01:39 +00:00
|
|
|
assert!(new_ucmd!().arg("--help").succeeds().no_stderr().stdout.contains("OPTIONS:"));
|
2017-10-28 14:32:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_env_version() {
|
|
|
|
assert!(new_ucmd!().arg("--version").succeeds().no_stderr().stdout.contains(util_name!()));
|
|
|
|
}
|
|
|
|
|
2018-11-19 08:22:13 +00:00
|
|
|
#[test]
|
|
|
|
fn test_echo() {
|
|
|
|
// assert!(new_ucmd!().arg("printf").arg("FOO-bar").succeeds().no_stderr().stdout.contains("FOO-bar"));
|
|
|
|
let mut cmd = new_ucmd!();
|
|
|
|
cmd.arg("echo").arg("FOO-bar");
|
|
|
|
println!("cmd={:?}", cmd);
|
|
|
|
|
|
|
|
let result = cmd.run();
|
|
|
|
println!("success={:?}", result.success);
|
|
|
|
println!("stdout={:?}", result.stdout);
|
|
|
|
println!("stderr={:?}", result.stderr);
|
|
|
|
assert!(result.success);
|
|
|
|
|
2019-05-13 05:42:20 +00:00
|
|
|
let out = result.stdout.trim_end();
|
2018-11-19 08:22:13 +00:00
|
|
|
|
|
|
|
assert_eq!(out, "FOO-bar");
|
|
|
|
}
|
|
|
|
|
2019-04-28 15:19:14 +00:00
|
|
|
#[test]
|
|
|
|
fn test_file_option() {
|
|
|
|
let out = new_ucmd!()
|
|
|
|
.arg("-f").arg("vars.conf.txt")
|
|
|
|
.run().stdout;
|
|
|
|
|
|
|
|
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "BAR=bamf this").count(), 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_combined_file_set() {
|
|
|
|
let out = new_ucmd!()
|
|
|
|
.arg("-f").arg("vars.conf.txt")
|
|
|
|
.arg("FOO=bar.alt")
|
|
|
|
.run().stdout;
|
|
|
|
|
|
|
|
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_combined_file_set_unset() {
|
|
|
|
let out = new_ucmd!()
|
|
|
|
.arg("-u").arg("BAR")
|
|
|
|
.arg("-f").arg("vars.conf.txt")
|
|
|
|
.arg("FOO=bar.alt")
|
|
|
|
.run().stdout;
|
|
|
|
|
|
|
|
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt" || line.starts_with("BAR=")).count(), 1);
|
|
|
|
}
|
|
|
|
|
2015-11-16 05:25:01 +00:00
|
|
|
#[test]
|
|
|
|
fn test_single_name_value_pair() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let out = new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg("FOO=bar").run().stdout;
|
2015-11-16 05:25:01 +00:00
|
|
|
|
|
|
|
assert!(out.lines().any(|line| line == "FOO=bar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_multiple_name_value_pairs() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let out = new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg("FOO=bar")
|
2015-11-16 05:25:01 +00:00
|
|
|
.arg("ABC=xyz")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
|
|
|
assert_eq!(out.lines().filter(|&line| line == "FOO=bar" || line == "ABC=xyz").count(),
|
|
|
|
2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_ignore_environment() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let scene = TestScenario::new(util_name!());
|
2015-11-16 05:25:01 +00:00
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let out = scene.ucmd()
|
2015-11-16 05:25:01 +00:00
|
|
|
.arg("-i")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
|
|
|
assert_eq!(out, "");
|
|
|
|
|
2016-07-29 21:26:32 +00:00
|
|
|
let out = scene.ucmd()
|
2015-11-16 05:25:01 +00:00
|
|
|
.arg("-")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
|
|
|
assert_eq!(out, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_null_delimiter() {
|
2016-08-23 11:52:43 +00:00
|
|
|
let out = new_ucmd!()
|
2016-07-29 21:26:32 +00:00
|
|
|
.arg("-i")
|
2015-11-16 05:25:01 +00:00
|
|
|
.arg("--null")
|
|
|
|
.arg("FOO=bar")
|
|
|
|
.arg("ABC=xyz")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
2015-12-22 11:44:05 +00:00
|
|
|
let mut vars : Vec<_> = out.split('\0').collect();
|
|
|
|
assert_eq!(vars.len(), 3);
|
|
|
|
vars.sort();
|
|
|
|
assert_eq!(vars[0], "");
|
|
|
|
assert_eq!(vars[1], "ABC=xyz");
|
|
|
|
assert_eq!(vars[2], "FOO=bar");
|
2015-11-16 05:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_unset_variable() {
|
|
|
|
// This test depends on the HOME variable being pre-defined by the
|
|
|
|
// default shell
|
2016-08-23 11:52:43 +00:00
|
|
|
let out = TestScenario::new(util_name!())
|
2016-07-29 21:26:32 +00:00
|
|
|
.ucmd_keepenv()
|
2015-11-16 05:25:01 +00:00
|
|
|
.arg("-u")
|
|
|
|
.arg("HOME")
|
|
|
|
.run()
|
|
|
|
.stdout;
|
|
|
|
|
|
|
|
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
|
|
|
|
}
|
2019-04-28 09:12:37 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_fail_null_with_program() {
|
|
|
|
let out = new_ucmd!().arg("--null").arg("cd").fails().stderr;
|
|
|
|
assert!(out.contains("cannot specify --null (-0) with command"));
|
|
|
|
}
|