Skip to content

Commit

Permalink
lscpu: Improve tests a tiny bit
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndrv committed Feb 13, 2025
1 parent 21706eb commit 2e924fd
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions tests/by-util/test_lscpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,30 @@ fn test_hex() {

#[test]
fn test_json() {
new_ucmd!()
.arg("--json")
.succeeds()
// ensure some fields are there, non-exhausting
.stdout_contains("\"lscpu\": [")
let res = new_ucmd!().arg("--json").succeeds();

let stdout = res.no_stderr().stdout_str();
assert!(stdout.starts_with("{"));
assert!(stdout.ends_with("}\n"));

res.stdout_contains("\"lscpu\": [")
.stdout_contains("\"field\": \"Architecture\"")
.stdout_contains("\"field\": \"CPU(s)\"");
.stdout_contains("\"field\": \"CPU(s)\"")
.stdout_contains("\"children\": [");
}

#[test]
fn test_output() {
let res = new_ucmd!().succeeds();
let stdout = res.no_stderr().stdout_str();

// Non-exhaustive list of fields we expect
// This also checks that fields which should be indented, are indeed indented as excepted
assert!(stdout.contains("Architecture:"));
assert!(stdout.contains("\n Address sizes:"));
assert!(stdout.contains("\n Byte Order:"));
assert!(stdout.contains("\nCPU(s):"));
assert!(stdout.contains("\nVendor ID:"));
assert!(stdout.contains("\n Model name:"));
assert!(stdout.contains("\n CPU Family:"));
}

0 comments on commit 2e924fd

Please sign in to comment.