8000 df: -h -H shouldn't cause an error #3366 by gmnsii · Pull Request #3414 · uutils/coreutils · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

df: -h -H shouldn't cause an error #3366 #3414

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 2 commits into from
Apr 18, 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
25 changes: 19 additions & 6 deletions src/uu/df/src/df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ impl fmt::Display for DfError {
#[uucore::main]
pub fn uumain(args: impl uucore::Args) -> UResult<()> {
let matches = uu_app().get_matches_from(args);

#[cfg(windows)]
{
if matches.is_present(OPT_INODES) {
Expand Down Expand Up @@ -422,54 +423,64 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_ALL)
.short('a')
.long("all")
.overrides_with(OPT_ALL)
.help("include dummy file systems"),
)
.arg(
Arg::new(OPT_BLOCKSIZE)
.short('B')
.long("block-size")
.takes_value(true)
.overrides_with_all(&[OPT_KILO, OPT_BLOCKSIZE])
.help(
"scale sizes by SIZE before printing them; e.g.\
'-BM' prints sizes in units of 1,048,576 bytes",
'-BM' prints sizes in units of 1,048,576 bytes",
),
)
.arg(
Arg::new(OPT_TOTAL)
.long("total")
.overrides_with(OPT_TOTAL)
.help("produce a grand total"),
)
.arg(
Arg::new(OPT_HUMAN_READABLE_BINARY)
.short('h')
.long("human-readable")
.conflicts_with(OPT_HUMAN_READABLE_DECIMAL)
.overrides_with_all(&[OPT_HUMAN_READABLE_DECIMAL, OPT_HUMAN_READABLE_BINARY])
.help("print sizes in human readable format (e.g., 1K 234M 2G)"),
)
.arg(
Arg::new(OPT_HUMAN_READABLE_DECIMAL)
.short('H')
.long("si")
.conflicts_with(OPT_HUMAN_READABLE_BINARY)
.overrides_with_all(&[OPT_HUMAN_READABLE_BINARY, OPT_HUMAN_READABLE_DECIMAL])
.help("likewise, but use powers of 1000 not 1024"),
)
.arg(
Arg::new(OPT_INODES)
.short('i')
.long("inodes")
.overrides_with(OPT_INODES)
.help("list inode information instead of block usage"),
)
.arg(Arg::new(OPT_KILO).short('k').help("like --block-size=1K"))
.arg(
Arg::new(OPT_KILO)
.short('k')
.help("like --block-size=1K")
.overrides_with_all(&[OPT_BLOCKSIZE, OPT_KILO]),
)
.arg(
Arg::new(OPT_LOCAL)
.short('l')
.long("local")
.overrides_with(OPT_LOCAL)
.help("limit listing to local file systems"),
)
.arg(
Arg::new(OPT_NO_SYNC)
.long("no-sync")
.conflicts_with(OPT_SYNC)
.overrides_with_all(&[OPT_SYNC, OPT_NO_SYNC])
.help("do not invoke sync before getting usage info (default)"),
)
.arg(
Expand All @@ -493,12 +504,13 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_PORTABILITY)
.short('P')
.long("portability")
.overrides_with(OPT_PORTABILITY)
.help("use the POSIX output format"),
)
.arg(
Arg::new(OPT_SYNC)
.long("sync")
.conflicts_with(OPT_NO_SYNC)
.overrides_with_all(&[OPT_NO_SYNC, OPT_SYNC])
.help("invoke sync before getting usage info"),
)
.arg(
Expand All @@ -514,6 +526,7 @@ pub fn uu_app<'a>() -> Command<'a> {
Arg::new(OPT_PRINT_TYPE)
.short('T')
.long("print-type")
.overrides_with(OPT_PRINT_TYPE)
.help("print file system type"),
)
.arg(
Expand Down
54 changes: 54 additions & 0 deletions tests/by-util/test_df.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,44 @@ fn test_df_compatible_si() {
new_ucmd!().arg("-aH").succeeds();
}

#[test]
fn test_df_arguments_override_themselves() {
new_ucmd!().args(&["--help", "--help"]).succeeds();
new_ucmd!().arg("-aa").succeeds();
new_ucmd!()
.args(&["--block-size=3000", "--block-size=1000"])
.succeeds();
new_ucmd!().args(&["--total", "--total"]).succeeds();
new_ucmd!().arg("-hh").succeeds();
new_ucmd!().arg("-HH").succeeds();
new_ucmd!().arg("-ii").succeeds();
new_ucmd!().arg("-kk").succeeds();
new_ucmd!().arg("-ll").succeeds();
new_ucmd!().args(&["--no-sync", "--no-sync"]).succeeds();
new_ucmd!().arg("-PP").succeeds();
new_ucmd!().args(&["--sync", "--sync"]).succeeds();
new_ucmd!().arg("-TT").succeeds();
}

#[test]
fn test_df_conflicts_overriding() {
new_ucmd!().arg("-hH").succeeds();
new_ucmd!().arg("-Hh").succeeds();
new_ucmd!().args(&["--no-sync", "--sync"]).succeeds();
new_ucmd!().args(&["--sync", "--no-sync"]).succeeds();
new_ucmd!().args(&["-k", "--block-size=3000"]).succeeds();
new_ucmd!().args(&["--block-size=3000", "-k"]).succeeds();
}

#[test]
fn test_df_output_arg() {
new_ucmd!().args(&["--output=source", "-iPT"]).fails();
new_ucmd!().args(&["-iPT", "--output=source"]).fails();
new_ucmd!()
.args(&["--output=source", "--output=source"])
.fails();
}

#[test]
fn test_df_output() {
let expected = if cfg!(target_os = "macos") {
Expand All @@ -42,6 +80,22 @@ fn test_df_output() {
assert_eq!(actual, expected);
}

#[test]
fn test_df_output_overridden() {
let expected = if cfg!(target_os = "macos") {
"Filesystem Size Used Available Capacity Use% Mounted on "
} else {
"Filesystem Size Used Available Use% Mounted on "
};
let output = new_ucmd!()
.arg("-hH")
.arg("--total")
.succeeds()
.stdout_move_str();
let actual = output.lines().take(1).collect::<Vec<&str>>()[0];
assert_eq!(actual, expected);
}

#[test]
fn test_total_option_with_single_dash() {
// These should fail because `-total` should have two dashes,
Expand Down
0