|
2 | 2 | // |
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | | -// spell-checker:ignore udev pcent iuse itotal iused ipcent |
| 5 | +// spell-checker:ignore udev pcent iuse itotal iused ipcent binfmt |
6 | 6 | #![allow( |
7 | 7 | clippy::similar_names, |
8 | 8 | clippy::cast_possible_truncation, |
@@ -1046,3 +1046,48 @@ fn test_nonexistent_file() { |
1046 | 1046 | .stderr_is("df: does-not-exist: No such file or directory\n") |
1047 | 1047 | .stdout_is("File\n.\n"); |
1048 | 1048 | } |
| 1049 | + |
| 1050 | +#[test] |
| 1051 | +#[cfg(target_os = "linux")] |
| 1052 | +fn test_df_all_shows_binfmt_misc() { |
| 1053 | + // Check if binfmt_misc is mounted |
| 1054 | + let is_mounted = std::fs::read_to_string("/proc/self/mountinfo") |
| 1055 | + .map(|content| content.lines().any(|line| line.contains("binfmt_misc"))) |
| 1056 | + .unwrap_or(false); |
| 1057 | + |
| 1058 | + if is_mounted { |
| 1059 | + let output = new_ucmd!() |
| 1060 | + .args(&["--all", "--output=fstype,target"]) |
| 1061 | + .succeeds() |
| 1062 | + .stdout_str_lossy(); |
| 1063 | + |
| 1064 | + assert!( |
| 1065 | + output.contains("binfmt_misc"), |
| 1066 | + "Expected binfmt_misc filesystem to appear in df --all output when it's mounted" |
| 1067 | + ); |
| 1068 | + } |
| 1069 | + // If binfmt_misc is not mounted, skip the test silently |
| 1070 | +} |
| 1071 | + |
| 1072 | +#[test] |
| 1073 | +#[cfg(target_os = "linux")] |
| 1074 | +fn test_df_hides_binfmt_misc_by_default() { |
| 1075 | + // Check if binfmt_misc is mounted |
| 1076 | + let is_mounted = std::fs::read_to_string("/proc/self/mountinfo") |
| 1077 | + .map(|content| content.lines().any(|line| line.contains("binfmt_misc"))) |
| 1078 | + .unwrap_or(false); |
| 1079 | + |
| 1080 | + if is_mounted { |
| 1081 | + let output = new_ucmd!() |
| 1082 | + .args(&["--output=fstype,target"]) |
| 1083 | + .succeeds() |
| 1084 | + .stdout_str_lossy(); |
| 1085 | + |
| 1086 | + // binfmt_misc should NOT appear in the output without --all |
| 1087 | + assert!( |
| 1088 | + !output.contains("binfmt_misc"), |
| 1089 | + "Expected binfmt_misc filesystem to be hidden in df output without --all" |
| 1090 | + ); |
| 1091 | + } |
| 1092 | + // If binfmt_misc is not mounted, skip the test silently |
| 1093 | +} |
0 commit comments