1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 11:37:44 +00:00

Merge pull request #5626 from cakebaker/ls_invalid_block_size

ls: handle invalid block size as GNU does
This commit is contained in:
Sylvestre Ledru 2023-12-11 07:49:38 +01:00 committed by GitHub
commit 4442b35370
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 5 deletions

View file

@ -183,7 +183,7 @@ impl UError for LsError {
Self::IOError(_) => 1,
Self::IOErrorContext(_, _, false) => 1,
Self::IOErrorContext(_, _, true) => 2,
Self::BlockSizeParseError(_) => 1,
Self::BlockSizeParseError(_) => 2,
Self::ConflictingArgumentDired => 1,
Self::DiredAndZeroAreIncompatible => 2,
Self::AlreadyListedError(_) => 2,
@ -809,10 +809,9 @@ impl Config {
match parse_size_u64(&raw_block_size.to_string_lossy()) {
Ok(size) => Some(size),
Err(_) => {
show!(LsError::BlockSizeParseError(
opt_block_size.unwrap().clone()
));
None
return Err(Box::new(LsError::BlockSizeParseError(
opt_block_size.unwrap().clone(),
)));
}
}
} else if env_var_posixly_correct.is_some() {

View file

@ -3864,6 +3864,16 @@ fn test_posixly_correct() {
.stdout_contains_line("total 8");
}
#[test]
fn test_ls_invalid_block_size() {
new_ucmd!()
.arg("--block-size=invalid")
.fails()
.code_is(2)
.no_stdout()
.stderr_is("ls: invalid --block-size argument 'invalid'\n");
}
#[test]
fn test_ls_hyperlink() {
let scene = TestScenario::new(util_name!());