Skip to content

Commit 218baa3

Browse files
committed
chmod: make a test environment-agnostic
run ssh, it might break with: ---- test_chmod::test_chmod_umask_expected stdout ---- thread 'test_chmod::test_chmod_umask_expected' panicked at tests/by-util/test_chmod.rs:240:5: assertion `left == right` failed: Unexpected umask value: expected 022 (octal), but got 002. Please adjust the test environment. left: 2 right: 18 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
1 parent 1a7e6c0 commit 218baa3

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)