From 01025afc40a5528ef77f9a8b568e8a7286b3c66f Mon Sep 17 00:00:00 2001 From: Florian Reisecker Date: Mon, 4 Nov 2024 16:51:22 +0100 Subject: [PATCH] Fix output format for 'not_found' units --- src/lib.rs | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 0e1ec34..014838c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -262,7 +262,10 @@ impl SystemCtl { .filter(|line| line.contains('.') && !line.ends_with('.')); for l in lines { - let parsed: Vec<&str> = l.split_ascii_whitespace().collect(); + // fixes format for not found units + let slice = if l.starts_with("● ") { &l[3..] } else { l }; + + let parsed: Vec<&str> = slice.split_ascii_whitespace().collect(); let description = parsed .split_at(4) @@ -836,6 +839,28 @@ mod test { } } + /// Test valid results for the --all argument + /// Example of broken output: + /// ```text + /// UnitService { + /// unit_name: "●", + /// loaded: "syslog.service", + /// state: "not-found", + /// sub_state: "inactive", + /// description: " dead syslog.service", + /// } + ///``` + #[test] + fn test_list_units_full_all() { + let ctl = SystemCtl::builder() + .additional_args(vec![String::from("--all")]) + .build(); + let units = ctl.list_units_full(None, None, None).unwrap(); // all units + for unit in units { + assert_ne!("●", unit.unit_name); + } + } + #[cfg(feature = "serde")] #[test] fn test_serde_for_unit() {