Skip to content
Merged
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
9 changes: 6 additions & 3 deletions src/uu/test/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,12 +341,15 @@ fn path(path: &OsStr, condition: &PathCondition) -> bool {
PathCondition::Sticky => false,
PathCondition::UserOwns => unimplemented!(),
PathCondition::Fifo => false,
PathCondition::Readable => false, // TODO
PathCondition::Readable => true,
PathCondition::Socket => false,
PathCondition::NonEmpty => stat.len() > 0,
PathCondition::UserIdFlag => false,
PathCondition::Writable => false, // TODO
PathCondition::Executable => false, // TODO
PathCondition::Writable => !stat.permissions().readonly(),
PathCondition::Executable => std::path::Path::new(path)
.extension()
.and_then(|e| e.to_str())
.is_some_and(|e| matches!(e, "exe" | "bat" | "cmd" | "com")),
}
}

Expand Down
25 changes: 22 additions & 3 deletions tests/by-util/test_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,6 @@ fn test_file_exists_and_is_regular() {
}

#[test]
#[cfg(not(windows))] // FIXME: implement on Windows
fn test_file_is_readable() {
new_ucmd!().args(&["-r", "regular_file"]).succeeds();
}
Expand All @@ -473,7 +472,6 @@ fn test_file_is_not_readable() {
}

#[test]
#[cfg(not(windows))] // FIXME: implement on Windows
fn test_file_is_writable() {
new_ucmd!().args(&["-w", "regular_file"]).succeeds();
}
Expand Down Expand Up @@ -517,7 +515,7 @@ fn test_file_is_not_executable() {
}

#[test]
#[cfg(not(windows))] // FIXME: implement on Windows
#[cfg(not(windows))]
fn test_file_is_executable() {
let scenario = TestScenario::new(util_name!());
let mut chmod = scenario.cmd("chmod");
Expand All @@ -527,6 +525,27 @@ fn test_file_is_executable() {
scenario.ucmd().args(&["-x", "regular_file"]).succeeds();
}

#[test]
#[cfg(windows)]
fn test_file_is_not_writable_windows() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("readonly_file");
let mut perms = std::fs::metadata(at.plus("readonly_file"))
.unwrap()
.permissions();
perms.set_readonly(true);
std::fs::set_permissions(at.plus("readonly_file"), perms).unwrap();
ucmd.args(&["!", "-w", "readonly_file"]).succeeds();
}

#[test]
#[cfg(windows)]
fn test_file_is_executable_windows() {
let (at, mut ucmd) = at_and_ucmd!();
at.touch("program.exe");
ucmd.args(&["-x", "program.exe"]).succeeds();
}

#[test]
fn test_is_not_empty() {
new_ucmd!().args(&["-s", "non_empty_file"]).succeeds();
Expand Down
Loading