Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 15 additions & 0 deletions src/uu/du/src/du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,11 @@ pub fn uu_app() -> Command {
Arg::new(options::BYTES)
.short('b')
.long("bytes")
.overrides_with_all([
Comment thread
cerdelen marked this conversation as resolved.
Outdated
options::BLOCK_SIZE_1K,
options::BLOCK_SIZE_1M,
options::BYTES,
])
.help(translate!("du-help-bytes"))
.action(ArgAction::SetTrue),
)
Expand Down Expand Up @@ -1314,6 +1319,11 @@ pub fn uu_app() -> Command {
.arg(
Arg::new(options::BLOCK_SIZE_1K)
.short('k')
.overrides_with_all([
options::BLOCK_SIZE_1K,
options::BLOCK_SIZE_1M,
options::BYTES,
])
.help(translate!("du-help-block-size-1k"))
.action(ArgAction::SetTrue),
)
Expand Down Expand Up @@ -1350,6 +1360,11 @@ pub fn uu_app() -> Command {
.arg(
Arg::new(options::BLOCK_SIZE_1M)
.short('m')
.overrides_with_all([
options::BLOCK_SIZE_1K,
options::BLOCK_SIZE_1M,
options::BYTES,
])
.help(translate!("du-help-block-size-1m"))
.action(ArgAction::SetTrue),
)
Expand Down
42 changes: 42 additions & 0 deletions tests/by-util/test_du.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,3 +2058,45 @@ fn test_du_symlinks_multiple_links_in_args() {
result.stdout_contains("dir1/file");
result.stdout_does_not_contain("dir1/link");
}

#[test]
fn test_block_size_args_override() {
let ts = TestScenario::new(util_name!());
let at = &ts.fixtures;
let dir = "a";

at.mkdir(dir);
let fpath = at.plus(format!("{dir}/file"));
std::fs::File::create(&fpath)
.expect("cannot create test file")
.set_len(100_000_000)
.expect("cannot set file size");

let test_cases = [
(["-sb", "-m"], "-sm"),
(["-sm", "-b"], "-sb"),
(["-sk", "-b"], "-sb"),
(["-sm", "-k"], "-sk"),
];

for (overwriting_args, expected) in test_cases {
let decimal = ts
.ucmd()
.arg(dir)
.args(&overwriting_args)
.succeeds()
.stdout_move_str();

let binary = ts
.ucmd()
.arg(dir)
.arg(expected)
.succeeds()
.stdout_move_str();

assert_eq!(
decimal, binary,
"The last argument of m, k and b should overwrite"
);
}
}
Loading