Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/uu/kill/src/kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
table();
Ok(())
}
Mode::List => list(pids_or_signals.first()),
Mode::List => {
list(&pids_or_signals);
Ok(())
}
}
}

Expand Down Expand Up @@ -164,12 +167,14 @@ fn print_signals() {
}
}

fn list(arg: Option<&String>) -> UResult<()> {
match arg {
Some(x) => print_signal(x),
None => {
print_signals();
Ok(())
fn list(signals: &Vec<String>) {
if signals.is_empty() {
print_signals();
} else {
for signal in signals {
if let Err(e) = print_signal(signal) {
uucore::show!(e)
}
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions tests/by-util/test_kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,38 @@ fn test_kill_list_one_signal_from_name() {
.stdout_matches(&Regex::new("\\b9\\b").unwrap());
}

#[test]
fn test_kill_list_all_vertically() {
// Check for a few signals. Do not try to be comprehensive.
let command = new_ucmd!().arg("-l").succeeds();
let signals = command.stdout_str().split('\n').collect::<Vec<&str>>();
assert!(signals.contains(&"KILL"));
assert!(signals.contains(&"TERM"));
assert!(signals.contains(&"HUP"));
}

#[test]
fn test_kill_list_two_signal_from_name() {
new_ucmd!()
.arg("-l")
.arg("INT")
.arg("KILL")
.succeeds()
.stdout_matches(&Regex::new("\\d\n\\d").unwrap());
}

#[test]
fn test_kill_list_three_signal_first_unknown() {
new_ucmd!()
.arg("-l")
.arg("IAMNOTASIGNAL") // spell-checker:disable-line
.arg("INT")
.arg("KILL")
.fails()
.stderr_contains("unknown signal")
.stdout_matches(&Regex::new("\\d\n\\d").unwrap());
}

#[test]
fn test_kill_set_bad_signal_name() {
// spell-checker:disable-line
Expand Down