Skip to content

Commit

Permalink
Fix output format for 'not_found' units
Browse files Browse the repository at this point in the history
  • Loading branch information
Journeycorner committed Nov 4, 2024
1 parent 3fbfad0 commit 01025af
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 01025af

Please sign in to comment.