Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions tests/by-util/test_chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,21 @@ fn test_chmod_ugoa() {
}

#[test]
#[cfg(any(target_os = "linux", target_os = "macos"))]
// TODO fix android, it has 0777
// We should force for the umask on startup
#[cfg(any(target_os = "linux", target_os = "macos", target_os = "android"))]
#[allow(clippy::cast_lossless)]
fn test_chmod_umask_expected() {
// Get the actual system umask using libc
let system_umask = unsafe {
let mask = libc::umask(0);
libc::umask(mask);
mask
};

// Now verify that get_umask() returns the same value
let current_umask = uucore::mode::get_umask();
assert_eq!(
current_umask, 0o022,
"Unexpected umask value: expected 022 (octal), but got {current_umask:03o}. Please adjust the test environment.",
current_umask, system_umask as u32,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, maybe I'm missing something. What's the reason for the conversion (and the corresponding allow(clippy::cast_lossless)? Both libc::umask and uucore::mode::get_umask return a u32 value and so no conversion is necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was failing on mac

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  Checking coreutils v0.1.0 (/Users/runner/work/coreutils/coreutils)
  error: casts from `u16` to `u32` can be expressed infallibly using `From`
     --> tests/by-util/test_chmod.rs:247:24
      |
  247 |         current_umask, system_umask as u32,
      |                        ^^^^^^^^^^^^^^^^^^^
      |
      = help: an `as` cast can become silently lossy if the types change in the future
      = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
      = note: `-D clippy::cast-lossless` implied by `-D clippy::pedantic`
      = help: to override `-D clippy::pedantic` add `#[allow(clippy::cast_lossless)]`
  help: use `u32::from` instead
      |
  247 -         current_umask, system_umask as u32,
  247 +         current_umask, u32::from(system_umask),
      |
  
  error: could not compile `coreutils` (test "tests") due to 1 previous error
Error: Final attempt failed. Child_process exited with error code 1

"get_umask() returned {current_umask:03o}, but system umask is {system_umask:03o}",
);
}

Expand Down
Loading