Skip to content

Commit

Permalink
add unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
cre4ture committed Mar 14, 2024
1 parent 7de5a92 commit 832532b
Showing 1 changed file with 116 additions and 0 deletions.
116 changes: 116 additions & 0 deletions src/uu/df/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type MaybeInodesT = Option<InodesIntT>;
///
/// A row comprises several pieces of information, including the
/// filesystem device, the mountpoint, the number of bytes used, etc.
#[derive(Clone)]
pub(crate) struct Row {
/// The filename given on the command-line, if given.
file: Option<String>,
Expand Down Expand Up @@ -873,4 +874,119 @@ mod tests {

assert_eq!(row.inodes_used, Some(0));
}

Check failure on line 877 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:877; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 877 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:877; use `cargo fmt -- "src/uu/df/src/table.rs"`)
#[test]
fn test_row_accumulation_u64_overflow() {

let total = u64::MAX as super::InodesIntT;
let used1 = 3000 as super::InodesIntT;
let used2 = 50000 as super::InodesIntT;

Check failure on line 884 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:884; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 884 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:884; use `cargo fmt -- "src/uu/df/src/table.rs"`)
let mut row1 = Row{
inodes: Some(total),
inodes_used: Some(used1),
inodes_free: Some(total - used1),
..Default::default()

Check failure on line 889 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:889; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 889 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:889; use `cargo fmt -- "src/uu/df/src/table.rs"`)
};

let row2 = Row{
inodes: Some(total),
inodes_used: Some(used2 ),
inodes_free: Some(total - used2),
..Default::default()
};

row1 += row2;

assert_eq!(row1.inodes, Some(total * 2));
assert_eq!(row1.inodes_used, Some(used1 + used2));
assert_eq!(row1.inodes_free, Some(total * 2 - used1 - used2));
}

Check failure on line 905 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:905; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 905 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:905; use `cargo fmt -- "src/uu/df/src/table.rs"`)
#[test]
fn test_row_accumulation_close_to_u128_overflow() {

let total = u128::MAX as super::InodesIntT / 2 - 1;
let used1 = total - 50000;
let used2 = total - 100000;

Check failure on line 912 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:912; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 912 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:912; use `cargo fmt -- "src/uu/df/src/table.rs"`)
let mut row1 = Row{
inodes: Some(total),
inodes_used: Some(used1),
inodes_free: Some(total - used1),
..Default::default()

Check failure on line 917 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:917; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 917 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:917; use `cargo fmt -- "src/uu/df/src/table.rs"`)
};

let row2 = Row{
inodes: Some(total),
inodes_used: Some(used2 ),
inodes_free: Some(total - used2),
..Default::default()
};

row1 += row2;

assert_eq!(row1.inodes, Some(total * 2));
assert_eq!(row1.inodes_used, Some(used1 + used2));
assert_eq!(row1.inodes_free, Some(total * 2 - used1 - used2));
}

Check failure on line 933 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:933; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 933 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:933; use `cargo fmt -- "src/uu/df/src/table.rs"`)
#[test]
fn test_row_accumulation_and_usage_close_over_u128_overflow() {

let total = u128::MAX as super::InodesIntT / 2 - 1;
let used1 = total / 2;
let free1 = total - used1;
let used2 = total / 2 - 10;

Check failure on line 940 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:940; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 940 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:940; use `cargo fmt -- "src/uu/df/src/table.rs"`)
let free2 = total - used2;

let mut row1 = Row{
inodes: Some(total),
inodes_used: Some(used1),
inodes_free: Some(free1),
..Default::default()

Check failure on line 947 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style/format (ubuntu-latest, feat_os_unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:947; use `cargo fmt -- "src/uu/df/src/table.rs"`)

Check failure on line 947 in src/uu/df/src/table.rs

View workflow job for this annotation

GitHub Actions / Style and Lint (ubuntu-22.04, unix)

ERROR: `cargo fmt`: style violation (file:'src/uu/df/src/table.rs', line:947; use `cargo fmt -- "src/uu/df/src/table.rs"`)
};

let row2 = Row{
inodes: Some(total),
inodes_used: Some(used2),
inodes_free: Some(free2),
..Default::default()
};

row1 += row2.clone();

assert_eq!(row1.inodes, Some(total * 2));
assert_eq!(row1.inodes_used, Some(used1 + used2));
assert_eq!(row1.inodes_free, Some(free1 + free2));
assert_eq!(row1.inodes_usage, Some(0.5));

row1 += row2.clone();

assert_eq!(row1.inodes, None); // total * 3
assert_eq!(row1.inodes_used, Some(used1 + used2 * 2));
assert_eq!(row1.inodes_free, Some(free1 + free2 * 2));
assert_eq!(row1.inodes_usage, None);

row1 += row2.clone();

assert_eq!(row1.inodes, None); // total * 4
assert_eq!(row1.inodes_used, Some(used1 + used2 * 3)); // used * 4
assert_eq!(row1.inodes_free, None); // free * 4
assert_eq!(row1.inodes_usage, None);

row1 += row2.clone();

assert_eq!(row1.inodes, None); // total * 5
assert_eq!(row1.inodes_used, None); // used * 5
assert_eq!(row1.inodes_free, None); // free * 5
assert_eq!(row1.inodes_usage, None);

row1 += row2.clone();

assert_eq!(row1.inodes, None); // total * 6
assert_eq!(row1.inodes_used, None); // used * 6
assert_eq!(row1.inodes_free, None); // free * 6
assert_eq!(row1.inodes_usage, None);
}
}

0 comments on commit 832532b

Please sign in to comment.