diff --git a/src/uu/test/src/test.rs b/src/uu/test/src/test.rs index 58cff2684a5..c1766f5481e 100644 --- a/src/uu/test/src/test.rs +++ b/src/uu/test/src/test.rs @@ -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")), } } diff --git a/tests/by-util/test_test.rs b/tests/by-util/test_test.rs index d7f8215bdb5..c767efa69b6 100644 --- a/tests/by-util/test_test.rs +++ b/tests/by-util/test_test.rs @@ -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();