1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Fix some tests to not use CmdResult fields

This commit is contained in:
Gilad Naaman 2021-04-05 23:03:43 +03:00
parent 4695667c7c
commit 81d42aa2b3
22 changed files with 353 additions and 478 deletions

View file

@ -2,17 +2,13 @@ use crate::common::util::*;
#[test] #[test]
fn test_arch() { fn test_arch() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!().succeeds();
let result = ucmd.run();
assert!(result.success);
} }
#[test] #[test]
fn test_arch_help() { fn test_arch_help() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("--help")
let result = ucmd.arg("--help").run(); .succeeds()
assert!(result.success); .stdout_contains("architecture name");
assert!(result.stdout.contains("architecture name"));
} }

View file

@ -66,7 +66,7 @@ fn test_zero_param() {
} }
fn expect_error(input: Vec<&str>) { fn expect_error(input: Vec<&str>) {
assert!(new_ucmd!().args(&input).fails().no_stdout().stderr.len() > 0); assert!(new_ucmd!().args(&input).fails().no_stdout().stderr().len() > 0);
} }
#[test] #[test]

View file

@ -149,7 +149,7 @@ fn test_big_h() {
.arg("bin") .arg("bin")
.arg("/proc/self/fd") .arg("/proc/self/fd")
.fails() .fails()
.stderr .stderr_str()
.lines() .lines()
.fold(0, |acc, _| acc + 1) .fold(0, |acc, _| acc + 1)
> 1 > 1

View file

@ -48,7 +48,7 @@ fn run_single_test(test: &TestCase, at: AtPath, mut ucmd: UCommand) {
} }
let r = ucmd.run(); let r = ucmd.run();
if !r.success { if !r.success {
println!("{}", r.stderr); println!("{}", r.stderr_str());
panic!("{:?}: failed", ucmd.raw); panic!("{:?}: failed", ucmd.raw);
} }
@ -297,13 +297,14 @@ fn test_chmod_recursive() {
mkfile(&at.plus_as_string("a/b/c/c"), 0o100444); mkfile(&at.plus_as_string("a/b/c/c"), 0o100444);
mkfile(&at.plus_as_string("z/y"), 0o100444); mkfile(&at.plus_as_string("z/y"), 0o100444);
let result = ucmd ucmd.arg("-R")
.arg("-R")
.arg("--verbose") .arg("--verbose")
.arg("-r,a+w") .arg("-r,a+w")
.arg("a") .arg("a")
.arg("z") .arg("z")
.succeeds(); .succeeds()
.stderr_contains(&"to 333 (-wx-wx-wx)")
.stderr_contains(&"to 222 (-w--w--w-)");
assert_eq!(at.metadata("z/y").permissions().mode(), 0o100222); assert_eq!(at.metadata("z/y").permissions().mode(), 0o100222);
assert_eq!(at.metadata("a/a").permissions().mode(), 0o100222); assert_eq!(at.metadata("a/a").permissions().mode(), 0o100222);
@ -312,8 +313,6 @@ fn test_chmod_recursive() {
println!("mode {:o}", at.metadata("a").permissions().mode()); println!("mode {:o}", at.metadata("a").permissions().mode());
assert_eq!(at.metadata("a").permissions().mode(), 0o40333); assert_eq!(at.metadata("a").permissions().mode(), 0o40333);
assert_eq!(at.metadata("z").permissions().mode(), 0o40333); assert_eq!(at.metadata("z").permissions().mode(), 0o40333);
assert!(result.stderr.contains("to 333 (-wx-wx-wx)"));
assert!(result.stderr.contains("to 222 (-w--w--w-)"));
unsafe { unsafe {
umask(original_umask); umask(original_umask);
@ -322,30 +321,24 @@ fn test_chmod_recursive() {
#[test] #[test]
fn test_chmod_non_existing_file() { fn test_chmod_non_existing_file() {
let (_at, mut ucmd) = at_and_ucmd!(); new_ucmd!()
let result = ucmd
.arg("-R") .arg("-R")
.arg("--verbose") .arg("--verbose")
.arg("-r,a+w") .arg("-r,a+w")
.arg("dont-exist") .arg("dont-exist")
.fails(); .fails()
assert!(result .stderr_contains(&"cannot access 'dont-exist': No such file or directory");
.stderr
.contains("cannot access 'dont-exist': No such file or directory"));
} }
#[test] #[test]
fn test_chmod_preserve_root() { fn test_chmod_preserve_root() {
let (_at, mut ucmd) = at_and_ucmd!(); new_ucmd!()
let result = ucmd
.arg("-R") .arg("-R")
.arg("--preserve-root") .arg("--preserve-root")
.arg("755") .arg("755")
.arg("/") .arg("/")
.fails(); .fails()
assert!(result .stderr_contains(&"chmod: error: it is dangerous to operate recursively on '/'");
.stderr
.contains("chmod: error: it is dangerous to operate recursively on '/'"));
} }
#[test] #[test]
@ -362,33 +355,27 @@ fn test_chmod_symlink_non_existing_file() {
let expected_stderr = &format!("cannot operate on dangling symlink '{}'", test_symlink); let expected_stderr = &format!("cannot operate on dangling symlink '{}'", test_symlink);
at.symlink_file(non_existing, test_symlink); at.symlink_file(non_existing, test_symlink);
let mut result;
// this cannot succeed since the symbolic link dangles // this cannot succeed since the symbolic link dangles
result = scene.ucmd().arg("755").arg("-v").arg(test_symlink).fails(); scene.ucmd()
.arg("755")
println!("stdout = {:?}", result.stdout); .arg("-v")
println!("stderr = {:?}", result.stderr); .arg(test_symlink)
.fails()
assert!(result.stdout.contains(expected_stdout)); .code_is(1)
assert!(result.stderr.contains(expected_stderr)); .stdout_contains(expected_stdout)
assert_eq!(result.code, Some(1)); .stderr_contains(expected_stderr);
// this should be the same than with just '-v' but without stderr // this should be the same than with just '-v' but without stderr
result = scene scene.ucmd()
.ucmd()
.arg("755") .arg("755")
.arg("-v") .arg("-v")
.arg("-f") .arg("-f")
.arg(test_symlink) .arg(test_symlink)
.fails(); .run()
.code_is(1)
println!("stdout = {:?}", result.stdout); .no_stderr()
println!("stderr = {:?}", result.stderr); .stdout_contains(expected_stdout);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.is_empty());
assert_eq!(result.code, Some(1));
} }
#[test] #[test]
@ -405,18 +392,15 @@ fn test_chmod_symlink_non_existing_file_recursive() {
non_existing, non_existing,
&format!("{}/{}", test_directory, test_symlink), &format!("{}/{}", test_directory, test_symlink),
); );
let mut result;
// this should succeed // this should succeed
result = scene scene.ucmd()
.ucmd()
.arg("-R") .arg("-R")
.arg("755") .arg("755")
.arg(test_directory) .arg(test_directory)
.succeeds(); .succeeds()
assert_eq!(result.code, Some(0)); .no_stderr()
assert!(result.stdout.is_empty()); .no_stdout();
assert!(result.stderr.is_empty());
let expected_stdout = &format!( let expected_stdout = &format!(
"mode of '{}' retained as 0755 (rwxr-xr-x)\nneither symbolic link '{}/{}' nor referent has been changed", "mode of '{}' retained as 0755 (rwxr-xr-x)\nneither symbolic link '{}/{}' nor referent has been changed",
@ -424,37 +408,25 @@ fn test_chmod_symlink_non_existing_file_recursive() {
); );
// '-v': this should succeed without stderr // '-v': this should succeed without stderr
result = scene scene.ucmd()
.ucmd()
.arg("-R") .arg("-R")
.arg("-v") .arg("-v")
.arg("755") .arg("755")
.arg(test_directory) .arg(test_directory)
.succeeds(); .succeeds()
.stdout_contains(expected_stdout)
println!("stdout = {:?}", result.stdout); .no_stderr();
println!("stderr = {:?}", result.stderr);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.is_empty());
assert_eq!(result.code, Some(0));
// '-vf': this should be the same than with just '-v' // '-vf': this should be the same than with just '-v'
result = scene scene.ucmd()
.ucmd()
.arg("-R") .arg("-R")
.arg("-v") .arg("-v")
.arg("-f") .arg("-f")
.arg("755") .arg("755")
.arg(test_directory) .arg(test_directory)
.succeeds(); .succeeds()
.stdout_contains(expected_stdout)
println!("stdout = {:?}", result.stdout); .no_stderr();
println!("stderr = {:?}", result.stderr);
assert!(result.stdout.contains(expected_stdout));
assert!(result.stderr.is_empty());
assert_eq!(result.code, Some(0));
} }
#[test] #[test]

View file

@ -53,22 +53,22 @@ fn test_chown_myself() {
// test chown username file.txt // test chown username file.txt
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("results {}", result.stdout); println!("results {}", result.stdout_str());
let username = result.stdout.trim_end(); let username = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
at.touch(file1); at.touch(file1);
let result = ucmd.arg(username).arg(file1).run(); let result = ucmd.arg(username).arg(file1).run();
println!("results stdout {}", result.stdout); println!("results stdout {}", result.stdout_str());
println!("results stderr {}", result.stderr); println!("results stderr {}", result.stderr_str());
if is_ci() && result.stderr.contains("invalid user") { if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id. // In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
@ -81,24 +81,24 @@ fn test_chown_myself_second() {
// test chown username: file.txt // test chown username: file.txt
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("results {}", result.stdout); println!("results {}", result.stdout_str());
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
at.touch(file1); at.touch(file1);
let result = ucmd let result = ucmd
.arg(result.stdout.trim_end().to_owned() + ":") .arg(result.stdout_str().trim_end().to_owned() + ":")
.arg(file1) .arg(file1)
.run(); .run();
println!("result.stdout = {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
assert!(result.success); assert!(result.success);
} }
@ -107,31 +107,31 @@ fn test_chown_myself_group() {
// test chown username:group file.txt // test chown username:group file.txt
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("user name = {}", result.stdout); println!("user name = {}", result.stdout_str());
let username = result.stdout.trim_end(); let username = result.stdout_str().trim_end();
let result = scene.cmd("id").arg("-gn").run(); let result = scene.cmd("id").arg("-gn").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("group name = {}", result.stdout); println!("group name = {}", result.stdout_str());
let group = result.stdout.trim_end(); let group = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
let perm = username.to_owned() + ":" + group; let perm = username.to_owned() + ":" + group;
at.touch(file1); at.touch(file1);
let result = ucmd.arg(perm).arg(file1).run(); let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout = {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("chown: invalid group:") { if is_ci() && result.stderr_str().contains("chown: invalid group:") {
// With some Ubuntu into the CI, we can get this answer // With some Ubuntu into the CI, we can get this answer
return; return;
} }
@ -143,27 +143,27 @@ fn test_chown_only_group() {
// test chown :group file.txt // test chown :group file.txt
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("results {}", result.stdout); println!("results {}", result.stdout_str());
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
let perm = ":".to_owned() + result.stdout.trim_end(); let perm = ":".to_owned() + result.stdout_str().trim_end();
at.touch(file1); at.touch(file1);
let result = ucmd.arg(perm).arg(file1).run(); let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout = {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("Operation not permitted") { if is_ci() && result.stderr_str().contains("Operation not permitted") {
// With ubuntu with old Rust in the CI, we can get an error // With ubuntu with old Rust in the CI, we can get an error
return; return;
} }
if is_ci() && result.stderr.contains("chown: invalid group:") { if is_ci() && result.stderr_str().contains("chown: invalid group:") {
// With mac into the CI, we can get this answer // With mac into the CI, we can get this answer
return; return;
} }
@ -174,14 +174,14 @@ fn test_chown_only_group() {
fn test_chown_only_id() { fn test_chown_only_id() {
// test chown 1111 file.txt // test chown 1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout = {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let id = String::from(result.stdout.trim()); let id = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
@ -189,9 +189,9 @@ fn test_chown_only_id() {
at.touch(file1); at.touch(file1);
let result = ucmd.arg(id).arg(file1).run(); let result = ucmd.arg(id).arg(file1).run();
println!("result.stdout = {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("chown: invalid user:") { if is_ci() && result.stderr_str().contains("chown: invalid user:") {
// With some Ubuntu into the CI, we can get this answer // With some Ubuntu into the CI, we can get this answer
return; return;
} }
@ -202,14 +202,14 @@ fn test_chown_only_id() {
fn test_chown_only_group_id() { fn test_chown_only_group_id() {
// test chown :1111 file.txt // test chown :1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let id = String::from(result.stdout.trim()); let id = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
@ -219,9 +219,9 @@ fn test_chown_only_group_id() {
let result = ucmd.arg(perm).arg(file1).run(); let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout = {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("chown: invalid group:") { if is_ci() && result.stderr_str().contains("chown: invalid group:") {
// With mac into the CI, we can get this answer // With mac into the CI, we can get this answer
return; return;
} }
@ -232,24 +232,24 @@ fn test_chown_only_group_id() {
fn test_chown_both_id() { fn test_chown_both_id() {
// test chown 1111:1111 file.txt // test chown 1111:1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let id_user = String::from(result.stdout.trim()); let id_user = String::from(result.stdout_str().trim());
let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-g").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let id_group = String::from(result.stdout.trim()); let id_group = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
@ -258,10 +258,10 @@ fn test_chown_both_id() {
let perm = id_user + &":".to_owned() + &id_group; let perm = id_user + &":".to_owned() + &id_group;
let result = ucmd.arg(perm).arg(file1).run(); let result = ucmd.arg(perm).arg(file1).run();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("invalid user") { if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id. // In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
@ -274,24 +274,24 @@ fn test_chown_both_id() {
fn test_chown_both_mix() { fn test_chown_both_mix() {
// test chown 1111:1111 file.txt // test chown 1111:1111 file.txt
let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-u").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let id_user = String::from(result.stdout.trim()); let id_user = String::from(result.stdout_str().trim());
let result = TestScenario::new("id").ucmd_keepenv().arg("-gn").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-gn").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let group_name = String::from(result.stdout.trim()); let group_name = String::from(result.stdout_str().trim());
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
let file1 = "test_install_target_dir_file_a1"; let file1 = "test_install_target_dir_file_a1";
@ -301,7 +301,7 @@ fn test_chown_both_mix() {
let result = ucmd.arg(perm).arg(file1).run(); let result = ucmd.arg(perm).arg(file1).run();
if is_ci() && result.stderr.contains("invalid user") { if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id. // In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
@ -313,14 +313,14 @@ fn test_chown_both_mix() {
fn test_chown_recursive() { fn test_chown_recursive() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let username = result.stdout.trim_end(); let username = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a"); at.mkdir("a");
@ -339,31 +339,32 @@ fn test_chown_recursive() {
.arg("a") .arg("a")
.arg("z") .arg("z")
.run(); .run();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("invalid user") { if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id. // In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
assert!(result.stderr.contains("ownership of 'a/a' retained as")); result
assert!(result.stderr.contains("ownership of 'z/y' retained as")); .stderr_contains(&"ownership of 'a/a' retained as")
assert!(result.success); .stderr_contains(&"ownership of 'z/y' retained as")
.success();
} }
#[test] #[test]
fn test_root_preserve() { fn test_root_preserve() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr_str().contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let username = result.stdout.trim_end(); let username = result.stdout_str().trim_end();
let result = new_ucmd!() let result = new_ucmd!()
.arg("--preserve-root") .arg("--preserve-root")
@ -371,9 +372,9 @@ fn test_root_preserve() {
.arg(username) .arg(username)
.arg("/") .arg("/")
.fails(); .fails();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("invalid user") { if is_ci() && result.stderr_str().contains("invalid user") {
// In the CI, some server are failing to return id. // In the CI, some server are failing to return id.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;

View file

@ -64,14 +64,14 @@ fn test_preference_of_userspec() {
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let username = result.stdout.trim_end(); let username = result.stdout_str().trim_end();
let ts = TestScenario::new("id"); let ts = TestScenario::new("id");
let result = ts.cmd("id").arg("-g").arg("-n").run(); let result = ts.cmd("id").arg("-g").arg("-n").run();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
if is_ci() && result.stderr.contains("cannot find name for user ID") { if is_ci() && result.stderr.contains("cannot find name for user ID") {
// In the CI, some server are failing to return id. // In the CI, some server are failing to return id.
@ -79,7 +79,7 @@ fn test_preference_of_userspec() {
return; return;
} }
let group_name = result.stdout.trim_end(); let group_name = result.stdout_str().trim_end();
let (at, mut ucmd) = at_and_ucmd!(); let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("a"); at.mkdir("a");
@ -93,6 +93,6 @@ fn test_preference_of_userspec() {
.arg(format!("--userspec={}:{}", username, group_name)) .arg(format!("--userspec={}:{}", username, group_name))
.run(); .run();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
} }

View file

@ -275,8 +275,8 @@ fn test_cp_arg_no_clobber_twice() {
.arg("dest.txt") .arg("dest.txt")
.run(); .run();
println!("stderr = {:?}", result.stderr); println!("stderr = {:?}", result.stderr_str());
println!("stdout = {:?}", result.stdout); println!("stdout = {:?}", result.stdout_str());
assert!(result.success); assert!(result.success);
assert!(result.stderr.is_empty()); assert!(result.stderr.is_empty());
assert_eq!(at.read("source.txt"), ""); assert_eq!(at.read("source.txt"), "");
@ -317,8 +317,8 @@ fn test_cp_arg_force() {
.arg(TEST_HELLO_WORLD_DEST) .arg(TEST_HELLO_WORLD_DEST)
.run(); .run();
println!("{:?}", result.stderr); println!("{:?}", result.stderr_str());
println!("{:?}", result.stdout); println!("{:?}", result.stdout_str());
assert!(result.success); assert!(result.success);
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n"); assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
@ -602,7 +602,7 @@ fn test_cp_deref_folder_to_folder() {
.arg(TEST_COPY_FROM_FOLDER) .arg(TEST_COPY_FROM_FOLDER)
.arg(TEST_COPY_TO_FOLDER_NEW) .arg(TEST_COPY_TO_FOLDER_NEW)
.run(); .run();
println!("cp output {}", result.stdout); println!("cp output {}", result.stdout_str());
// Check that the exit code represents a successful copy. // Check that the exit code represents a successful copy.
assert!(result.success); assert!(result.success);
@ -611,12 +611,12 @@ fn test_cp_deref_folder_to_folder() {
{ {
let scene2 = TestScenario::new("ls"); let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run(); let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls source {}", result.stdout); println!("ls source {}", result.stdout_str());
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW); let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run(); let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
} }
#[cfg(windows)] #[cfg(windows)]
@ -706,7 +706,7 @@ fn test_cp_no_deref_folder_to_folder() {
.arg(TEST_COPY_FROM_FOLDER) .arg(TEST_COPY_FROM_FOLDER)
.arg(TEST_COPY_TO_FOLDER_NEW) .arg(TEST_COPY_TO_FOLDER_NEW)
.run(); .run();
println!("cp output {}", result.stdout); println!("cp output {}", result.stdout_str());
// Check that the exit code represents a successful copy. // Check that the exit code represents a successful copy.
assert!(result.success); assert!(result.success);
@ -715,12 +715,12 @@ fn test_cp_no_deref_folder_to_folder() {
{ {
let scene2 = TestScenario::new("ls"); let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run(); let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls source {}", result.stdout); println!("ls source {}", result.stdout_str());
let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW); let path_to_new_symlink = at.subdir.join(TEST_COPY_TO_FOLDER_NEW);
let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run(); let result = scene2.cmd("ls").arg("-al").arg(path_to_new_symlink).run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
} }
#[cfg(windows)] #[cfg(windows)]
@ -809,7 +809,7 @@ fn test_cp_archive() {
let scene2 = TestScenario::new("ls"); let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run(); let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
assert_eq!(creation, creation2); assert_eq!(creation, creation2);
assert!(result.success); assert!(result.success);
} }
@ -863,7 +863,7 @@ fn test_cp_archive_recursive() {
.arg(&at.subdir.join(TEST_COPY_TO_FOLDER)) .arg(&at.subdir.join(TEST_COPY_TO_FOLDER))
.run(); .run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
let scene2 = TestScenario::new("ls"); let scene2 = TestScenario::new("ls");
let result = scene2 let result = scene2
@ -872,7 +872,7 @@ fn test_cp_archive_recursive() {
.arg(&at.subdir.join(TEST_COPY_TO_FOLDER_NEW)) .arg(&at.subdir.join(TEST_COPY_TO_FOLDER_NEW))
.run(); .run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
assert!(at.file_exists( assert!(at.file_exists(
&at.subdir &at.subdir
.join(TEST_COPY_TO_FOLDER_NEW) .join(TEST_COPY_TO_FOLDER_NEW)
@ -946,7 +946,7 @@ fn test_cp_preserve_timestamps() {
let scene2 = TestScenario::new("ls"); let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run(); let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
assert_eq!(creation, creation2); assert_eq!(creation, creation2);
assert!(result.success); assert!(result.success);
} }
@ -984,7 +984,7 @@ fn test_cp_dont_preserve_timestamps() {
let scene2 = TestScenario::new("ls"); let scene2 = TestScenario::new("ls");
let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run(); let result = scene2.cmd("ls").arg("-al").arg(at.subdir).run();
println!("ls dest {}", result.stdout); println!("ls dest {}", result.stdout_str());
println!("creation {:?} / {:?}", creation, creation2); println!("creation {:?} / {:?}", creation, creation2);
assert_ne!(creation, creation2); assert_ne!(creation, creation2);

View file

@ -28,13 +28,13 @@ fn test_date_rfc_3339() {
// Check that the output matches the regexp // Check that the output matches the regexp
let rfc_regexp = r"(\d+)-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])\s([01]\d|2[0-3]):([0-5]\d):([0-5]\d|60)(\.\d+)?(([Zz])|([\+|\-]([01]\d|2[0-3])))"; let rfc_regexp = r"(\d+)-(0[1-9]|1[012])-(0[1-9]|[12]\d|3[01])\s([01]\d|2[0-3]):([0-5]\d):([0-5]\d|60)(\.\d+)?(([Zz])|([\+|\-]([01]\d|2[0-3])))";
let re = Regex::new(rfc_regexp).unwrap(); let re = Regex::new(rfc_regexp).unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("--rfc-3339=seconds").succeeds(); result = scene.ucmd().arg("--rfc-3339=seconds").succeeds();
// Check that the output matches the regexp // Check that the output matches the regexp
let re = Regex::new(rfc_regexp).unwrap(); let re = Regex::new(rfc_regexp).unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
} }
#[test] #[test]
@ -73,13 +73,13 @@ fn test_date_format_y() {
assert!(result.success); assert!(result.success);
let mut re = Regex::new(r"^\d{4}$").unwrap(); let mut re = Regex::new(r"^\d{4}$").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%y").succeeds(); result = scene.ucmd().arg("+%y").succeeds();
assert!(result.success); assert!(result.success);
re = Regex::new(r"^\d{2}$").unwrap(); re = Regex::new(r"^\d{2}$").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
} }
#[test] #[test]
@ -90,13 +90,13 @@ fn test_date_format_m() {
assert!(result.success); assert!(result.success);
let mut re = Regex::new(r"\S+").unwrap(); let mut re = Regex::new(r"\S+").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%m").succeeds(); result = scene.ucmd().arg("+%m").succeeds();
assert!(result.success); assert!(result.success);
re = Regex::new(r"^\d{2}$").unwrap(); re = Regex::new(r"^\d{2}$").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
} }
#[test] #[test]
@ -107,20 +107,20 @@ fn test_date_format_day() {
assert!(result.success); assert!(result.success);
let mut re = Regex::new(r"\S+").unwrap(); let mut re = Regex::new(r"\S+").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%A").succeeds(); result = scene.ucmd().arg("+%A").succeeds();
assert!(result.success); assert!(result.success);
re = Regex::new(r"\S+").unwrap(); re = Regex::new(r"\S+").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
result = scene.ucmd().arg("+%u").succeeds(); result = scene.ucmd().arg("+%u").succeeds();
assert!(result.success); assert!(result.success);
re = Regex::new(r"^\d{1}$").unwrap(); re = Regex::new(r"^\d{1}$").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
} }
#[test] #[test]
@ -131,7 +131,7 @@ fn test_date_format_full_day() {
assert!(result.success); assert!(result.success);
let re = Regex::new(r"\S+ \d{4}-\d{2}-\d{2}").unwrap(); let re = Regex::new(r"\S+ \d{4}-\d{2}-\d{2}").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str().trim()));
} }
#[test] #[test]

View file

@ -7,10 +7,9 @@ const SUB_LINK: &str = "subdir/links/sublink.txt";
#[test] #[test]
fn test_du_basics() { fn test_du_basics() {
let (_at, mut ucmd) = at_and_ucmd!(); new_ucmd!()
let result = ucmd.run(); .succeeds()
assert!(result.success); .no_stderr();
assert_eq!(result.stderr, "");
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
fn _du_basics(s: String) { fn _du_basics(s: String) {
@ -22,7 +21,7 @@ fn _du_basics(s: String) {
assert_eq!(s, answer); assert_eq!(s, answer);
} }
#[cfg(not(target_vendor = "apple"))] #[cfg(not(target_vendor = "apple"))]
fn _du_basics(s: String) { fn _du_basics(s: &str) {
let answer = "28\t./subdir let answer = "28\t./subdir
8\t./subdir/deeper 8\t./subdir/deeper
16\t./subdir/links 16\t./subdir/links
@ -38,19 +37,19 @@ fn test_du_basics_subdir() {
let result = ucmd.arg(SUB_DIR).run(); let result = ucmd.arg(SUB_DIR).run();
assert!(result.success); assert!(result.success);
assert_eq!(result.stderr, ""); assert_eq!(result.stderr, "");
_du_basics_subdir(result.stdout); _du_basics_subdir(result.stdout_str());
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
fn _du_basics_subdir(s: String) { fn _du_basics_subdir(s: &str) {
assert_eq!(s, "4\tsubdir/deeper\n"); assert_eq!(s, "4\tsubdir/deeper\n");
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn _du_basics_subdir(s: String) { fn _du_basics_subdir(s: &str) {
assert_eq!(s, "0\tsubdir/deeper\n"); assert_eq!(s, "0\tsubdir/deeper\n");
} }
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))] #[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_basics_subdir(s: String) { fn _du_basics_subdir(s: &str) {
// MS-WSL linux has altered expected output // MS-WSL linux has altered expected output
if !is_wsl() { if !is_wsl() {
assert_eq!(s, "8\tsubdir/deeper\n"); assert_eq!(s, "8\tsubdir/deeper\n");
@ -64,7 +63,7 @@ fn test_du_basics_bad_name() {
let (_at, mut ucmd) = at_and_ucmd!(); let (_at, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg("bad_name").run(); let result = ucmd.arg("bad_name").run();
assert_eq!(result.stdout, ""); assert_eq!(result.stdout_str(), "");
assert_eq!( assert_eq!(
result.stderr, result.stderr,
"du: error: bad_name: No such file or directory\n" "du: error: bad_name: No such file or directory\n"
@ -81,20 +80,20 @@ fn test_du_soft_link() {
let result = ts.ucmd().arg(SUB_DIR_LINKS).run(); let result = ts.ucmd().arg(SUB_DIR_LINKS).run();
assert!(result.success); assert!(result.success);
assert_eq!(result.stderr, ""); assert_eq!(result.stderr, "");
_du_soft_link(result.stdout); _du_soft_link(result.stdout_str());
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
fn _du_soft_link(s: String) { fn _du_soft_link(s: &str) {
// 'macos' host variants may have `du` output variation for soft links // 'macos' host variants may have `du` output variation for soft links
assert!((s == "12\tsubdir/links\n") || (s == "16\tsubdir/links\n")); assert!((s == "12\tsubdir/links\n") || (s == "16\tsubdir/links\n"));
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn _du_soft_link(s: String) { fn _du_soft_link(s: &str) {
assert_eq!(s, "8\tsubdir/links\n"); assert_eq!(s, "8\tsubdir/links\n");
} }
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))] #[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_soft_link(s: String) { fn _du_soft_link(s: &str) {
// MS-WSL linux has altered expected output // MS-WSL linux has altered expected output
if !is_wsl() { if !is_wsl() {
assert_eq!(s, "16\tsubdir/links\n"); assert_eq!(s, "16\tsubdir/links\n");
@ -114,19 +113,19 @@ fn test_du_hard_link() {
assert!(result.success); assert!(result.success);
assert_eq!(result.stderr, ""); assert_eq!(result.stderr, "");
// We do not double count hard links as the inodes are identical // We do not double count hard links as the inodes are identical
_du_hard_link(result.stdout); _du_hard_link(result.stdout_str());
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
fn _du_hard_link(s: String) { fn _du_hard_link(s: &str) {
assert_eq!(s, "12\tsubdir/links\n") assert_eq!(s, "12\tsubdir/links\n")
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn _du_hard_link(s: String) { fn _du_hard_link(s: &str) {
assert_eq!(s, "8\tsubdir/links\n") assert_eq!(s, "8\tsubdir/links\n")
} }
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))] #[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_hard_link(s: String) { fn _du_hard_link(s: &str) {
// MS-WSL linux has altered expected output // MS-WSL linux has altered expected output
if !is_wsl() { if !is_wsl() {
assert_eq!(s, "16\tsubdir/links\n"); assert_eq!(s, "16\tsubdir/links\n");
@ -142,19 +141,19 @@ fn test_du_d_flag() {
let result = ts.ucmd().arg("-d").arg("1").run(); let result = ts.ucmd().arg("-d").arg("1").run();
assert!(result.success); assert!(result.success);
assert_eq!(result.stderr, ""); assert_eq!(result.stderr, "");
_du_d_flag(result.stdout); _du_d_flag(result.stdout_str());
} }
#[cfg(target_vendor = "apple")] #[cfg(target_vendor = "apple")]
fn _du_d_flag(s: String) { fn _du_d_flag(s: &str) {
assert_eq!(s, "16\t./subdir\n20\t./\n"); assert_eq!(s, "16\t./subdir\n20\t./\n");
} }
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
fn _du_d_flag(s: String) { fn _du_d_flag(s: &str) {
assert_eq!(s, "8\t./subdir\n8\t./\n"); assert_eq!(s, "8\t./subdir\n8\t./\n");
} }
#[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))] #[cfg(all(not(target_vendor = "apple"), not(target_os = "windows")))]
fn _du_d_flag(s: String) { fn _du_d_flag(s: &str) {
// MS-WSL linux has altered expected output // MS-WSL linux has altered expected output
if !is_wsl() { if !is_wsl() {
assert_eq!(s, "28\t./subdir\n36\t./\n"); assert_eq!(s, "28\t./subdir\n36\t./\n");
@ -167,10 +166,11 @@ fn _du_d_flag(s: String) {
fn test_du_h_flag_empty_file() { fn test_du_h_flag_empty_file() {
let ts = TestScenario::new("du"); let ts = TestScenario::new("du");
let result = ts.ucmd().arg("-h").arg("empty.txt").run(); ts.ucmd()
assert!(result.success); .arg("-h")
assert_eq!(result.stderr, ""); .arg("empty.txt")
assert_eq!(result.stdout, "0\tempty.txt\n"); .succeeds()
.stdout_only("0\tempty.txt\n");
} }
#[cfg(feature = "touch")] #[cfg(feature = "touch")]

View file

@ -2,22 +2,20 @@ use crate::common::util::*;
#[test] #[test]
fn test_default() { fn test_default() {
//CmdResult.stdout_only(...) trims trailing newlines new_ucmd!()
assert_eq!("hi\n", new_ucmd!().arg("hi").succeeds().no_stderr().stdout); .arg("hi")
.succeeds()
.stdout_only("hi\n");
} }
#[test] #[test]
fn test_no_trailing_newline() { fn test_no_trailing_newline() {
//CmdResult.stdout_only(...) trims trailing newlines
assert_eq!(
"hi",
new_ucmd!() new_ucmd!()
.arg("-n") .arg("-n")
.arg("hi") .arg("hi")
.succeeds() .succeeds()
.no_stderr() .no_stderr()
.stdout .stdout_only("hi");
);
} }
#[test] #[test]
@ -192,39 +190,38 @@ fn test_hyphen_values_inside_string() {
new_ucmd!() new_ucmd!()
.arg("'\"\n'CXXFLAGS=-g -O2'\n\"'") .arg("'\"\n'CXXFLAGS=-g -O2'\n\"'")
.succeeds() .succeeds()
.stdout .stdout_contains("CXXFLAGS");
.contains("CXXFLAGS");
} }
#[test] #[test]
fn test_hyphen_values_at_start() { fn test_hyphen_values_at_start() {
let result = new_ucmd!() new_ucmd!()
.arg("-E") .arg("-E")
.arg("-test") .arg("-test")
.arg("araba") .arg("araba")
.arg("-merci") .arg("-merci")
.run(); .run()
.success()
assert!(result.success); .stdout_does_not_contain("-E")
assert_eq!(false, result.stdout.contains("-E")); .stdout_is("-test araba -merci\n");
assert_eq!(result.stdout, "-test araba -merci\n");
} }
#[test] #[test]
fn test_hyphen_values_between() { fn test_hyphen_values_between() {
let result = new_ucmd!().arg("test").arg("-E").arg("araba").run(); new_ucmd!()
.arg("test")
.arg("-E")
.arg("araba")
.run()
.success()
.stdout_is("test -E araba\n");
assert!(result.success); new_ucmd!()
assert_eq!(result.stdout, "test -E araba\n");
let result = new_ucmd!()
.arg("dumdum ") .arg("dumdum ")
.arg("dum dum dum") .arg("dum dum dum")
.arg("-e") .arg("-e")
.arg("dum") .arg("dum")
.run(); .run()
.success()
assert!(result.success); .stdout_is("dumdum dum dum dum -e dum\n");
assert_eq!(result.stdout, "dumdum dum dum dum -e dum\n");
assert_eq!(true, result.stdout.contains("-e"));
} }

View file

@ -8,45 +8,35 @@ use tempfile::tempdir;
#[test] #[test]
fn test_env_help() { fn test_env_help() {
assert!(new_ucmd!() new_ucmd!()
.arg("--help") .arg("--help")
.succeeds() .succeeds()
.no_stderr() .no_stderr()
.stdout .stdout_contains("OPTIONS:");
.contains("OPTIONS:"));
} }
#[test] #[test]
fn test_env_version() { fn test_env_version() {
assert!(new_ucmd!() new_ucmd!()
.arg("--version") .arg("--version")
.succeeds() .succeeds()
.no_stderr() .no_stderr()
.stdout .stdout_contains(util_name!());
.contains(util_name!()));
} }
#[test] #[test]
fn test_echo() { fn test_echo() {
// assert!(new_ucmd!().arg("printf").arg("FOO-bar").succeeds().no_stderr().stdout.contains("FOO-bar")); let result = new_ucmd!()
let mut cmd = new_ucmd!(); .arg("echo")
cmd.arg("echo").arg("FOO-bar"); .arg("FOO-bar")
println!("cmd={:?}", cmd); .succeeds();
let result = cmd.run(); assert_eq!(result.stdout_str().trim(), "FOO-bar");
println!("success={:?}", result.success);
println!("stdout={:?}", result.stdout);
println!("stderr={:?}", result.stderr);
assert!(result.success);
let out = result.stdout.trim_end();
assert_eq!(out, "FOO-bar");
} }
#[test] #[test]
fn test_file_option() { fn test_file_option() {
let out = new_ucmd!().arg("-f").arg("vars.conf.txt").run().stdout; let out = new_ucmd!().arg("-f").arg("vars.conf.txt").run().stdout_move_str();
assert_eq!( assert_eq!(
out.lines() out.lines()
@ -63,7 +53,7 @@ fn test_combined_file_set() {
.arg("vars.conf.txt") .arg("vars.conf.txt")
.arg("FOO=bar.alt") .arg("FOO=bar.alt")
.run() .run()
.stdout; .stdout_move_str();
assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1); assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1);
} }
@ -76,8 +66,8 @@ fn test_combined_file_set_unset() {
.arg("-f") .arg("-f")
.arg("vars.conf.txt") .arg("vars.conf.txt")
.arg("FOO=bar.alt") .arg("FOO=bar.alt")
.run() .succeeds()
.stdout; .stdout_move_str();
assert_eq!( assert_eq!(
out.lines() out.lines()
@ -89,17 +79,17 @@ fn test_combined_file_set_unset() {
#[test] #[test]
fn test_single_name_value_pair() { fn test_single_name_value_pair() {
let out = new_ucmd!().arg("FOO=bar").run().stdout; let out = new_ucmd!().arg("FOO=bar").run();
assert!(out.lines().any(|line| line == "FOO=bar")); assert!(out.stdout_str().lines().any(|line| line == "FOO=bar"));
} }
#[test] #[test]
fn test_multiple_name_value_pairs() { fn test_multiple_name_value_pairs() {
let out = new_ucmd!().arg("FOO=bar").arg("ABC=xyz").run().stdout; let out = new_ucmd!().arg("FOO=bar").arg("ABC=xyz").run();
assert_eq!( assert_eq!(
out.lines() out.stdout_str().lines()
.filter(|&line| line == "FOO=bar" || line == "ABC=xyz") .filter(|&line| line == "FOO=bar" || line == "ABC=xyz")
.count(), .count(),
2 2
@ -110,13 +100,8 @@ fn test_multiple_name_value_pairs() {
fn test_ignore_environment() { fn test_ignore_environment() {
let scene = TestScenario::new(util_name!()); let scene = TestScenario::new(util_name!());
let out = scene.ucmd().arg("-i").run().stdout; scene.ucmd().arg("-i").run().no_stdout();
scene.ucmd().arg("-").run().no_stdout();
assert_eq!(out, "");
let out = scene.ucmd().arg("-").run().stdout;
assert_eq!(out, "");
} }
#[test] #[test]
@ -126,8 +111,8 @@ fn test_null_delimiter() {
.arg("--null") .arg("--null")
.arg("FOO=bar") .arg("FOO=bar")
.arg("ABC=xyz") .arg("ABC=xyz")
.run() .succeeds()
.stdout; .stdout_move_str();
let mut vars: Vec<_> = out.split('\0').collect(); let mut vars: Vec<_> = out.split('\0').collect();
assert_eq!(vars.len(), 3); assert_eq!(vars.len(), 3);
@ -145,8 +130,8 @@ fn test_unset_variable() {
.ucmd_keepenv() .ucmd_keepenv()
.arg("-u") .arg("-u")
.arg("HOME") .arg("HOME")
.run() .succeeds()
.stdout; .stdout_move_str();
assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false); assert_eq!(out.lines().any(|line| line.starts_with("HOME=")), false);
} }
@ -173,8 +158,8 @@ fn test_change_directory() {
.arg("--chdir") .arg("--chdir")
.arg(&temporary_path) .arg(&temporary_path)
.arg(pwd) .arg(pwd)
.run() .succeeds()
.stdout; .stdout_move_str();
assert_eq!(out.trim(), temporary_path.as_os_str()) assert_eq!(out.trim(), temporary_path.as_os_str())
} }
@ -193,8 +178,8 @@ fn test_change_directory() {
.ucmd() .ucmd()
.arg("--chdir") .arg("--chdir")
.arg(&temporary_path) .arg(&temporary_path)
.run() .succeeds()
.stdout; .stdout_move_str();
assert_eq!( assert_eq!(
out.lines() out.lines()
.any(|line| line.ends_with(temporary_path.file_name().unwrap().to_str().unwrap())), .any(|line| line.ends_with(temporary_path.file_name().unwrap().to_str().unwrap())),
@ -214,6 +199,6 @@ fn test_fail_change_directory() {
.arg(some_non_existing_path) .arg(some_non_existing_path)
.arg("pwd") .arg("pwd")
.fails() .fails()
.stderr; .stderr_move_str();
assert!(out.contains("env: cannot change directory to ")); assert!(out.contains("env: cannot change directory to "));
} }

View file

@ -2,57 +2,54 @@ use crate::common::util::*;
#[test] #[test]
fn test_with_tab() { fn test_with_tab() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("with-tab.txt")
let result = ucmd.arg("with-tab.txt").run(); .succeeds()
assert!(result.success); .stdout_contains(" ")
assert!(result.stdout.contains(" ")); .stdout_does_not_contain("\t");
assert!(!result.stdout.contains("\t"));
} }
#[test] #[test]
fn test_with_trailing_tab() { fn test_with_trailing_tab() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("with-trailing-tab.txt")
let result = ucmd.arg("with-trailing-tab.txt").run(); .succeeds()
assert!(result.success); .stdout_contains("with tabs=> ")
assert!(result.stdout.contains("with tabs=> ")); .stdout_does_not_contain("\t");
assert!(!result.stdout.contains("\t"));
} }
#[test] #[test]
fn test_with_trailing_tab_i() { fn test_with_trailing_tab_i() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("with-trailing-tab.txt")
let result = ucmd.arg("with-trailing-tab.txt").arg("-i").run(); .arg("-i")
assert!(result.success); .succeeds()
assert!(result.stdout.contains(" // with tabs=>\t")); .stdout_contains(" // with tabs=>\t");
} }
#[test] #[test]
fn test_with_tab_size() { fn test_with_tab_size() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("with-tab.txt")
let result = ucmd.arg("with-tab.txt").arg("--tabs=10").run(); .arg("--tabs=10")
assert!(result.success); .succeeds()
assert!(result.stdout.contains(" ")); .stdout_contains(" ");
} }
#[test] #[test]
fn test_with_space() { fn test_with_space() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("with-spaces.txt")
let result = ucmd.arg("with-spaces.txt").run(); .succeeds()
assert!(result.success); .stdout_contains(" return");
assert!(result.stdout.contains(" return"));
} }
#[test] #[test]
fn test_with_multiple_files() { fn test_with_multiple_files() {
let (_, mut ucmd) = at_and_ucmd!(); new_ucmd!()
.arg("with-spaces.txt")
let result = ucmd.arg("with-spaces.txt").arg("with-tab.txt").run(); .arg("with-tab.txt")
assert!(result.success); .succeeds()
assert!(result.stdout.contains(" return")); .stdout_contains(" return")
assert!(result.stdout.contains(" ")); .stdout_contains(" ");
} }

View file

@ -32,13 +32,10 @@ fn test_first_100000_integers() {
} }
println!("STDIN='{}'", instring); println!("STDIN='{}'", instring);
let result = new_ucmd!().pipe_in(instring.as_bytes()).run(); let result = new_ucmd!().pipe_in(instring.as_bytes()).succeeds();
let stdout = result.stdout;
assert!(result.success);
// `seq 0 100000 | factor | sha1sum` => "4ed2d8403934fa1c76fe4b84c5d4b8850299c359" // `seq 0 100000 | factor | sha1sum` => "4ed2d8403934fa1c76fe4b84c5d4b8850299c359"
let hash_check = sha1::Sha1::from(stdout.as_bytes()).hexdigest(); let hash_check = sha1::Sha1::from(result.stdout()).hexdigest();
assert_eq!(hash_check, "4ed2d8403934fa1c76fe4b84c5d4b8850299c359"); assert_eq!(hash_check, "4ed2d8403934fa1c76fe4b84c5d4b8850299c359");
} }

View file

@ -5,7 +5,7 @@ fn test_fmt() {
let result = new_ucmd!().arg("one-word-per-line.txt").run(); let result = new_ucmd!().arg("one-word-per-line.txt").run();
//.stdout_is_fixture("call_graph.expected"); //.stdout_is_fixture("call_graph.expected");
assert_eq!( assert_eq!(
result.stdout.trim(), result.stdout_str().trim(),
"this is a file with one word per line" "this is a file with one word per line"
); );
} }
@ -15,7 +15,7 @@ fn test_fmt_q() {
let result = new_ucmd!().arg("-q").arg("one-word-per-line.txt").run(); let result = new_ucmd!().arg("-q").arg("one-word-per-line.txt").run();
//.stdout_is_fixture("call_graph.expected"); //.stdout_is_fixture("call_graph.expected");
assert_eq!( assert_eq!(
result.stdout.trim(), result.stdout_str().trim(),
"this is a file with one word per line" "this is a file with one word per line"
); );
} }
@ -42,7 +42,7 @@ fn test_fmt_w() {
.arg("one-word-per-line.txt") .arg("one-word-per-line.txt")
.run(); .run();
//.stdout_is_fixture("call_graph.expected"); //.stdout_is_fixture("call_graph.expected");
assert_eq!(result.stdout.trim(), "this is a file with one word per line"); assert_eq!(result.stdout_str().trim(), "this is a file with one word per line");
} }

View file

@ -2,26 +2,25 @@ use crate::common::util::*;
#[test] #[test]
fn test_groups() { fn test_groups() {
let (_, mut ucmd) = at_and_ucmd!(); let result = new_ucmd!().run();
let result = ucmd.run(); println!("result.stdout = {}", result.stdout_str());
println!("result.stdout {}", result.stdout); println!("result.stderr = {}", result.stderr_str());
println!("result.stderr = {}", result.stderr); if is_ci() && result.stdout_str().trim().is_empty() {
if is_ci() && result.stdout.trim().is_empty() {
// In the CI, some server are failing to return the group. // In the CI, some server are failing to return the group.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
assert!(result.success); assert!(result.success);
assert!(!result.stdout.trim().is_empty()); assert!(!result.stdout_str().trim().is_empty());
} }
#[test] #[test]
fn test_groups_arg() { fn test_groups_arg() {
// get the username with the "id -un" command // get the username with the "id -un" command
let result = TestScenario::new("id").ucmd_keepenv().arg("-un").run(); let result = TestScenario::new("id").ucmd_keepenv().arg("-un").run();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
let s1 = String::from(result.stdout.trim()); let s1 = String::from(result.stdout_str().trim());
if is_ci() && s1.parse::<f64>().is_ok() { if is_ci() && s1.parse::<f64>().is_ok() {
// In the CI, some server are failing to return id -un. // In the CI, some server are failing to return id -un.
// So, if we are getting a uid, just skip this test // So, if we are getting a uid, just skip this test
@ -29,18 +28,18 @@ fn test_groups_arg() {
return; return;
} }
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
assert!(result.success); assert!(result.success);
assert!(!result.stdout.is_empty()); assert!(!result.stdout_str().is_empty());
let username = result.stdout.trim(); let username = result.stdout_str().trim();
// call groups with the user name to check that we // call groups with the user name to check that we
// are getting something // are getting something
let (_, mut ucmd) = at_and_ucmd!(); let (_, mut ucmd) = at_and_ucmd!();
let result = ucmd.arg(username).run(); let result = ucmd.arg(username).run();
println!("result.stdout {}", result.stdout); println!("result.stdout = {}", result.stdout_str());
println!("result.stderr = {}", result.stderr); println!("result.stderr = {}", result.stderr_str());
assert!(result.success); assert!(result.success);
assert!(!result.stdout.is_empty()); assert!(!result.stdout_str().is_empty());
} }

View file

@ -17,14 +17,14 @@ macro_rules! test_digest {
fn test_single_file() { fn test_single_file() {
let ts = TestScenario::new("hashsum"); let ts = TestScenario::new("hashsum");
assert_eq!(ts.fixtures.read(EXPECTED_FILE), assert_eq!(ts.fixtures.read(EXPECTED_FILE),
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("input.txt").succeeds().no_stderr().stdout)); get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).arg("input.txt").succeeds().no_stderr().stdout_str()));
} }
#[test] #[test]
fn test_stdin() { fn test_stdin() {
let ts = TestScenario::new("hashsum"); let ts = TestScenario::new("hashsum");
assert_eq!(ts.fixtures.read(EXPECTED_FILE), assert_eq!(ts.fixtures.read(EXPECTED_FILE),
get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout)); get_hash!(ts.ucmd().arg(DIGEST_ARG).arg(BITS_ARG).pipe_in_fixture("input.txt").succeeds().no_stderr().stdout_str()));
} }
} }
)*) )*)

View file

@ -9,5 +9,5 @@ fn test_normal() {
assert!(result.success); assert!(result.success);
let re = Regex::new(r"^[0-9a-f]{8}").unwrap(); let re = Regex::new(r"^[0-9a-f]{8}").unwrap();
assert!(re.is_match(&result.stdout.trim())); assert!(re.is_match(&result.stdout_str()));
} }

View file

@ -6,8 +6,8 @@ fn test_hostname() {
let ls_short_res = new_ucmd!().arg("-s").succeeds(); let ls_short_res = new_ucmd!().arg("-s").succeeds();
let ls_domain_res = new_ucmd!().arg("-d").succeeds(); let ls_domain_res = new_ucmd!().arg("-d").succeeds();
assert!(ls_default_res.stdout.len() >= ls_short_res.stdout.len()); assert!(ls_default_res.stdout().len() >= ls_short_res.stdout().len());
assert!(ls_default_res.stdout.len() >= ls_domain_res.stdout.len()); assert!(ls_default_res.stdout().len() >= ls_domain_res.stdout().len());
} }
// FixME: fails for "MacOS" // FixME: fails for "MacOS"
@ -17,14 +17,14 @@ fn test_hostname_ip() {
let result = new_ucmd!().arg("-i").run(); let result = new_ucmd!().arg("-i").run();
println!("{:#?}", result); println!("{:#?}", result);
assert!(result.success); assert!(result.success);
assert!(!result.stdout.trim().is_empty()); assert!(!result.stdout_str().trim().is_empty());
} }
#[test] #[test]
fn test_hostname_full() { fn test_hostname_full() {
let result = new_ucmd!().arg("-f").succeeds();
assert!(!result.stdout.trim().is_empty());
let ls_short_res = new_ucmd!().arg("-s").succeeds(); let ls_short_res = new_ucmd!().arg("-s").succeeds();
assert!(result.stdout.trim().contains(ls_short_res.stdout.trim())); assert!(!ls_short_res.stdout_str().trim().is_empty());
new_ucmd!().arg("-f").succeeds()
.stdout_contains(ls_short_res.stdout_str().trim());
} }

View file

@ -9,33 +9,29 @@ fn return_whoami_username() -> String {
return String::from(""); return String::from("");
} }
result.stdout.trim().to_string() result.stdout_str().trim().to_string()
} }
#[test] #[test]
fn test_id() { fn test_id() {
let scene = TestScenario::new(util_name!()); let result = new_ucmd!().arg("-u").run();
let mut result = scene.ucmd().arg("-u").run();
if result.stderr.contains("cannot find name for user ID") { if result.stderr.contains("cannot find name for user ID") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
assert!(result.success);
let uid = String::from(result.stdout.trim()); let uid = result.success().stdout_str().trim();
result = scene.ucmd().run(); let result = new_ucmd!().run();
if is_ci() && result.stderr.contains("cannot find name for user ID") { if is_ci() && result.stderr.contains("cannot find name for user ID") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr); if !result.stderr_str().contains("Could not find uid") {
if !result.stderr.contains("Could not find uid") {
// Verify that the id found by --user/-u exists in the list // Verify that the id found by --user/-u exists in the list
assert!(result.stdout.contains(&uid)); result.success().stdout_contains(&uid);
} }
} }
@ -47,88 +43,64 @@ fn test_id_from_name() {
return; return;
} }
let scene = TestScenario::new(util_name!()); let result = new_ucmd!().arg(&username).succeeds();
let result = scene.ucmd().arg(&username).succeeds(); let uid = result.stdout_str().trim();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr); new_ucmd!().succeeds()
assert!(result.success);
let uid = String::from(result.stdout.trim());
let result = scene.ucmd().succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
// Verify that the id found by --user/-u exists in the list // Verify that the id found by --user/-u exists in the list
assert!(result.stdout.contains(&uid)); .stdout_contains(uid)
// Verify that the username found by whoami exists in the list // Verify that the username found by whoami exists in the list
assert!(result.stdout.contains(&username)); .stdout_contains(username);
} }
#[test] #[test]
fn test_id_name_from_id() { fn test_id_name_from_id() {
let mut scene = TestScenario::new(util_name!()); let result = new_ucmd!().arg("-u").succeeds();
let result = scene.ucmd().arg("-u").run(); let uid = result.stdout_str().trim();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let uid = String::from(result.stdout.trim());
scene = TestScenario::new(util_name!()); let result = new_ucmd!().arg("-nu").arg(uid).run();
let result = scene.ucmd().arg("-nu").arg(uid).run();
if is_ci() && result.stderr.contains("No such user/group") { if is_ci() && result.stderr.contains("No such user/group") {
// In the CI, some server are failing to return whoami. // In the CI, some server are failing to return whoami.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let username_id = String::from(result.stdout.trim()); let username_id = result
.success()
.stdout_str()
.trim();
scene = TestScenario::new("whoami"); let scene = TestScenario::new("whoami");
let result = scene.cmd("whoami").run(); let result = scene.cmd("whoami").succeeds();
let username_whoami = result.stdout.trim(); let username_whoami = result.stdout_str().trim();
assert_eq!(username_id, username_whoami); assert_eq!(username_id, username_whoami);
} }
#[test] #[test]
fn test_id_group() { fn test_id_group() {
let scene = TestScenario::new(util_name!()); let mut result = new_ucmd!().arg("-g").succeeds();
let s1 = result.stdout_str().trim();
let mut result = scene.ucmd().arg("-g").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let s1 = String::from(result.stdout.trim());
assert!(s1.parse::<f64>().is_ok()); assert!(s1.parse::<f64>().is_ok());
result = scene.ucmd().arg("--group").succeeds(); result = new_ucmd!().arg("--group").succeeds();
println!("result.stdout = {}", result.stdout); let s1 = result.stdout_str().trim();
println!("result.stderr = {}", result.stderr);
assert!(result.success);
let s1 = String::from(result.stdout.trim());
assert!(s1.parse::<f64>().is_ok()); assert!(s1.parse::<f64>().is_ok());
} }
#[test] #[test]
fn test_id_groups() { fn test_id_groups() {
let scene = TestScenario::new(util_name!()); let result = new_ucmd!().arg("-G").succeeds();
let result = scene.ucmd().arg("-G").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success); assert!(result.success);
let groups = result.stdout.trim().split_whitespace(); let groups = result.stdout_str().trim().split_whitespace();
for s in groups { for s in groups {
assert!(s.parse::<f64>().is_ok()); assert!(s.parse::<f64>().is_ok());
} }
let result = scene.ucmd().arg("--groups").succeeds(); let result = new_ucmd!().arg("--groups").succeeds();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success); assert!(result.success);
let groups = result.stdout.trim().split_whitespace(); let groups = result.stdout_str().trim().split_whitespace();
for s in groups { for s in groups {
assert!(s.parse::<f64>().is_ok()); assert!(s.parse::<f64>().is_ok());
} }
@ -136,15 +108,12 @@ fn test_id_groups() {
#[test] #[test]
fn test_id_user() { fn test_id_user() {
let scene = TestScenario::new(util_name!()); let mut result = new_ucmd!().arg("-u").succeeds();
let s1 = result.stdout_str().trim();
let mut result = scene.ucmd().arg("-u").succeeds();
assert!(result.success);
let s1 = String::from(result.stdout.trim());
assert!(s1.parse::<f64>().is_ok()); assert!(s1.parse::<f64>().is_ok());
result = scene.ucmd().arg("--user").succeeds();
assert!(result.success); result = new_ucmd!().arg("--user").succeeds();
let s1 = String::from(result.stdout.trim()); let s1 = result.stdout_str().trim();
assert!(s1.parse::<f64>().is_ok()); assert!(s1.parse::<f64>().is_ok());
} }
@ -156,17 +125,13 @@ fn test_id_pretty_print() {
return; return;
} }
let scene = TestScenario::new(util_name!()); let result = new_ucmd!().arg("-p").run();
let result = scene.ucmd().arg("-p").run(); if result.stdout_str().trim() == "" {
if result.stdout.trim() == "" {
// Sometimes, the CI is failing here with // Sometimes, the CI is failing here with
// old rust versions on Linux // old rust versions on Linux
return; return;
} }
println!("result.stdout = {}", result.stdout); result.success().stdout_contains(username);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
assert!(result.stdout.contains(&username));
} }
#[test] #[test]
@ -176,12 +141,7 @@ fn test_id_password_style() {
// Sometimes, the CI is failing here // Sometimes, the CI is failing here
return; return;
} }
let scene = TestScenario::new(util_name!());
let result = scene.ucmd().arg("-P").succeeds(); let result = new_ucmd!().arg("-P").succeeds();
assert!(result.stdout_str().starts_with(&username));
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
assert!(result.success);
assert!(result.stdout.starts_with(&username));
} }

View file

@ -195,12 +195,8 @@ fn test_install_mode_numeric() {
let mode_arg = "-m 0333"; let mode_arg = "-m 0333";
at.mkdir(dir2); at.mkdir(dir2);
let result = scene.ucmd().arg(mode_arg).arg(file).arg(dir2).run(); scene.ucmd().arg(mode_arg).arg(file).arg(dir2).succeeds();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
assert!(result.success);
let dest_file = &format!("{}/{}", dir2, file); let dest_file = &format!("{}/{}", dir2, file);
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(dest_file)); assert!(at.file_exists(dest_file));
@ -313,16 +309,13 @@ fn test_install_target_new_file_with_group() {
.arg(format!("{}/{}", dir, file)) .arg(format!("{}/{}", dir, file))
.run(); .run();
println!("stderr = {:?}", result.stderr); if is_ci() && result.stderr_str().contains("error: no such group:") {
println!("stdout = {:?}", result.stdout);
if is_ci() && result.stderr.contains("error: no such group:") {
// In the CI, some server are failing to return the group. // In the CI, some server are failing to return the group.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
assert!(result.success); result.success();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(&format!("{}/{}", dir, file))); assert!(at.file_exists(&format!("{}/{}", dir, file)));
} }
@ -343,16 +336,13 @@ fn test_install_target_new_file_with_owner() {
.arg(format!("{}/{}", dir, file)) .arg(format!("{}/{}", dir, file))
.run(); .run();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
if is_ci() && result.stderr.contains("error: no such user:") { if is_ci() && result.stderr.contains("error: no such user:") {
// In the CI, some server are failing to return the user id. // In the CI, some server are failing to return the user id.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
assert!(result.success); result.success();
assert!(at.file_exists(file)); assert!(at.file_exists(file));
assert!(at.file_exists(&format!("{}/{}", dir, file))); assert!(at.file_exists(&format!("{}/{}", dir, file)));
} }
@ -366,13 +356,10 @@ fn test_install_target_new_file_failing_nonexistent_parent() {
at.touch(file1); at.touch(file1);
let err = ucmd ucmd.arg(file1)
.arg(file1)
.arg(format!("{}/{}", dir, file2)) .arg(format!("{}/{}", dir, file2))
.fails() .fails()
.stderr; .stderr_contains(&"not a directory");
assert!(err.contains("not a directory"))
} }
#[test] #[test]
@ -417,18 +404,12 @@ fn test_install_copy_file() {
#[test] #[test]
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
fn test_install_target_file_dev_null() { fn test_install_target_file_dev_null() {
let scene = TestScenario::new(util_name!()); let (at, mut ucmd) = at_and_ucmd!();
let at = &scene.fixtures;
let file1 = "/dev/null"; let file1 = "/dev/null";
let file2 = "target_file"; let file2 = "target_file";
let result = scene.ucmd().arg(file1).arg(file2).run(); ucmd.arg(file1).arg(file2).succeeds();
println!("stderr = {:?}", result.stderr);
println!("stdout = {:?}", result.stdout);
assert!(result.success);
assert!(at.file_exists(file2)); assert!(at.file_exists(file2));
} }

View file

@ -520,10 +520,7 @@ fn test_symlink_no_deref_dir() {
scene.ucmd().args(&["-sn", dir1, link]).fails(); scene.ucmd().args(&["-sn", dir1, link]).fails();
// Try with the no-deref // Try with the no-deref
let result = scene.ucmd().args(&["-sfn", dir1, link]).run(); scene.ucmd().args(&["-sfn", dir1, link]).succeeds();
println!("stdout {}", result.stdout);
println!("stderr {}", result.stderr);
assert!(result.success);
assert!(at.dir_exists(dir1)); assert!(at.dir_exists(dir1));
assert!(at.dir_exists(dir2)); assert!(at.dir_exists(dir2));
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));
@ -566,10 +563,7 @@ fn test_symlink_no_deref_file() {
scene.ucmd().args(&["-sn", file1, link]).fails(); scene.ucmd().args(&["-sn", file1, link]).fails();
// Try with the no-deref // Try with the no-deref
let result = scene.ucmd().args(&["-sfn", file1, link]).run(); scene.ucmd().args(&["-sfn", file1, link]).succeeds();
println!("stdout {}", result.stdout);
println!("stderr {}", result.stderr);
assert!(result.success);
assert!(at.file_exists(file1)); assert!(at.file_exists(file1));
assert!(at.file_exists(file2)); assert!(at.file_exists(file2));
assert!(at.is_symlink(link)); assert!(at.is_symlink(link));

View file

@ -3,23 +3,19 @@ use std::env;
#[test] #[test]
fn test_normal() { fn test_normal() {
let (_, mut ucmd) = at_and_ucmd!(); let result = new_ucmd!().run();
let result = ucmd.run();
println!("result.stdout = {}", result.stdout);
println!("result.stderr = {}", result.stderr);
println!("env::var(CI).is_ok() = {}", env::var("CI").is_ok()); println!("env::var(CI).is_ok() = {}", env::var("CI").is_ok());
for (key, value) in env::vars() { for (key, value) in env::vars() {
println!("{}: {}", key, value); println!("{}: {}", key, value);
} }
if (is_ci() || is_wsl()) && result.stderr.contains("error: no login name") { if (is_ci() || is_wsl()) && result.stderr_str().contains("error: no login name") {
// ToDO: investigate WSL failure // ToDO: investigate WSL failure
// In the CI, some server are failing to return logname. // In the CI, some server are failing to return logname.
// As seems to be a configuration issue, ignoring it // As seems to be a configuration issue, ignoring it
return; return;
} }
assert!(result.success); result.success();
assert!(!result.stdout.trim().is_empty()); assert!(!result.stdout_str().trim().is_empty());
} }