Skip to content

Commit 7d2d674

Browse files
authored
Merge pull request #8525 from sylvestre/test-chmod
chmod: make a test environment-agnostic
2 parents 1a7e6c0 + 218baa3 commit 7d2d674

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

tests/by-util/test_chmod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,21 @@ fn test_chmod_ugoa() {
232232
}
233233

234234
#[test]
235-
#[cfg(any(target_os = "linux", target_os = "macos"))]
236-
// TODO fix android, it has 0777
237-
// We should force for the umask on startup
235+
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))]
236+
#[allow(clippy::cast_lossless)]
238237
fn test_chmod_umask_expected() {
238+
// Get the actual system umask using libc
239+
let system_umask = unsafe {
240+
let mask = libc::umask(0);
241+
libc::umask(mask);
242+
mask
243+
};
244+
245+
// Now verify that get_umask() returns the same value
239246
let current_umask = uucore::mode::get_umask();
240247
assert_eq!(
241-
current_umask, 0o022,
242-
"Unexpected umask value: expected 022 (octal), but got {current_umask:03o}. Please adjust the test environment.",
248+
current_umask, system_umask as u32,
249+
"get_umask() returned {current_umask:03o}, but system umask is {system_umask:03o}",
243250
);
244251
}
245252

0 commit comments

Comments
 (0)