diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index f6e09420482..e82873f3a2b 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -102,8 +102,8 @@ impl AddAssign for Row { let bytes = self.bytes + rhs.bytes; let bytes_used = self.bytes_used + rhs.bytes_used; let bytes_avail = self.bytes_avail + rhs.bytes_avail; - let inodes = self.inodes + rhs.inodes; - let inodes_used = self.inodes_used + rhs.inodes_used; + let inodes = self.inodes.saturating_add(rhs.inodes); + let inodes_used = self.inodes_used.saturating_add(rhs.inodes_used); *self = Self { file: None, fs_device: "total".into(), @@ -125,7 +125,7 @@ impl AddAssign for Row { bytes_capacity: None, inodes, inodes_used, - inodes_free: self.inodes_free + rhs.inodes_free, + inodes_free: self.inodes_free.saturating_add(rhs.inodes_free), inodes_usage: if inodes == 0 { None } else { diff --git a/tests/by-util/test_df.rs b/tests/by-util/test_df.rs index 0276f18c3c1..43b1651c6d3 100644 --- a/tests/by-util/test_df.rs +++ b/tests/by-util/test_df.rs @@ -264,13 +264,18 @@ fn test_type_option() { #[test] #[cfg(not(any(target_os = "freebsd", target_os = "windows")))] // FIXME: fix test for FreeBSD & Win fn test_type_option_with_file() { - let fs_type = new_ucmd!() + let fs_type_cwd = new_ucmd!() .args(&["--output=fstype", "."]) .succeeds() .stdout_move_str(); - let fs_type = fs_type.lines().nth(1).unwrap().trim(); + let fs_type_cwd = fs_type_cwd.lines().nth(1).unwrap().trim(); + let fs_type_root_dir = new_ucmd!() + .args(&["--output=fstype", "/"]) + .succeeds() + .stdout_move_str(); + let fs_type_root_dir = fs_type_root_dir.lines().nth(1).unwrap().trim(); - new_ucmd!().args(&["-t", fs_type, "."]).succeeds(); + new_ucmd!().args(&["-t", fs_type_cwd, "."]).succeeds(); new_ucmd!() .args(&["-t", "nonexisting", "."]) .fails() @@ -283,7 +288,7 @@ fn test_type_option_with_file() { let fs_types: Vec<_> = fs_types .lines() .skip(1) - .filter(|t| t.trim() != fs_type && t.trim() != "") + .filter(|t| t.trim() != fs_type_cwd && t.trim() != fs_type_root_dir && t.trim() != "") .collect(); if !fs_types.is_empty() { diff --git a/tests/by-util/test_ls.rs b/tests/by-util/test_ls.rs index 8d4e5875951..de593d53266 100644 --- a/tests/by-util/test_ls.rs +++ b/tests/by-util/test_ls.rs @@ -115,13 +115,24 @@ fn test_ls_allocation_size() { .succeeds() .stdout_matches(&Regex::new("[^ ] 2 [^ ]").unwrap()); + #[cfg(all( + not(target_os = "freebsd"), + not(all(target_os = "android", target_pointer_width = "64")) + ))] + let (zero_file_size_4k, zero_file_size_1k, zero_file_size_8k, zero_file_size_4m) = + (4096, 1024, 8192, "4.0M"); + + #[cfg(all(target_os = "android", target_pointer_width = "64"))] + let (zero_file_size_4k, zero_file_size_1k, zero_file_size_8k, zero_file_size_4m) = + (4100, 1025, 8200, "4.1M"); // FIXME: Investigate where this difference comes from. Is it OS or filesystem? + #[cfg(not(target_os = "freebsd"))] scene .ucmd() .arg("-s1") .arg("some-dir1") .succeeds() - .stdout_is("total 4096\n 0 empty-file\n 0 file-with-holes\n4096 zero-file\n"); + .stdout_is(format!("total {zero_file_size_4k}\n 0 empty-file\n 0 file-with-holes\n{zero_file_size_4k} zero-file\n")); scene .ucmd() @@ -138,7 +149,7 @@ fn test_ls_allocation_size() { .arg("some-dir1") .succeeds() .stdout_contains("0 empty-file") - .stdout_contains("4096 zero-file"); + .stdout_contains(format!("{zero_file_size_4k} zero-file")); // Test alignment of different block sized files let res = scene.ucmd().arg("-si1").arg("some-dir1").succeeds(); @@ -185,10 +196,10 @@ fn test_ls_allocation_size() { .arg("-s1") .arg("some-dir1") .succeeds() - .stdout_contains("total 1024") + .stdout_contains(format!("total {zero_file_size_1k}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("1024 zero-file"); + .stdout_contains(format!("{zero_file_size_1k} zero-file")); #[cfg(not(target_os = "freebsd"))] scene @@ -210,10 +221,10 @@ fn test_ls_allocation_size() { .arg("-s1") .arg("some-dir1") .succeeds() - .stdout_contains("total 1024") + .stdout_contains(format!("total {zero_file_size_1k}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("1024 zero-file"); + .stdout_contains(format!("{zero_file_size_1k} zero-file")); #[cfg(not(target_os = "freebsd"))] scene @@ -222,10 +233,10 @@ fn test_ls_allocation_size() { .arg("-s1") .arg("some-dir1") .succeeds() - .stdout_contains("total 8192") + .stdout_contains(format!("total {zero_file_size_8k}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("8192 zero-file"); + .stdout_contains(format!("{zero_file_size_8k} zero-file")); // -k should make 'ls' ignore the env var #[cfg(not(target_os = "freebsd"))] @@ -235,10 +246,10 @@ fn test_ls_allocation_size() { .arg("-s1k") .arg("some-dir1") .succeeds() - .stdout_contains("total 4096") + .stdout_contains(format!("total {zero_file_size_4k}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("4096 zero-file"); + .stdout_contains(format!("{zero_file_size_4k} zero-file")); // but manually specified blocksize overrides -k #[cfg(not(target_os = "freebsd"))] @@ -248,10 +259,10 @@ fn test_ls_allocation_size() { .arg("--block-size=4K") .arg("some-dir1") .succeeds() - .stdout_contains("total 1024") + .stdout_contains(format!("total {zero_file_size_1k}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("1024 zero-file"); + .stdout_contains(format!("{zero_file_size_1k} zero-file")); #[cfg(not(target_os = "freebsd"))] scene @@ -260,10 +271,10 @@ fn test_ls_allocation_size() { .arg("--block-size=4K") .arg("some-dir1") .succeeds() - .stdout_contains("total 1024") + .stdout_contains(format!("total {zero_file_size_1k}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("1024 zero-file"); + .stdout_contains(format!("{zero_file_size_1k} zero-file")); // si option should always trump the human-readable option #[cfg(not(target_os = "freebsd"))] @@ -285,10 +296,10 @@ fn test_ls_allocation_size() { .arg("--block-size=human-readable") .arg("some-dir1") .succeeds() - .stdout_contains("total 4.0M") + .stdout_contains(format!("total {zero_file_size_4m}")) .stdout_contains("0 empty-file") .stdout_contains("0 file-with-holes") - .stdout_contains("4.0M zero-file"); + .stdout_contains(format!("{zero_file_size_4m} zero-file")); #[cfg(not(target_os = "freebsd"))] scene