2022-02-27 16:20:27 +00:00
|
|
|
// spell-checker:ignore udev
|
2020-05-25 17:05:26 +00:00
|
|
|
use crate::common::util::*;
|
2020-04-28 07:34:55 +00:00
|
|
|
|
2020-04-29 17:03:22 +00:00
|
|
|
#[test]
|
|
|
|
fn test_df_compatible_no_size_arg() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!().arg("-a").succeeds();
|
2020-04-29 17:03:22 +00:00
|
|
|
}
|
|
|
|
|
2022-01-29 00:03:28 +00:00
|
|
|
#[test]
|
|
|
|
fn test_df_shortened_long_argument() {
|
|
|
|
new_ucmd!().arg("--a").succeeds();
|
|
|
|
}
|
|
|
|
|
2020-04-28 07:34:55 +00:00
|
|
|
#[test]
|
|
|
|
fn test_df_compatible() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!().arg("-ah").succeeds();
|
2020-04-28 07:34:55 +00:00
|
|
|
}
|
2020-04-30 21:02:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_df_compatible_type() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!().arg("-aT").succeeds();
|
2020-04-30 21:02:22 +00:00
|
|
|
}
|
2020-04-29 17:03:22 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_df_compatible_si() {
|
2021-04-22 20:37:44 +00:00
|
|
|
new_ucmd!().arg("-aH").succeeds();
|
2020-04-29 17:03:22 +00:00
|
|
|
}
|
|
|
|
|
2021-05-03 08:55:17 +00:00
|
|
|
#[test]
|
|
|
|
fn test_df_output() {
|
|
|
|
if cfg!(target_os = "macos") {
|
|
|
|
new_ucmd!().arg("-H").arg("-total").succeeds().
|
|
|
|
stdout_only("Filesystem Size Used Available Capacity Use% Mounted on \n");
|
|
|
|
} else {
|
|
|
|
new_ucmd!().arg("-H").arg("-total").succeeds().stdout_only(
|
2021-05-08 11:13:52 +00:00
|
|
|
"Filesystem Size Used Available Use% Mounted on \n",
|
2021-05-03 08:55:17 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-13 02:02:09 +00:00
|
|
|
/// Test that the order of rows in the table does not change across executions.
|
|
|
|
#[test]
|
|
|
|
fn test_order_same() {
|
|
|
|
// TODO When #3057 is resolved, we should just use
|
|
|
|
//
|
|
|
|
// new_ucmd!().arg("--output=source").succeeds().stdout_move_str();
|
|
|
|
//
|
|
|
|
// instead of parsing the entire `df` table as a string.
|
|
|
|
let output1 = new_ucmd!().succeeds().stdout_move_str();
|
|
|
|
let output2 = new_ucmd!().succeeds().stdout_move_str();
|
|
|
|
let output1: Vec<String> = output1
|
|
|
|
.lines()
|
|
|
|
.map(|l| String::from(l.split_once(' ').unwrap().0))
|
|
|
|
.collect();
|
|
|
|
let output2: Vec<String> = output2
|
|
|
|
.lines()
|
|
|
|
.map(|l| String::from(l.split_once(' ').unwrap().0))
|
|
|
|
.collect();
|
|
|
|
assert_eq!(output1, output2);
|
|
|
|
}
|
|
|
|
|
2022-02-17 05:43:59 +00:00
|
|
|
#[test]
|
|
|
|
fn test_output_conflict_options() {
|
|
|
|
for option in ["-i", "-T", "-P"] {
|
|
|
|
new_ucmd!().arg("--output=source").arg(option).fails();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_output_option() {
|
|
|
|
new_ucmd!().arg("--output").succeeds();
|
|
|
|
new_ucmd!().arg("--output=source,target").succeeds();
|
|
|
|
new_ucmd!().arg("--output=invalid_option").fails();
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_type_option() {
|
|
|
|
new_ucmd!().args(&["-t", "ext4", "-t", "ext3"]).succeeds();
|
|
|
|
}
|
|
|
|
|
2022-02-27 16:20:27 +00:00
|
|
|
#[test]
|
|
|
|
fn test_total() {
|
|
|
|
// Example output:
|
|
|
|
//
|
|
|
|
// Filesystem 1K-blocks Used Available Use% Mounted on
|
|
|
|
// udev 3858016 0 3858016 0% /dev
|
|
|
|
// ...
|
|
|
|
// /dev/loop14 63488 63488 0 100% /snap/core20/1361
|
|
|
|
// total 258775268 98099712 148220200 40% -
|
|
|
|
let output = new_ucmd!().arg("--total").succeeds().stdout_move_str();
|
|
|
|
|
|
|
|
// Skip the header line.
|
|
|
|
let lines: Vec<&str> = output.lines().skip(1).collect();
|
|
|
|
|
|
|
|
// Parse the values from the last row.
|
|
|
|
let last_line = lines.last().unwrap();
|
|
|
|
let mut iter = last_line.split_whitespace();
|
|
|
|
assert_eq!(iter.next().unwrap(), "total");
|
|
|
|
let reported_total_size = iter.next().unwrap().parse().unwrap();
|
|
|
|
let reported_total_used = iter.next().unwrap().parse().unwrap();
|
|
|
|
let reported_total_avail = iter.next().unwrap().parse().unwrap();
|
|
|
|
|
|
|
|
// Loop over each row except the last, computing the sum of each column.
|
|
|
|
let mut computed_total_size = 0;
|
|
|
|
let mut computed_total_used = 0;
|
|
|
|
let mut computed_total_avail = 0;
|
|
|
|
let n = lines.len();
|
|
|
|
for line in &lines[..n - 1] {
|
|
|
|
let mut iter = line.split_whitespace();
|
|
|
|
iter.next().unwrap();
|
|
|
|
computed_total_size += iter.next().unwrap().parse::<u64>().unwrap();
|
|
|
|
computed_total_used += iter.next().unwrap().parse::<u64>().unwrap();
|
|
|
|
computed_total_avail += iter.next().unwrap().parse::<u64>().unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the sum of each column matches the reported value in
|
|
|
|
// the last row.
|
|
|
|
assert_eq!(computed_total_size, reported_total_size);
|
|
|
|
assert_eq!(computed_total_used, reported_total_used);
|
|
|
|
assert_eq!(computed_total_avail, reported_total_avail);
|
|
|
|
// TODO We could also check here that the use percentage matches.
|
|
|
|
}
|
|
|
|
|
2020-04-29 17:03:22 +00:00
|
|
|
// ToDO: more tests...
|