1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-27 11:07:44 +00:00

kill: print --table as vertical (#6216)

* kill: print --table as vertical

* kill: remove signal padding on --table

* kill: skip exit signal in --table

* kill: replace "skip" with "filter"

---------

Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
Haisham 2024-04-14 18:08:51 +05:00 committed by GitHub
parent 9b4a787be7
commit 333e4d9fe9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 8 deletions

View file

@ -142,15 +142,14 @@ fn handle_obsolete(args: &mut Vec<String>) -> Option<usize> {
}
fn table() {
let name_width = ALL_SIGNALS.iter().map(|n| n.len()).max().unwrap();
for (idx, signal) in ALL_SIGNALS.iter().enumerate() {
print!("{0: >#2} {1: <#2$}", idx, signal, name_width + 2);
if (idx + 1) % 7 == 0 {
println!();
// GNU kill doesn't list the EXIT signal with --table, so we ignore it, too
for (idx, signal) in ALL_SIGNALS
.iter()
.enumerate()
.filter(|(_, s)| **s != "EXIT")
{
println!("{0: >#2} {1}", idx, signal);
}
}
println!();
}
fn print_signal(signal_name_or_value: &str) -> UResult<()> {

View file

@ -83,6 +83,29 @@ fn test_kill_list_all_signals_as_table() {
.stdout_contains("HUP");
}
#[test]
fn test_kill_table_starts_at_1() {
new_ucmd!()
.arg("-t")
.succeeds()
.stdout_matches(&Regex::new("^\\s?1\\sHUP").unwrap());
}
#[test]
fn test_kill_table_lists_all_vertically() {
// Check for a few signals. Do not try to be comprehensive.
let command = new_ucmd!().arg("-t").succeeds();
let signals = command
.stdout_str()
.split('\n')
.flat_map(|line| line.trim().split(" ").nth(1))
.collect::<Vec<&str>>();
assert!(signals.contains(&"KILL"));
assert!(signals.contains(&"TERM"));
assert!(signals.contains(&"HUP"));
}
#[test]
fn test_kill_list_one_signal_from_name() {
// Use SIGKILL because it is 9 on all unixes.