8000 df: show "block-size argument too large" error by cakebaker · Pull Request #3458 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

df: show "block-size argument too large" error #3458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
21 changes: 15 additions & 6 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod table;
use uucore::display::Quotable;
use uucore::error::{UError, UResult, USimpleError};
use uucore::fsext::{read_fs_list, MountInfo};
use uucore::parse_size::ParseSizeError;
use uucore::{format_usage, show};

use clap::{crate_version, Arg, ArgMatches, Command};
Expand Down Expand Up @@ -105,7 +106,8 @@ impl Default for Options {

#[derive(Debug)]
enum OptionsError {
InvalidBlockSize,
BlockSizeTooLarge(String),
InvalidBlockSize(String),

/// An error getting the columns to display in the output table.
ColumnError(ColumnError),
Expand All @@ -116,11 +118,14 @@ enum OptionsError {
impl fmt::Display for OptionsError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8000 match self {
// TODO This should include the raw string provided as the argument.
//
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.
Self::InvalidBlockSize => write!(f, "invalid --block-size argument"),
Self::BlockSizeTooLarge(s) => {
write!(f, "--block-size argument {} too large", s.quote())
}
// TODO This needs to vary based on whether `--block-size`
// or `-B` were provided.
Self::InvalidBlockSize(s) => write!(f, "invalid --block-size argument {}", s),
Self::ColumnError(ColumnError::MultipleColumns(s)) => write!(
f,
"option --output: field {} used more than once",
Expand Down Expand Up @@ -155,8 +160,12 @@ impl Options {
Ok(Self {
show_local_fs: matches.is_present(OPT_LOCAL),
show_all_fs: matches.is_present(OPT_ALL),
block_size: block_size_from_matches(matches)
.map_err(|_| OptionsError::InvalidBlockSize)?,
block_size: block_size_from_matches(matches).map_err(|e| match e {
ParseSizeError::SizeTooBig(_) => OptionsError::BlockSizeTooLarge(
matches.value_of(OPT_BLOCKSIZE).unwrap().to_string(),
),
ParseSizeError::ParseFailure(s) => OptionsError::InvalidBlockSize(s),
})?,
include,
exclude,
show_total: matches.is_present(OPT_TOTAL),
Expand Down
24 changes: 24 additions & 0 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,30 @@ fn test_block_size_with_suffix() {
//assert_eq!(get_header("1GB"), "1GB-blocks");
}

#[test]
fn test_too_large_block_size() {
fn run_command(size: &str) {
new_ucmd!()
.arg(format!("--block-size={}", size))
.fails()
.stderr_contains(format!("--block-size argument '{}' too large", size));
}

let too_large_sizes = vec!["1Y", "1Z"];

for size in too_large_sizes {
run_command(size);
}
}

#[test]
fn test_invalid_block_size() {
new_ucmd!()
.arg("--block-size=x")
.fails()
.stderr_contains("invalid --block-size argument 'x'");
}

#[test]
fn test_output_selects_columns() {
let output = new_ucmd!()
Expand Down
0