Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/uu/chmod/src/chmod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,6 @@ mod tests {
let (c, a, i) = extract_negative_modes(["--", "-r", "file"].iter().map(OsString::from));
assert_eq!(c, None);
assert_eq!(a, ["--", "-r", "file"]);
assert!(i.is_empty());

@oech3 oech3 Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I like previous one. Can we disable the clippy?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Me too. We can disable a particular clippy rule globally, but you would not have consistency (as both mechanisms would be allowed). My suggestion is to follow the default config from clippy in this case assert_is_empty.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

disabled at #15026

assert_eq!(i, [] as [usize; 0]);
}
}
20 changes: 10 additions & 10 deletions src/uu/cp/src/platform/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ fn check_sparse_detection(src_file: &File) -> io::Result<bool> {
fn sparse_copy_without_hole_fd(src_file: &File, dst_file: &File, context: &str) -> CopyResult<()> {
let ctx_err = |e: io::Error| CpError::IoErrContext(e, context.to_owned());

let size = src_file.metadata().map_err(&ctx_err)?.size();
let size = src_file.metadata().map_err(ctx_err)?.size();
ftruncate(dst_file, size).map_err(|e| CpError::IoErrContext(e.into(), context.to_owned()))?;
let mut current_offset = 0;
// Maximize the data read at once to 16 MiB to avoid memory hogging with large files
Expand All @@ -178,10 +178,10 @@ fn sparse_copy_without_hole_fd(src_file: &File, dst_file: &File, context: &str)
let buf = &mut buf[..read_len];
src_file
.read_exact_at(buf, current_offset + i)
.map_err(&ctx_err)?;
.map_err(ctx_err)?;
dst_file
.write_all_at(buf, current_offset + i)
.map_err(&ctx_err)?;
.map_err(ctx_err)?;
}
current_offset = hole;
}
Expand All @@ -194,18 +194,18 @@ fn sparse_copy_fd(src_file: &mut File, dst_file: &File, context: &str) -> CopyRe

// Keep the size as u64: on 32-bit targets a usize conversion would
// panic for sources of 4 GiB and more.
let size = src_file.metadata().map_err(&ctx_err)?.size();
let size = src_file.metadata().map_err(ctx_err)?.size();
ftruncate(dst_file, size).map_err(|e| CpError::IoErrContext(e.into(), context.to_owned()))?;

let blksize = dst_file.metadata().map_err(&ctx_err)?.blksize();
let blksize = dst_file.metadata().map_err(ctx_err)?.blksize();
let mut buf: Vec<u8> = vec![0; blksize as usize];
let mut current_offset: u64 = 0;

// TODO Perhaps we can employ the "fiemap ioctl" API to get the
// file extent mappings:
// https://www.kernel.org/doc/html/latest/filesystems/fiemap.html
while current_offset < size {
let this_read = src_file.read(&mut buf).map_err(&ctx_err)?;
let this_read = src_file.read(&mut buf).map_err(ctx_err)?;
if this_read == 0 {
// EOF before the size seen at fstat time (source truncated
// concurrently): shrink the dest to the bytes actually copied
Expand All @@ -218,7 +218,7 @@ fn sparse_copy_fd(src_file: &mut File, dst_file: &File, context: &str) -> CopyRe
if buf.iter().any(|&x| x != 0) {
dst_file
.write_all_at(buf, current_offset)
.map_err(&ctx_err)?;
.map_err(ctx_err)?;
}
current_offset += this_read as u64;
}
Expand Down Expand Up @@ -269,15 +269,15 @@ where

let ctx_err = |e: io::Error| CpError::IoErrContext(e, context.to_owned());

let dest_is_stream = is_stream(&dst_file.metadata().map_err(&ctx_err)?);
let dest_is_stream = is_stream(&dst_file.metadata().map_err(ctx_err)?);
if !dest_is_stream {
// `copy_stream` doesn't clear the dest file, if dest is not a stream, we should clear it manually.
dst_file.set_len(0).map_err(&ctx_err)?;
dst_file.set_len(0).map_err(ctx_err)?;
}

buf_copy::copy_fast(&mut src_file, &mut dst_file)
.map_err(|e| io::Error::other(format!("{e}")))
.map_err(&ctx_err)?;
.map_err(ctx_err)?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/cut/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ExactMatcher<'a> {

impl<'a> ExactMatcher<'a> {
pub fn new(needle: &'a [u8]) -> Self {
assert!(!needle.is_empty());
assert_ne!(needle, []);
Self { needle }
}
}
Expand Down Expand Up @@ -51,7 +51,7 @@ pub struct MbExactMatcher<'a> {

impl<'a> MbExactMatcher<'a> {
pub fn new(needle: &'a [u8]) -> Self {
assert!(!needle.is_empty());
assert_ne!(needle, []);
Self { needle }
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/uu/cut/src/searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ mod exact_searcher_tests {
let matcher = ExactMatcher::new("a".as_bytes());
let iter = Searcher::new(&matcher, "".as_bytes());
let items: Vec<(usize, usize)> = iter.collect();
assert!(items.is_empty());
assert_eq!(items, [] as [(usize, usize); 0]);
}

fn test_multibyte(line: &[u8], expected: &[(usize, usize)]) {
Expand Down Expand Up @@ -137,7 +137,7 @@ mod whitespace_searcher_tests {
let matcher = WhitespaceMatcher {};
let iter = Searcher::new(&matcher, "".as_bytes());
let items: Vec<(usize, usize)> = iter.collect();
assert!(items.is_empty());
assert_eq!(items, [] as [(usize, usize); 0]);
}

fn test_multispace(line: &[u8], expected: &[(usize, usize)]) {
Expand Down
2 changes: 1 addition & 1 deletion src/uu/dd/src/dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,6 @@ mod tests {
use crate::AlignedBuf;

let buf = AlignedBuf::new(0).unwrap();
assert!(buf.as_bytes().is_empty());
assert_eq!(buf.as_bytes(), []);
}
}
2 changes: 1 addition & 1 deletion src/uu/ls/src/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ impl<'a> StyleManager<'a> {
style_code: &mut String,
) {
if let Some(raw) = self.indicator_codes.get(&indicator).cloned() {
debug_assert!(!raw.is_empty());
debug_assert_ne!(raw, "");
style_code.push_str(self.reset(!self.initial_reset_is_done));
style_code.push_str(ANSI_CSI);
style_code.push_str(&raw);
Expand Down
8 changes: 4 additions & 4 deletions src/uu/ls/src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ mod tests {
fn test_streaming_output_new() {
let collector = StreamingOutput::new();
assert!(collector.entries().is_empty());
assert!(collector.directories().is_empty());
assert!(collector.totals().is_empty());
assert_eq!(collector.directories(), Vec::<PathBuf>::new());
assert_eq!(collector.totals(), Vec::<u64>::new());
}

#[test]
Expand Down Expand Up @@ -369,8 +369,8 @@ mod tests {

collector.clear();
assert!(collector.entries().is_empty());
assert!(collector.directories().is_empty());
assert!(collector.totals().is_empty());
assert_eq!(collector.directories(), Vec::<PathBuf>::new());
assert_eq!(collector.totals(), Vec::<u64>::new());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/uu/printf/src/printf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ fn print_formatted(args: impl uucore::Args) -> UResult<()> {
if let Ok(FormatItem::Spec(_)) = item {
format_seen = true;
}
match item.map_err(&raise)?.write(stdout(), &mut args)? {
match item.map_err(raise)?.write(stdout(), &mut args)? {
ControlFlow::Continue(()) => {}
ControlFlow::Break(()) => return Ok(()),
}
Expand All @@ -127,7 +127,7 @@ fn print_formatted(args: impl uucore::Args) -> UResult<()> {

while !args.is_exhausted() {
for item in parse_spec_and_escape(format) {
match item.map_err(&raise)?.write(stdout(), &mut args)? {
match item.map_err(raise)?.write(stdout(), &mut args)? {
ControlFlow::Continue(()) => {}
ControlFlow::Break(()) => return Ok(()),
}
Expand Down
10 changes: 5 additions & 5 deletions src/uu/ptx/src/ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1184,8 +1184,8 @@ mod tests {
assert_eq!(chunks.keyword, "nut");
assert_eq!(chunks.after, " cake tart pie");
// Nothing wrapped around the ends of the line.
assert!(chunks.head.is_empty());
assert!(chunks.tail.is_empty());
assert_eq!(chunks.head, "");
assert_eq!(chunks.tail, "");
}

#[test]
Expand All @@ -1204,8 +1204,8 @@ mod tests {
assert_eq!(chunks.before, "/plum");
// No word at all fit to the right of the keyword.
assert_eq!(chunks.after, "/");
assert!(chunks.head.is_empty());
assert!(chunks.tail.is_empty());
assert_eq!(chunks.head, "");
assert_eq!(chunks.tail, "");
}

#[test]
Expand All @@ -1222,6 +1222,6 @@ mod tests {
&chars(" cake tart pie"),
);
assert_eq!(chunks.before, "plum");
assert!(chunks.after.is_empty());
assert_eq!(chunks.after, "");
}
}
2 changes: 1 addition & 1 deletion src/uu/shuf/src/shuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ mod test_split_seps {

#[test]
fn test_empty_input() {
assert!(split_seps(b"", b'\n').is_empty());
assert_eq!(split_seps(b"", b'\n'), [] as [&[u8]; 0]);
}

#[test]
Expand Down
14 changes: 7 additions & 7 deletions src/uu/sort/src/chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,13 @@ fn parse_lines<'a>(

let read = read.strip_suffix(&[separator]).unwrap_or(read);

assert!(lines.is_empty());
assert!(line_data.selections.is_empty());
assert!(line_data.num_infos.is_empty());
assert!(line_data.parsed_floats.is_empty());
assert!(line_data.line_num_floats.is_empty());
assert!(line_data.collation_key_buffer.is_empty());
assert!(line_data.collation_key_ends.is_empty());
assert_eq!(lines.len(), 0);
assert_eq!(line_data.selections.len(), 0);
assert_eq!(line_data.num_infos.len(), 0);
assert_eq!(line_data.parsed_floats.len(), 0);
assert_eq!(line_data.line_num_floats.len(), 0);
assert_eq!(line_data.collation_key_buffer.len(), 0);
assert_eq!(line_data.collation_key_ends.len(), 0);
token_buffer.clear();
let mut estimated = (*line_count_hint).max(1);
let mut exact_line_count = None;
Expand Down
2 changes: 1 addition & 1 deletion src/uu/sort/src/sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ fn tokenize(
token_buffer: &mut Vec<Field>,
precomputed: &Precomputed,
) {
assert!(token_buffer.is_empty());
assert_eq!(token_buffer.as_slice(), []);
if let Some(separator) = separator {
tokenize_with_separator(line, separator, token_buffer);
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/uucore/src/lib/features/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl Base64SimdWrapper {
) -> Self {
assert!(valid_decoding_multiple > 0);
assert!(unpadded_multiple > 0);
assert!(!alphabet.is_empty());
assert_ne!(alphabet, []);

Self {
alphabet,
Expand Down Expand Up @@ -195,7 +195,7 @@ impl EncodingWrapper {

assert!(unpadded_multiple > 0);

assert!(!alphabet.is_empty());
assert_ne!(alphabet, []);

Self {
alphabet,
Expand Down
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/fsext/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ mod tests {
.all(|m| m.mount_dir.to_string_lossy().ends_with('\\'))
);
let system = mounts.iter().find(|m| m.mount_dir == system_drive).unwrap();
assert!(!system.fs_type.is_empty());
assert_ne!(system.fs_type, "");
assert_eq!(system.dev_name, system_drive.to_string_lossy());
}
}
2 changes: 1 addition & 1 deletion src/uucore/src/lib/features/i18n/charmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Encoding {
/// `bytes.len()`, and never `0` for a non-empty slice.
#[inline]
pub fn char_len(self, bytes: &[u8]) -> usize {
debug_assert!(!bytes.is_empty());
debug_assert_ne!(bytes, []);
let b0 = bytes[0];
if b0 <= 0x7F {
return 1;
Expand Down
12 changes: 6 additions & 6 deletions src/uucore/src/lib/mods/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1748,7 +1748,7 @@ invalid-syntax = This is { $missing
// Test that we can get messages (should use embedded English for "test" utility)
let message = get_message("test-about");
// Since we're using embedded resources, we should get the expected message
assert!(!message.is_empty());
assert_ne!(message, "");

// Restore original LANG value
if let Some(val) = original_lang {
Expand Down Expand Up @@ -1779,7 +1779,7 @@ invalid-syntax = This is { $missing

// Should fall back to English embedded resources
let message = get_message("test-about");
assert!(!message.is_empty()); // Should get something, not just the key
assert_ne!(message, ""); // Should get something, not just the key

// Restore original LANG value
if let Some(val) = original_lang {
Expand Down Expand Up @@ -1858,18 +1858,18 @@ invalid-syntax = This is { $missing
// Test that common strings are available after initialization
let error_after_init = get_message("common-error");
// Should either be translated or return the key (but not panic)
assert!(!error_after_init.is_empty());
assert_ne!(error_after_init, "");

let tip_after_init = get_message("common-tip");
assert!(!tip_after_init.is_empty());
assert_ne!(tip_after_init, "");

// Test that clap error keys work with fallbacks
let unknown_arg_key = get_message("clap-error-unexpected-argument");
assert!(!unknown_arg_key.is_empty());
assert_ne!(unknown_arg_key, "");

// Test usage key fallback
let usage_key = get_message("common-usage");
assert!(!usage_key.is_empty());
assert_ne!(usage_key, "");
})
.join()
.unwrap();
Expand Down
9 changes: 1 addition & 8 deletions tests/by-util/test_basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,7 @@ fn test_zero_param() {
}

fn expect_error(input: &[&str]) {
assert!(
!new_ucmd!()
.args(input)
.fails()
.no_stdout()
.stderr_str()
.is_empty()
);
assert_ne!(new_ucmd!().args(input).fails().no_stdout().stderr_str(), "");
}

#[test]
Expand Down
Loading
Loading