Skip to content

Commit 748949f

Browse files
committed
chmod: add regression test for correct exit codes
1 parent df2d272 commit 748949f

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/by-util/test_chmod.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,38 @@ fn test_permission_denied() {
375375
.stderr_is("chmod: 'd/no-x/y': Permission denied\n");
376376
}
377377

378+
#[test]
379+
#[allow(clippy::unreadable_literal)]
380+
fn test_chmod_recursive_correct_exit_code() {
381+
let (at, mut ucmd) = at_and_ucmd!();
382+
383+
// create 3 folders to test on
384+
at.mkdir("a");
385+
at.mkdir("a/b");
386+
at.mkdir("z");
387+
388+
// remove read permissions for folder a so the chmod command for a/b fails
389+
let mut perms = at.metadata("a").permissions();
390+
perms.set_mode(0o000);
391+
set_permissions(at.plus_as_string("a"), perms).unwrap();
392+
393+
#[cfg(not(target_os = "linux"))]
394+
let err_msg = "chmod: Permission denied\n";
395+
#[cfg(target_os = "linux")]
396+
let err_msg = "chmod: 'a': Permission denied\n";
397+
398+
// order of command is a, a/b then c
399+
// command is expected to fail and not just take the last exit code
400+
ucmd.arg("-R")
401+
.arg("--verbose")
402+
.arg("a+w")
403+
.arg("a")
404+
.arg("z")
405+
.umask(0)
406+
.fails()
407+
.stderr_is(err_msg);
408+
}
409+
378410
#[test]
379411
#[allow(clippy::unreadable_literal)]
380412
fn test_chmod_recursive() {

0 commit comments

Comments
 (0)