Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions tests/by-util/test_cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ fn test_write_fast_read_error() {
at.write("foo", "content");

// Remove read permissions to cause a read error
let file_path = at.plus_as_string("foo");
let file_path = at.plus("foo");
let mut perms = std::fs::metadata(&file_path).unwrap().permissions();
perms.set_mode(0o000); // No permissions
std::fs::set_permissions(&file_path, perms).unwrap();
Expand Down Expand Up @@ -803,7 +803,7 @@ fn test_appending_same_input_output() {
let (at, mut ucmd) = at_and_ucmd!();

at.write("foo", "content");
let foo_file = at.plus_as_string("foo");
let foo_file = at.plus("foo");

let file_read = File::open(&foo_file).unwrap();
let file_write = OpenOptions::new().append(true).open(&foo_file).unwrap();
Expand Down
58 changes: 29 additions & 29 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ struct TestCase {
umask: Option<libc::mode_t>,
}

fn make_file(file: &str, mode: u32) {
fn make_file(file: impl AsRef<std::path::Path>, mode: u32) {
OpenOptions::new()
.mode(mode)
.create(true)
.write(true)
.open(file)
.open(&file)
.unwrap();
let mut perms = metadata(file).unwrap().permissions();
let mut perms = metadata(&file).unwrap().permissions();
perms.set_mode(mode);
set_permissions(file, perms).unwrap();
}

fn run_single_test(test: &TestCase, at: &AtPath, mut ucmd: UCommand) {
make_file(&at.plus_as_string(TEST_FILE), test.before);
make_file(at.plus(TEST_FILE), test.before);
let perms = at.metadata(TEST_FILE).permissions().mode();

assert_eq!(
Expand Down Expand Up @@ -407,7 +407,7 @@ fn test_chmod_reference_file() {
},
];
let (at, ucmd) = at_and_ucmd!();
make_file(&at.plus_as_string(REFERENCE_FILE), REFERENCE_PERMS);
make_file(at.plus(REFERENCE_FILE), REFERENCE_PERMS);
run_single_test(&tests[0], &at, ucmd);
}

Expand Down Expand Up @@ -441,8 +441,8 @@ fn test_chmod_inaccessible_file_reports_permission_denied() {
let at = &scene.fixtures;

at.mkdir("locked");
make_file(&at.plus_as_string("locked/file"), 0o100_644);
set_permissions(at.plus_as_string("locked"), Permissions::from_mode(0o000)).unwrap();
make_file(at.plus("locked/file"), 0o100_644);
set_permissions(at.plus("locked"), Permissions::from_mode(0o000)).unwrap();

scene
.ucmd()
Expand All @@ -452,7 +452,7 @@ fn test_chmod_inaccessible_file_reports_permission_denied() {
.stderr_is("chmod: cannot access 'locked/file': Permission denied\n");

// Restore search permission so the fixture directory can be cleaned up.
set_permissions(at.plus_as_string("locked"), Permissions::from_mode(0o755)).unwrap();
set_permissions(at.plus("locked"), Permissions::from_mode(0o755)).unwrap();
}

#[test]
Expand Down Expand Up @@ -507,7 +507,7 @@ fn test_chmod_recursive_correct_exit_code() {
// remove read permissions for folder a so the chmod command for a/b fails
let mut perms = at.metadata("a").permissions();
perms.set_mode(0o000);
set_permissions(at.plus_as_string("a"), perms).unwrap();
set_permissions(at.plus("a"), perms).unwrap();

// `a` is changed before it is read, so the failure is about reading it.
let err_msg = "chmod: cannot read directory 'a': Permission denied\n";
Expand Down Expand Up @@ -548,10 +548,10 @@ fn test_chmod_recursive() {
let a_perms_expected = (at.metadata("a").permissions().mode() & !0o444) | 0o222;
let z_perms_expected = (at.metadata("z").permissions().mode() & !0o444) | 0o222;

make_file(&at.plus_as_string("a/a"), 0o100444);
make_file(&at.plus_as_string("a/b/b"), 0o100444);
make_file(&at.plus_as_string("a/b/c/c"), 0o100444);
make_file(&at.plus_as_string("z/y"), 0o100444);
make_file(at.plus("a/a"), 0o100444);
make_file(at.plus("a/b/b"), 0o100444);
make_file(at.plus("a/b/c/c"), 0o100444);
make_file(at.plus("z/y"), 0o100444);
// Both operands become unreadable, and each failure is reported.
let err_msg = "chmod: cannot read directory 'a': Permission denied\n\
chmod: cannot read directory 'z': Permission denied\n";
Expand Down Expand Up @@ -581,7 +581,7 @@ fn test_chmod_recursive_reports_every_unreadable_directory() {
let (at, mut ucmd) = at_and_ucmd!();
let dirs = ["d/a", "d/b", "d/c"];
for dir in dirs {
at.mkdir_all(&format!("{dir}/y"));
at.mkdir_all(format!("{dir}/y"));
set_permissions(at.plus_as_string(dir), Permissions::from_mode(0o311)).unwrap();
}

Expand Down Expand Up @@ -646,8 +646,8 @@ fn test_chmod_recursive_read_permission() {
at.mkdir("a/b");
let mut perms = at.metadata("a/b").permissions();
perms.set_mode(0o311);
set_permissions(at.plus_as_string("a/b"), perms.clone()).unwrap();
set_permissions(at.plus_as_string("a"), perms).unwrap();
set_permissions(at.plus("a/b"), perms.clone()).unwrap();
set_permissions(at.plus("a"), perms).unwrap();

ucmd.arg("-R").arg("u+r").arg("a").succeeds();

Expand Down Expand Up @@ -833,7 +833,7 @@ fn test_chmod_symlink_non_existing_file_recursive() {
let test_directory = "test_chmod_symlink_non_existing_file_directory";

at.mkdir(test_directory);
at.symlink_file(non_existing, &format!("{test_directory}/{test_symlink}"));
at.symlink_file(non_existing, format!("{test_directory}/{test_symlink}"));

// this should succeed
scene
Expand Down Expand Up @@ -1081,15 +1081,15 @@ fn test_gnu_special_filenames() {
let perms_before = Permissions::from_mode(0o100_640);
let perms_after = Permissions::from_mode(0o100_440);

make_file(&at.plus_as_string("--"), perms_before.mode());
make_file(at.plus("--"), perms_before.mode());
scene.ucmd().arg("-w").arg("--").arg("--").succeeds();
assert_eq!(at.metadata("--").permissions(), perms_after);
set_permissions(at.plus("--"), perms_before.clone()).unwrap();
scene.ucmd().arg("--").arg("-w").arg("--").succeeds();
assert_eq!(at.metadata("--").permissions(), perms_after);
at.remove("--");

make_file(&at.plus_as_string("-w"), perms_before.mode());
make_file(at.plus("-w"), perms_before.mode());
scene.ucmd().arg("-w").arg("--").arg("-w").succeeds();
assert_eq!(at.metadata("-w").permissions(), perms_after);
set_permissions(at.plus("-w"), perms_before).unwrap();
Expand Down Expand Up @@ -1153,7 +1153,7 @@ fn test_gnu_usage_matrix() {
// 0o644 has no group or other write bit, so `-w` lands on 0o444 under any umask. This test
// is about which operands get picked, not about umask arithmetic.
for name in ["f", "--", "-w"] {
make_file(&at.plus_as_string(name), 0o644);
make_file(at.plus(name), 0o644);
}

let result = scene.ucmd().arg("-v").args(args).run();
Expand Down Expand Up @@ -1220,7 +1220,7 @@ fn test_umask_conflict_reported_only_for_option_like_mode() {
let at = &scene.fixtures;
// 0o666 is required: on 0o644 the umask has nothing left to keep, so the conflict never
// arises and every one of these cases would pass vacuously.
make_file(&at.plus_as_string("file"), 0o666);
make_file(at.plus("file"), 0o666);

let result = scene.ucmd().umask(0o022).args(args).run();
let context = format!("chmod {}", args.join(" "));
Expand Down Expand Up @@ -1466,7 +1466,7 @@ fn test_chmod_traverse_symlink_combo() {

at.mkdir(directory);
at.touch(target);
at.symlink_file(target, &format!("{directory}/{symlink}"));
at.symlink_file(target, format!("{directory}/{symlink}"));

set_permissions(at.plus(target), Permissions::from_mode(0o664)).unwrap();

Expand All @@ -1485,7 +1485,7 @@ fn test_chmod_traverse_symlink_combo() {
);

let actual_symlink = at
.symlink_metadata(&format!("{directory}/{symlink}"))
.symlink_metadata(format!("{directory}/{symlink}"))
.permissions()
.mode();
assert_eq!(
Expand Down Expand Up @@ -1531,7 +1531,7 @@ fn test_chmod_recursive_symlink_to_directory_command_line() {
.no_stderr();

let actual_file_perms = at
.metadata(&format!("{target_dir}/{file_in_target}"))
.metadata(format!("{target_dir}/{file_in_target}"))
.permissions()
.mode();

Expand Down Expand Up @@ -1573,7 +1573,7 @@ fn test_chmod_recursive_symlink_during_traversal() {
at.mkdir(directory);
at.mkdir(target_dir);
at.touch(format!("{target_dir}/{file_in_target}"));
at.symlink_dir(target_dir, &format!("{directory}/{symlink_to_dir}"));
at.symlink_dir(target_dir, format!("{directory}/{symlink_to_dir}"));

set_permissions(
at.plus(format!("{target_dir}/{file_in_target}")),
Expand All @@ -1589,7 +1589,7 @@ fn test_chmod_recursive_symlink_during_traversal() {
.no_stderr();

let actual_file_perms = at
.metadata(&format!("{target_dir}/{file_in_target}"))
.metadata(format!("{target_dir}/{file_in_target}"))
.permissions()
.mode();

Expand Down Expand Up @@ -1625,8 +1625,8 @@ fn test_chmod_recursive_symlink_combinations() {
at.mkdir(target_dir);
at.touch(target_file);
at.touch(format!("{target_dir}/{file_in_target}"));
at.symlink_dir(target_dir, &format!("{directory}/{symlink_to_dir}"));
at.symlink_file(target_file, &format!("{directory}/{symlink_to_file}"));
at.symlink_dir(target_dir, format!("{directory}/{symlink_to_dir}"));
at.symlink_file(target_file, format!("{directory}/{symlink_to_file}"));

set_permissions(at.plus(target_file), Permissions::from_mode(0o644)).unwrap();
set_permissions(
Expand All @@ -1648,7 +1648,7 @@ fn test_chmod_recursive_symlink_combinations() {
// Both target file and file in target directory should have permissions changed
assert_eq!(at.metadata(target_file).permissions().mode(), 0o100_600);
assert_eq!(
at.metadata(&format!("{target_dir}/{file_in_target}"))
at.metadata(format!("{target_dir}/{file_in_target}"))
.permissions()
.mode(),
0o100_600
Expand Down
8 changes: 4 additions & 4 deletions tests/by-util/test_chown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -780,10 +780,10 @@ fn test_chown_recursive() {

at.mkdir_all("a/b/c");
at.mkdir("z");
at.touch(at.plus_as_string("a/a"));
at.touch(at.plus_as_string("a/b/b"));
at.touch(at.plus_as_string("a/b/c/c"));
at.touch(at.plus_as_string("z/y"));
at.touch(at.plus("a/a"));
at.touch(at.plus("a/b/b"));
at.touch(at.plus("a/b/c/c"));
at.touch(at.plus("z/y"));

scene
.ucmd()
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 @@ -70,7 +70,7 @@ fn test_no_such() {
#[cfg(target_env = "gnu")] // todo: override by proper error message on other platforms
fn test_not_a_directory() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch(at.plus_as_string("a"));
at.touch(at.plus("a"));
ucmd.arg("a")
.fails_with_code(125)
.stderr_only("chroot: cannot chroot to 'a': Not a directory\n");
Expand Down
Loading
Loading