lsmem: Fix JSON output writing size as Number in bytes-mode

This commit is contained in:
Foorack
2025-02-09 15:11:13 +01:00
parent eb93139c3d
commit f34ebac3fe
2 changed files with 9 additions and 6 deletions

View File

@@ -578,7 +578,11 @@ fn print_json(lsmem: &Lsmem, opts: &Options) {
for column in &opts.columns { for column in &opts.columns {
record.insert( record.insert(
column.get_name().to_lowercase(), column.get_name().to_lowercase(),
serde_json::Value::String(row.get_value(column)), if column == &Column::Size && opts.bytes {
serde_json::Value::Number(row.get_value(column).parse().unwrap())
} else {
serde_json::Value::String(row.get_value(column))
},
); );
} }
memory_records.push(serde_json::Value::Object(record)); memory_records.push(serde_json::Value::Object(record));

View File

@@ -65,11 +65,10 @@ fn test_json_all() {
sysroot_test_with_args("test_lsmem_json_all.expected", &["-J", "-a"]); sysroot_test_with_args("test_lsmem_json_all.expected", &["-J", "-a"]);
} }
// FAILS, COMMENT FOR NOW - TODO #[test]
// #[test] fn test_json_bytes() {
// fn test_json_bytes() { sysroot_test_with_args("test_lsmem_json_bytes.expected", &["-J", "-b"]);
// sysroot_test_with_args("test_lsmem_json_bytes.expected", &["-J", "-b"]); }
// }
#[test] #[test]
fn test_json_noheadings() { fn test_json_noheadings() {