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

Merge pull request #3513 from cakebaker/portability_headers

df: implement POSIX conform header line
This commit is contained in:
Sylvestre Ledru 2022-05-12 08:33:50 +02:00 committed by GitHub
commit c212f4a556
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 147 additions and 19 deletions

View file

@ -73,7 +73,7 @@ fn test_df_output() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Capacity",
"Use%",
"Mounted",
@ -84,7 +84,7 @@ fn test_df_output() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Use%",
"Mounted",
"on",
@ -107,7 +107,7 @@ fn test_df_output_overridden() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Capacity",
"Use%",
"Mounted",
@ -118,7 +118,7 @@ fn test_df_output_overridden() {
"Filesystem",
"Size",
"Used",
"Available",
"Avail",
"Use%",
"Mounted",
"on",
@ -134,6 +134,46 @@ fn test_df_output_overridden() {
assert_eq!(actual, expected);
}
#[test]
fn test_default_headers() {
let expected = if cfg!(target_os = "macos") {
vec![
"Filesystem",
"1K-blocks",
"Used",
"Available",
"Capacity",
"Use%",
"Mounted",
"on",
]
} else {
vec![
"Filesystem",
"1K-blocks",
"Used",
"Available",
"Use%",
"Mounted",
"on",
]
};
let output = new_ucmd!().succeeds().stdout_move_str();
let actual = output.lines().take(1).collect::<Vec<&str>>()[0];
let actual = actual.split_whitespace().collect::<Vec<_>>();
assert_eq!(actual, expected);
}
#[test]
fn test_precedence_of_human_readable_header_over_output_header() {
let output = new_ucmd!()
.args(&["-H", "--output=size"])
.succeeds()
.stdout_move_str();
let header = output.lines().next().unwrap().to_string();
assert_eq!(header.trim(), "Size");
}
#[test]
fn test_total_option_with_single_dash() {
// These should fail because `-total` should have two dashes,
@ -443,6 +483,31 @@ fn test_block_size_with_suffix() {
assert_eq!(get_header("1GB"), "1GB-blocks");
}
#[test]
fn test_block_size_in_posix_portability_mode() {
fn get_header(block_size: &str) -> String {
let output = new_ucmd!()
.args(&["-P", "-B", block_size])
.succeeds()
.stdout_move_str();
output
.lines()
.next()
.unwrap()
.to_string()
.split_whitespace()
.nth(1)
.unwrap()
.to_string()
}
assert_eq!(get_header("1024"), "1024-blocks");
assert_eq!(get_header("1K"), "1024-blocks");
assert_eq!(get_header("1KB"), "1000-blocks");
assert_eq!(get_header("1M"), "1048576-blocks");
assert_eq!(get_header("1MB"), "1000000-blocks");
}
#[test]
fn test_too_large_block_size() {
fn run_command(size: &str) {