mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
du, ls: add integration tests for block size env var behavior
This commit is contained in:
committed by
Dorian Péron
parent
a846f91772
commit
32cf4cdf0c
@@ -371,6 +371,74 @@ fn test_du_invalid_binary_size() {
|
||||
.stderr_only("du: invalid suffix in --threshold argument '0b123'\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_invalid_env_block_size_stops_lookup() {
|
||||
// When DU_BLOCK_SIZE is set but invalid, it should stop the lookup
|
||||
// and use the default block size — not fall through to BLOCK_SIZE.
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
let dir = "a";
|
||||
|
||||
at.mkdir(dir);
|
||||
at.write(&format!("{dir}/file"), "some content");
|
||||
|
||||
let default_output = ts
|
||||
.ucmd()
|
||||
.arg(dir)
|
||||
.arg("--block-size=1024")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
// Invalid DU_BLOCK_SIZE should use default (1024), not BLOCK_SIZE=1
|
||||
let result = ts
|
||||
.ucmd()
|
||||
.arg(dir)
|
||||
.env("DU_BLOCK_SIZE", "invalid")
|
||||
.env("BLOCK_SIZE", "1")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
assert_eq!(default_output, result);
|
||||
|
||||
// Empty DU_BLOCK_SIZE should also use default
|
||||
let result = ts
|
||||
.ucmd()
|
||||
.arg(dir)
|
||||
.env("DU_BLOCK_SIZE", "")
|
||||
.env("BLOCK_SIZE", "1")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
assert_eq!(default_output, result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_posixly_correct_default() {
|
||||
// With POSIXLY_CORRECT and no block size env vars, default is 512
|
||||
let ts = TestScenario::new(util_name!());
|
||||
let at = &ts.fixtures;
|
||||
let dir = "a";
|
||||
|
||||
at.mkdir(dir);
|
||||
at.write(&format!("{dir}/file"), "some content");
|
||||
|
||||
let expected = ts
|
||||
.ucmd()
|
||||
.arg(dir)
|
||||
.arg("--block-size=512")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
let result = ts
|
||||
.ucmd()
|
||||
.arg(dir)
|
||||
.env("POSIXLY_CORRECT", "1")
|
||||
.succeeds()
|
||||
.stdout_move_str();
|
||||
|
||||
assert_eq!(expected, result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_du_binary_edge_cases() {
|
||||
let ts = TestScenario::new(util_name!());
|
||||
|
||||
@@ -5781,6 +5781,53 @@ fn test_ls_block_size_override() {
|
||||
.stdout_contains_line("total 8");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
#[cfg(not(target_os = "openbsd"))]
|
||||
fn test_ls_block_size_si_file_size() {
|
||||
// Verify --si and --block-size interaction for file size display in -l
|
||||
let scene = TestScenario::new(util_name!());
|
||||
let at = &scene.fixtures;
|
||||
|
||||
at.write_bytes("file", &[0u8; 1024]);
|
||||
|
||||
// --si last: file size shown as human-readable SI
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.arg("--block-size=512")
|
||||
.arg("--si")
|
||||
.succeeds()
|
||||
.stdout_contains("1.1k");
|
||||
|
||||
// --block-size last: file size shown in 512-byte blocks
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.arg("--si")
|
||||
.arg("--block-size=512")
|
||||
.succeeds()
|
||||
.stdout_contains(" 2 ");
|
||||
|
||||
// --human-readable last: file size shown as human-readable IEC
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.arg("--block-size=512")
|
||||
.arg("--human-readable")
|
||||
.succeeds()
|
||||
.stdout_contains("1.0K");
|
||||
|
||||
// --block-size last: file size shown in 512-byte blocks
|
||||
scene
|
||||
.ucmd()
|
||||
.arg("-l")
|
||||
.arg("--human-readable")
|
||||
.arg("--block-size=512")
|
||||
.succeeds()
|
||||
.stdout_contains(" 2 ");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ls_block_size_override_self() {
|
||||
new_ucmd!()
|
||||
|
||||
Reference in New Issue
Block a user