Skip to content

Commit

Permalink
Merge pull request #4261 from Joining7943/tests-util-enhance-cmdresult
Browse files Browse the repository at this point in the history
`tests/util`: Implement enhancements of `CmdResult` #4259
  • Loading branch information
tertsdiepraam authored Jan 25, 2023
2 parents dce8a02 + 78a3810 commit fc7e51a
Show file tree
Hide file tree
Showing 42 changed files with 779 additions and 432 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ sha1 = { version="0.10", features=["std"] }
tempfile = "3"
time = {version="0.3", features=["local-offset"]}
unindent = "0.1"
uucore = { version=">=0.0.17", package="uucore", path="src/uucore", features=["entries", "process"] }
uucore = { version=">=0.0.17", package="uucore", path="src/uucore", features=["entries", "process", "signals"] }
walkdir = "2.2"
atty = "0.2"
hex-literal = "0.3.1"
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_base32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ fn test_base32_file_not_found() {
new_ucmd!()
.arg("a.txt")
.fails()
.stderr_only("base32: a.txt: No such file or directory");
.stderr_only("base32: a.txt: No such file or directory\n");
}
2 changes: 1 addition & 1 deletion tests/by-util/test_base64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,5 @@ fn test_base64_file_not_found() {
new_ucmd!()
.arg("a.txt")
.fails()
.stderr_only("base64: a.txt: No such file or directory");
.stderr_only("base64: a.txt: No such file or directory\n");
}
4 changes: 2 additions & 2 deletions tests/by-util/test_basenc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ fn test_z85_not_padded() {
.args(&["--z85", "-d"])
.pipe_in("##########")
.fails()
.stderr_only("basenc: error: invalid input");
.stderr_only("basenc: error: invalid input\n");
new_ucmd!()
.args(&["--z85"])
.pipe_in("123")
.fails()
.stderr_only("basenc: error: invalid input (length must be multiple of 4 characters)");
.stderr_only("basenc: error: invalid input (length must be multiple of 4 characters)\n");
}
6 changes: 3 additions & 3 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ fn test_directory() {
s.ucmd()
.args(&["test_directory"])
.fails()
.stderr_is("cat: test_directory: Is a directory");
.stderr_is("cat: test_directory: Is a directory\n");
}

#[test]
Expand All @@ -194,7 +194,7 @@ fn test_directory_and_file() {
s.ucmd()
.args(&["test_directory2", fixture])
.fails()
.stderr_is("cat: test_directory2: Is a directory")
.stderr_is("cat: test_directory2: Is a directory\n")
.stdout_is_fixture(fixture);
}
}
Expand Down Expand Up @@ -527,7 +527,7 @@ fn test_write_to_self() {
.arg("second_file")
.fails()
.code_is(2)
.stderr_only("cat: first_file: input file is output file\ncat: first_file: input file is output file");
.stderr_only("cat: first_file: input file is output file\ncat: first_file: input file is output file\n");

assert_eq!(
s.fixtures.read("first_file"),
Expand Down
16 changes: 8 additions & 8 deletions tests/by-util/test_chgrp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ fn test_invalid_group() {
.arg("__nosuchgroup__")
.arg("/")
.fails()
.stderr_is("chgrp: invalid group: '__nosuchgroup__'");
.stderr_is("chgrp: invalid group: '__nosuchgroup__'\n");
}

#[test]
Expand Down Expand Up @@ -92,7 +92,7 @@ fn test_preserve_root() {
.arg("-R")
.arg("bin").arg(d)
.fails()
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe\n");
}
}

Expand All @@ -111,7 +111,7 @@ fn test_preserve_root_symlink() {
.arg("-HR")
.arg("bin").arg(file)
.fails()
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe\n");
}

let (at, mut ucmd) = at_and_ucmd!();
Expand All @@ -120,15 +120,15 @@ fn test_preserve_root_symlink() {
.arg("-HR")
.arg("bin").arg(format!(".//{}/..//..//../../", file))
.fails()
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe\n");

let (at, mut ucmd) = at_and_ucmd!();
at.symlink_file("/", "__root__");
ucmd.arg("--preserve-root")
.arg("-R")
.arg("bin").arg("__root__/.")
.fails()
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe");
.stderr_is("chgrp: it is dangerous to operate recursively on '/'\nchgrp: use --no-preserve-root to override this failsafe\n");
}

#[test]
Expand All @@ -143,7 +143,7 @@ fn test_reference() {
.arg("--reference=/etc/passwd")
.arg("/etc")
.fails()
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\nfailed to change group of '/etc' from root to root");
.stderr_is("chgrp: changing group of '/etc': Operation not permitted (os error 1)\nfailed to change group of '/etc' from root to root\n");
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ fn test_permission_denied() {
.arg(group.as_raw().to_string())
.arg("dir")
.fails()
.stderr_only("chgrp: cannot access 'dir': Permission denied");
.stderr_only("chgrp: cannot access 'dir': Permission denied\n");
}
}

Expand All @@ -289,7 +289,7 @@ fn test_subdir_permission_denied() {
.arg(group.as_raw().to_string())
.arg("dir")
.fails()
.stderr_only("chgrp: cannot access 'dir/subdir': Permission denied");
.stderr_only("chgrp: cannot access 'dir/subdir': Permission denied\n");
}
}

Expand Down
6 changes: 3 additions & 3 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ fn test_chmod_ugoa() {
.fails()
.code_is(1)
// spell-checker:disable-next-line
.stderr_is("chmod: file: new permissions are r-xrwxrwx, not r-xr-xr-x");
.stderr_is("chmod: file: new permissions are r-xrwxrwx, not r-xr-xr-x\n");
assert_eq!(
metadata(at.plus("file")).unwrap().permissions().mode(),
0o100577
Expand Down Expand Up @@ -314,7 +314,7 @@ fn test_permission_denied() {
.arg("o=r")
.arg("d")
.fails()
.stderr_is("chmod: 'd/no-x/y': Permission denied");
.stderr_is("chmod: 'd/no-x/y': Permission denied\n");
}

#[test]
Expand All @@ -341,7 +341,7 @@ fn test_chmod_recursive() {
.arg("a")
.arg("z")
.fails()
.stderr_is("chmod: Permission denied");
.stderr_is("chmod: Permission denied\n");

assert_eq!(at.metadata("z/y").permissions().mode(), 0o100444);
assert_eq!(at.metadata("a/a").permissions().mode(), 0o100444);
Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_chroot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn test_no_such_directory() {

ucmd.arg("a")
.fails()
.stderr_is("chroot: cannot change root directory to 'a': no such directory")
.stderr_is("chroot: cannot change root directory to 'a': no such directory\n")
.code_is(125);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/by-util/test_comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,5 @@ fn test_no_such_file() {
new_ucmd!()
.args(&["bogus_file_1", "bogus_file_2"])
.fails()
.stderr_only("comm: bogus_file_1: No such file or directory");
.stderr_only("comm: bogus_file_1: No such file or directory\n");
}
32 changes: 16 additions & 16 deletions tests/by-util/test_cp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ fn test_cp_backup_simple_protect_source() {
.arg(TEST_HELLO_WORLD_SOURCE)
.fails()
.stderr_only(format!(
"cp: backing up '{}' might destroy source; '{}' not copied",
"cp: backing up '{}' might destroy source; '{}' not copied\n",
TEST_HELLO_WORLD_SOURCE, source,
));

Expand Down Expand Up @@ -1524,7 +1524,7 @@ fn test_cp_reflink_insufficient_permission() {
.arg("unreadable")
.arg(TEST_EXISTING_FILE)
.fails()
.stderr_only("cp: 'unreadable' -> 'existing_file.txt': Permission denied (os error 13)");
.stderr_only("cp: 'unreadable' -> 'existing_file.txt': Permission denied (os error 13)\n");
}

#[cfg(any(target_os = "linux", target_os = "android"))]
Expand Down Expand Up @@ -1863,9 +1863,9 @@ fn test_copy_through_just_created_symlink() {
.arg("c")
.fails()
.stderr_only(if cfg!(not(target_os = "windows")) {
"cp: will not copy 'b/1' through just-created symlink 'c/1'"
"cp: will not copy 'b/1' through just-created symlink 'c/1'\n"
} else {
"cp: will not copy 'b/1' through just-created symlink 'c\\1'"
"cp: will not copy 'b/1' through just-created symlink 'c\\1'\n"
});
if create_t {
assert_eq!(at.read("a/1"), "world");
Expand All @@ -1881,7 +1881,7 @@ fn test_copy_through_dangling_symlink() {
ucmd.arg("file")
.arg("target")
.fails()
.stderr_only("cp: not writing through dangling symlink 'target'");
.stderr_only("cp: not writing through dangling symlink 'target'\n");
}

#[test]
Expand Down Expand Up @@ -1933,7 +1933,7 @@ fn test_copy_through_dangling_symlink_no_dereference_2() {
at.symlink_file("nonexistent", "target");
ucmd.args(&["-P", "file", "target"])
.fails()
.stderr_only("cp: not writing through dangling symlink 'target'");
.stderr_only("cp: not writing through dangling symlink 'target'\n");
}

/// Test that copy through a dangling symbolic link fails, even with --force.
Expand All @@ -1945,7 +1945,7 @@ fn test_copy_through_dangling_symlink_force() {
at.symlink_file("no-such-file", "dest");
ucmd.args(&["--force", "src", "dest"])
.fails()
.stderr_only("cp: not writing through dangling symlink 'dest'");
.stderr_only("cp: not writing through dangling symlink 'dest'\n");
assert!(!at.file_exists("dest"));
}

Expand All @@ -1958,7 +1958,7 @@ fn test_cp_archive_on_nonexistent_file() {
.arg(TEST_EXISTING_FILE)
.fails()
.stderr_only(
"cp: cannot stat 'nonexistent_file.txt': No such file or directory (os error 2)",
"cp: cannot stat 'nonexistent_file.txt': No such file or directory (os error 2)\n",
);
}

Expand Down Expand Up @@ -2043,7 +2043,7 @@ fn test_cp_dir_vs_file() {
.arg(TEST_COPY_FROM_FOLDER)
.arg(TEST_EXISTING_FILE)
.fails()
.stderr_only("cp: cannot overwrite non-directory with directory");
.stderr_only("cp: cannot overwrite non-directory with directory\n");
}

#[test]
Expand Down Expand Up @@ -2285,9 +2285,9 @@ fn test_copy_directory_to_itself_disallowed() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("d");
#[cfg(not(windows))]
let expected = "cp: cannot copy a directory, 'd', into itself, 'd/d'";
let expected = "cp: cannot copy a directory, 'd', into itself, 'd/d'\n";
#[cfg(windows)]
let expected = "cp: cannot copy a directory, 'd', into itself, 'd\\d'";
let expected = "cp: cannot copy a directory, 'd', into itself, 'd\\d'\n";
ucmd.args(&["-R", "d", "d"]).fails().stderr_only(expected);
}

Expand All @@ -2299,9 +2299,9 @@ fn test_copy_nested_directory_to_itself_disallowed() {
at.mkdir("a/b");
at.mkdir("a/b/c");
#[cfg(not(windows))]
let expected = "cp: cannot copy a directory, 'a/b', into itself, 'a/b/c/b'";
let expected = "cp: cannot copy a directory, 'a/b', into itself, 'a/b/c/b'\n";
#[cfg(windows)]
let expected = "cp: cannot copy a directory, 'a/b', into itself, 'a/b/c\\b'";
let expected = "cp: cannot copy a directory, 'a/b', into itself, 'a/b/c\\b'\n";
ucmd.args(&["-R", "a/b", "a/b/c"])
.fails()
.stderr_only(expected);
Expand Down Expand Up @@ -2361,7 +2361,7 @@ fn test_copy_dir_preserve_permissions_inaccessible_file() {
ucmd.args(&["-p", "-R", "d1", "d2"])
.fails()
.code_is(1)
.stderr_only("cp: cannot open 'd1/f' for reading: Permission denied");
.stderr_only("cp: cannot open 'd1/f' for reading: Permission denied\n");
assert!(at.dir_exists("d2"));
assert!(!at.file_exists("d2/f"));

Expand All @@ -2378,7 +2378,7 @@ fn test_same_file_backup() {
at.touch("f");
ucmd.args(&["--backup", "f", "f"])
.fails()
.stderr_only("cp: 'f' and 'f' are the same file");
.stderr_only("cp: 'f' and 'f' are the same file\n");
assert!(!at.file_exists("f~"));
}

Expand All @@ -2390,7 +2390,7 @@ fn test_same_file_force() {
at.touch("f");
ucmd.args(&["--force", "f", "f"])
.fails()
.stderr_only("cp: 'f' and 'f' are the same file");
.stderr_only("cp: 'f' and 'f' are the same file\n");
assert!(!at.file_exists("f~"));
}

Expand Down
Loading

0 comments on commit fc7e51a

Please sign in to comment.