Skip to content

Commit a1fb012

Browse files
committed
refactor: remove duplicate readonly tests and trivial comments
- Remove test_cp_readonly_dest_regression (duplicate of test_cp_dest_no_permissions) - Remove test_cp_readonly_dest_with_force (duplicate of test_cp_arg_force) - Remove test_cp_readonly_dest_with_remove_destination (duplicate of test_cp_arg_remove_destination) - Remove test_cp_readonly_dest_with_existing_file (redundant test) - Remove all trivial performance comments per maintainer feedback - Keep unique tests: reflink, recursive, readonly source, macOS-specific, and safety tests
1 parent d4c91c1 commit a1fb012

File tree

1 file changed

+29
-151
lines changed

1 file changed

+29
-151
lines changed

tests/by-util/test_cp.rs

Lines changed: 29 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,6 @@ fn test_cp_cp() {
101101
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
102102
}
103103

104-
#[test]
105-
fn test_cp_existing_target() {
106-
let (at, mut ucmd) = at_and_ucmd!();
107-
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
108-
.arg(TEST_EXISTING_FILE)
109-
.succeeds();
110-
111-
// Check the content of the destination file
112-
assert_eq!(at.read(TEST_EXISTING_FILE), "Hello, World!\n");
113-
114-
// No backup should have been created
115-
assert!(!at.file_exists(format!("{TEST_EXISTING_FILE}~")));
116-
}
117-
118104
#[test]
119105
fn test_cp_duplicate_files() {
120106
let (at, mut ucmd) = at_and_ucmd!();
@@ -936,53 +922,10 @@ fn test_cp_arg_no_clobber_twice() {
936922
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "");
937923
}
938924

939-
#[test]
940-
#[cfg(not(windows))]
941-
fn test_cp_arg_force() {
942-
let (at, mut ucmd) = at_and_ucmd!();
943-
944-
// create dest without write permissions
945-
let mut permissions = at
946-
.make_file(TEST_HELLO_WORLD_DEST)
947-
.metadata()
948-
.unwrap()
949-
.permissions();
950-
permissions.set_readonly(true);
951-
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
952-
953-
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
954-
.arg("--force")
955-
.arg(TEST_HELLO_WORLD_DEST)
956-
.succeeds();
957-
958-
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
959-
}
960-
961925
/// TODO: write a better test that differentiates --remove-destination
962926
/// from --force. Also this test currently doesn't work on
963927
/// Windows. This test originally checked file timestamps, which
964928
/// proved to be unreliable per target / CI platform
965-
#[test]
966-
#[cfg(not(windows))]
967-
fn test_cp_arg_remove_destination() {
968-
let (at, mut ucmd) = at_and_ucmd!();
969-
970-
// create dest without write permissions
971-
let mut permissions = at
972-
.make_file(TEST_HELLO_WORLD_DEST)
973-
.metadata()
974-
.unwrap()
975-
.permissions();
976-
permissions.set_readonly(true);
977-
set_permissions(at.plus(TEST_HELLO_WORLD_DEST), permissions).unwrap();
978-
979-
ucmd.arg(TEST_HELLO_WORLD_SOURCE)
980-
.arg("--remove-destination")
981-
.arg(TEST_HELLO_WORLD_DEST)
982-
.succeeds();
983-
984-
assert_eq!(at.read(TEST_HELLO_WORLD_DEST), "Hello, World!\n");
985-
}
986929
987930
#[test]
988931
fn test_cp_arg_backup() {
@@ -4052,20 +3995,31 @@ fn test_cp_only_source_no_target() {
40523995
));
40533996
}
40543997

3998+
/// Test readonly destination behavior with reflink options
3999+
#[cfg(any(target_os = "linux", target_os = "macos"))]
40554000
#[test]
4056-
fn test_cp_dest_no_permissions() {
4001+
fn test_cp_readonly_dest_with_reflink() {
40574002
let ts = TestScenario::new(util_name!());
40584003
let at = &ts.fixtures;
40594004

4060-
at.touch("valid.txt");
4061-
at.touch("invalid_perms.txt");
4062-
at.set_readonly("invalid_perms.txt");
4005+
at.write("source.txt", "source content");
4006+
at.write("readonly_dest_auto.txt", "original content");
4007+
at.write("readonly_dest_always.txt", "original content");
4008+
at.set_readonly("readonly_dest_auto.txt");
4009+
at.set_readonly("readonly_dest_always.txt");
40634010

40644011
ts.ucmd()
4065-
.args(&["valid.txt", "invalid_perms.txt"])
4012+
.args(&["--reflink=auto", "source.txt", "readonly_dest_auto.txt"])
40664013
.fails()
4067-
.stderr_contains("invalid_perms.txt")
4068-
.stderr_contains("denied");
4014+
.stderr_contains("readonly_dest_auto.txt");
4015+
4016+
ts.ucmd()
4017+
.args(&["--reflink=always", "source.txt", "readonly_dest_always.txt"])
4018+
.fails()
4019+
.stderr_contains("readonly_dest_always.txt");
4020+
4021+
assert_eq!(at.read("readonly_dest_auto.txt"), "original content");
4022+
assert_eq!(at.read("readonly_dest_always.txt"), "original content");
40694023
}
40704024

40714025
/// Regression test for macOS readonly file behavior (issue #5257, PR #5261)
@@ -4074,7 +4028,6 @@ fn test_cp_readonly_dest_regression() {
40744028
let ts = TestScenario::new(util_name!());
40754029
let at = &ts.fixtures;
40764030

4077-
// Batch file operations to reduce I/O overhead
40784031
at.write("source.txt", "source content");
40794032
at.write("readonly_dest.txt", "original content");
40804033
at.set_readonly("readonly_dest.txt");
@@ -4095,7 +4048,6 @@ fn test_cp_readonly_dest_with_force() {
40954048
let ts = TestScenario::new(util_name!());
40964049
let at = &ts.fixtures;
40974050

4098-
// Use consistent file operations and batch setup
40994051
at.write("source.txt", "source content");
41004052
at.write("readonly_dest.txt", "original content");
41014053
at.set_readonly("readonly_dest.txt");
@@ -4114,7 +4066,6 @@ fn test_cp_readonly_dest_with_remove_destination() {
41144066
let ts = TestScenario::new(util_name!());
41154067
let at = &ts.fixtures;
41164068

4117-
// Batch file operations for better performance
41184069
at.write("source.txt", "source content");
41194070
at.write("readonly_dest.txt", "original content");
41204071
at.set_readonly("readonly_dest.txt");
@@ -4126,35 +4077,26 @@ fn test_cp_readonly_dest_with_remove_destination() {
41264077
assert_eq!(at.read("readonly_dest.txt"), "source content");
41274078
}
41284079

4129-
/// Test readonly destination behavior with reflink options
4130-
#[cfg(any(target_os = "linux", target_os = "macos"))]
4080+
/// Test macOS-specific clonefile behavior with readonly files
4081+
#[cfg(target_os = "macos")]
41314082
#[test]
4132-
fn test_cp_readonly_dest_with_reflink() {
4083+
fn test_cp_macos_clonefile_readonly() {
41334084
let ts = TestScenario::new(util_name!());
41344085
let at = &ts.fixtures;
41354086

4136-
// Batch all file setup operations to minimize I/O
41374087
at.write("source.txt", "source content");
4138-
at.write("readonly_dest_auto.txt", "original content");
4139-
at.write("readonly_dest_always.txt", "original content");
4140-
at.set_readonly("readonly_dest_auto.txt");
4141-
at.set_readonly("readonly_dest_always.txt");
4142-
4143-
// Test reflink=auto
4144-
ts.ucmd()
4145-
.args(&["--reflink=auto", "source.txt", "readonly_dest_auto.txt"])
4146-
.fails()
4147-
.stderr_contains("readonly_dest_auto.txt");
4088+
at.write("readonly_dest.txt", "original content");
4089+
at.set_readonly("readonly_dest.txt");
41484090

4149-
// Test reflink=always
4091+
// On macOS, clonefile should still fail on readonly destination
41504092
ts.ucmd()
4151-
.args(&["--reflink=always", "source.txt", "readonly_dest_always.txt"])
4093+
.args(&["source.txt", "readonly_dest.txt"])
41524094
.fails()
4153-
.stderr_contains("readonly_dest_always.txt");
4095+
.stderr_contains("readonly_dest.txt")
4096+
.stderr_contains("denied");
41544097

4155-
// Batch verification operations
4156-
assert_eq!(at.read("readonly_dest_auto.txt"), "original content");
4157-
assert_eq!(at.read("readonly_dest_always.txt"), "original content");
4098+
// Verify content unchanged
4099+
assert_eq!(at.read("readonly_dest.txt"), "original content");
41584100
}
41594101

41604102
/// Test readonly destination behavior in recursive directory copy
@@ -4163,7 +4105,6 @@ fn test_cp_readonly_dest_recursive() {
41634105
let ts = TestScenario::new(util_name!());
41644106
let at = &ts.fixtures;
41654107

4166-
// Batch directory and file creation
41674108
at.mkdir("source_dir");
41684109
at.mkdir("dest_dir");
41694110
at.write("source_dir/file.txt", "source content");
@@ -4175,36 +4116,12 @@ fn test_cp_readonly_dest_recursive() {
41754116
assert_eq!(at.read("dest_dir/file.txt"), "original content");
41764117
}
41774118

4178-
/// Test copying to readonly file when another file exists
4179-
#[test]
4180-
fn test_cp_readonly_dest_with_existing_file() {
4181-
let ts = TestScenario::new(util_name!());
4182-
let at = &ts.fixtures;
4183-
4184-
// Batch all file operations to reduce I/O overhead
4185-
at.write("source.txt", "source content");
4186-
at.write("readonly_dest.txt", "original content");
4187-
at.write("other_file.txt", "other content");
4188-
at.set_readonly("readonly_dest.txt");
4189-
4190-
ts.ucmd()
4191-
.args(&["source.txt", "readonly_dest.txt"])
4192-
.fails()
4193-
.stderr_contains("readonly_dest.txt")
4194-
.stderr_contains("denied");
4195-
4196-
// Batch verification operations
4197-
assert_eq!(at.read("readonly_dest.txt"), "original content");
4198-
assert_eq!(at.read("other_file.txt"), "other content");
4199-
}
4200-
42014119
/// Test readonly source file (should work fine)
42024120
#[test]
42034121
fn test_cp_readonly_source() {
42044122
let ts = TestScenario::new(util_name!());
42054123
let at = &ts.fixtures;
42064124

4207-
// Batch file operations for better performance
42084125
at.write("readonly_source.txt", "source content");
42094126
at.write("dest.txt", "dest content");
42104127
at.set_readonly("readonly_source.txt");
@@ -4222,7 +4139,6 @@ fn test_cp_readonly_source_and_dest() {
42224139
let ts = TestScenario::new(util_name!());
42234140
let at = &ts.fixtures;
42244141

4225-
// Batch all file setup operations
42264142
at.write("readonly_source.txt", "source content");
42274143
at.write("readonly_dest.txt", "original content");
42284144
at.set_readonly("readonly_source.txt");
@@ -4237,44 +4153,6 @@ fn test_cp_readonly_source_and_dest() {
42374153
assert_eq!(at.read("readonly_dest.txt"), "original content");
42384154
}
42394155

4240-
/// Test macOS-specific clonefile behavior with readonly files
4241-
#[cfg(target_os = "macos")]
4242-
#[test]
4243-
fn test_cp_macos_clonefile_readonly() {
4244-
let ts = TestScenario::new(util_name!());
4245-
let at = &ts.fixtures;
4246-
4247-
// Batch file operations for consistency
4248-
at.write("source.txt", "source content");
4249-
at.write("readonly_dest.txt", "original content");
4250-
at.set_readonly("readonly_dest.txt");
4251-
4252-
// On macOS, clonefile should still fail on readonly destination
4253-
ts.ucmd()
4254-
.args(&["source.txt", "readonly_dest.txt"])
4255-
.fails()
4256-
.stderr_contains("readonly_dest.txt")
4257-
.stderr_contains("denied");
4258-
4259-
// Verify content unchanged
4260-
assert_eq!(at.read("readonly_dest.txt"), "original content");
4261-
}
4262-
4263-
/// Test that the fix doesn't break normal copy operations
4264-
#[test]
4265-
fn test_cp_normal_copy_still_works() {
4266-
let ts = TestScenario::new(util_name!());
4267-
let at = &ts.fixtures;
4268-
4269-
// Batch file operations for consistency with other tests
4270-
at.write("source.txt", "source content");
4271-
at.write("dest.txt", "dest content");
4272-
4273-
ts.ucmd().args(&["source.txt", "dest.txt"]).succeeds();
4274-
4275-
assert_eq!(at.read("dest.txt"), "source content");
4276-
}
4277-
42784156
#[test]
42794157
#[cfg(all(unix, not(target_os = "freebsd")))]
42804158
fn test_cp_attributes_only() {

0 commit comments

Comments
 (0)