diff --git a/src/uu/ps/src/picker.rs b/src/uu/ps/src/picker.rs index be0a1c41..58f67940 100644 --- a/src/uu/ps/src/picker.rs +++ b/src/uu/ps/src/picker.rs @@ -50,7 +50,8 @@ pub(crate) fn collect_pickers( "time" | "cputime" => pickers.push(helper(time)), "ucmd" | "comm" => pickers.push(helper(ucmd)), "cmd" | "command" | "args" => pickers.push(helper(cmd)), - _ => {} + // Not implemented yet: keep the column so later values stay under their headers + _ => pickers.push(helper(|_| "-".to_string())), } } diff --git a/tests/by-util/test_ps.rs b/tests/by-util/test_ps.rs index d6bb2531..60e2ef55 100644 --- a/tests/by-util/test_ps.rs +++ b/tests/by-util/test_ps.rs @@ -417,3 +417,23 @@ fn test_combined_selection_criteria() { assert!(pids.contains(&1)); assert!(pids.len() > 1); } + +#[test] +#[cfg(target_os = "linux")] +fn test_unimplemented_field_keeps_columns_aligned() { + // wchan has no value yet; pid must still be printed in its own column + let out = new_ucmd!() + .args(&["-p", "1", "--no-headers", "-o", "wchan,pid"]) + .succeeds() + .stdout_move_str(); + assert_eq!(out.split_whitespace().collect::>(), ["-", "1"]); + + let out = new_ucmd!() + .args(&["-p", "1", "-l"]) + .succeeds() + .stdout_move_str(); + let mut lines = out.lines(); + let headers = lines.next().unwrap().split_whitespace().count(); + let values = lines.next().unwrap().split_whitespace().count(); + assert_eq!(headers, values); +}