test: implement -r/-w/-x on Windows (#11120)

* test: implement -r/-w/-x on Windows

* test: fix clippy map-then-unwrap_or lint for Windows executable check

Replace `.map(...).unwrap_or(false)` with `.is_some_and(...)` to satisfy
the `clippy::option_map_unwrap_or` lint on Windows targets.

---------

Co-authored-by: Nihal Ajayakumar <nihal.ajayakumar@gmail.com>
This commit is contained in:
Nihal Ajayakumar
2026-02-26 09:37:39 +01:00
committed by GitHub
co-authored by Nihal Ajayakumar
parent e9bedfa387
commit e6d109e7e8
2 changed files with 28 additions and 6 deletions
+6 -3
View File
@@ -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")),
}
}
+22 -3
View File
@@ -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();
}
@@ -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();
}
@@ -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");
@@ -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();