mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
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:
co-authored by
Nihal Ajayakumar
parent
e9bedfa387
commit
e6d109e7e8
@@ -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")),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user