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

Merge pull request #3288 from cakebaker/ticket_3252

df: show error if specified type doesn't exist
This commit is contained in:
Sylvestre Ledru 2022-04-14 15:51:05 +02:00 committed by GitHub
commit 4f41e285a8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 10 deletions

View file

@ -358,22 +358,31 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
} }
let opt = Options::from(&matches).map_err(DfError::OptionsError)?; let opt = Options::from(&matches).map_err(DfError::OptionsError)?;
// Get the list of filesystems to display in the output table. // Get the list of filesystems to display in the output table.
let filesystems: Vec<Filesystem> = match matches.values_of(OPT_PATHS) { let filesystems: Vec<Filesystem> = match matches.values_of(OPT_PATHS) {
None => get_all_filesystems(&opt), None => {
let filesystems = get_all_filesystems(&opt);
if filesystems.is_empty() {
return Err(USimpleError::new(1, "No file systems processed"));
}
filesystems
}
Some(paths) => { Some(paths) => {
let paths: Vec<&str> = paths.collect(); let paths: Vec<&str> = paths.collect();
get_named_filesystems(&paths) let filesystems = get_named_filesystems(&paths);
// This can happen if paths are given as command-line arguments
// but none of the paths exist.
if filesystems.is_empty() {
return Ok(());
}
filesystems
} }
}; };
// This can happen if paths are given as command-line arguments
// but none of the paths exist.
if filesystems.is_empty() {
return Ok(());
}
// The running total of filesystem sizes and usage. // The running total of filesystem sizes and usage.
// //
// This accumulator is computed in case we need to display the // This accumulator is computed in case we need to display the

View file

@ -42,6 +42,13 @@ fn test_df_output() {
assert_eq!(actual, expected); assert_eq!(actual, expected);
} }
#[test]
fn test_total_option_with_single_dash() {
// These should fail because `-total` should have two dashes,
// not just one.
new_ucmd!().arg("-total").fails();
}
/// Test that the order of rows in the table does not change across executions. /// Test that the order of rows in the table does not change across executions.
#[test] #[test]
fn test_order_same() { fn test_order_same() {
@ -89,7 +96,17 @@ fn test_output_option_without_equals_sign() {
#[test] #[test]
fn test_type_option() { fn test_type_option() {
new_ucmd!().args(&["-t", "ext4", "-t", "ext3"]).succeeds(); let fs_types = new_ucmd!()
.arg("--output=fstype")
.succeeds()
.stdout_move_str();
let fs_type = fs_types.lines().nth(1).unwrap().trim();
new_ucmd!().args(&["-t", fs_type]).succeeds();
new_ucmd!()
.args(&["-t", fs_type, "-t", "nonexisting"])
.succeeds();
new_ucmd!().args(&["-t", "nonexisting"]).fails();
} }
#[test] #[test]