8000 df: show error if all types are excluded by cakebaker · Pull Request #3418 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

df: show error if all types are excluded #3418

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 1 commit into from
Apr 20, 2022
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
3 changes: 2 additions & 1 deletion src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ fn get_all_filesystems(opt: &Options) -> Vec<Filesystem> {
mounts
.into_iter()
.filter_map(|m| Filesystem::new(m, None))
.filter(|fs| opt.show_all_fs || fs.usage.blocks > 0)
.collect()
}

Expand Down Expand Up @@ -362,7 +363,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let filesystems = get_all_filesystems(&opt);

if filesystems.is_empty() {
return Err(USimpleError::new(1, "No file systems processed"));
return Err(USimpleError::new(1, "no file systems processed"));
}

filesystems
Expand Down
23 changes: 23 additions & 0 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// spell-checker:ignore udev pcent iuse itotal iused ipcent
use std::collections::HashSet;

use crate::common::util::*;

#[test]
Expand Down Expand Up @@ -204,6 +206,27 @@ fn test_exclude_type_option() {
new_ucmd!().args(&["-x", "ext4", "-x", "ext3"]).succeeds();
}

#[test]
fn test_exclude_all_types() {
let fs_types = new_ucmd!()
.arg("--output=fstype")
.succeeds()
.stdout_move_str();
let fs_types: HashSet<_> = fs_types.lines().skip(1).collect();
Copy link
Member

Choose a reason for hiding this comment

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

Nice test! Is there a particular reason to use a HashSet here instead of a Vec? If not then HashSet is still fine, but I'm just curious :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it was more of an intuitive decision to use a HashSet. It avoids duplicates because for the test it only matters that a file system type is there, but not how often.


let mut args = Vec::new();

for fs_type in fs_types {
args.push("-x");
args.push(fs_type.trim_end());
}

new_ucmd!()
.args(&args)
.fails()
.stderr_contains("no file systems processed");
}

#[test]
fn test_include_exclude_same_type() {
new_ucmd!()
Expand Down
0