pidof: Add test for no name and no pid found case.

This commit is contained in:
Krysztal Huang
2024-07-10 16:00:26 +08:00
parent de3ffd0595
commit a69de2dcd2
2 changed files with 18 additions and 0 deletions
+6
View File
@@ -25,6 +25,12 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
};
let mut collected = collect_matched_pids(&matches);
if collected.is_empty() {
uucore::error::set_exit_code(1);
return Ok(());
};
collected.sort_by(|a, b| b.pid.cmp(&a.pid));
let output = collected
+12
View File
@@ -21,3 +21,15 @@ fn test_find_init() {
fn test_find_kthreadd() {
new_ucmd!().arg("kthreadd").succeeds();
}
#[test]
#[cfg(target_os = "linux")]
fn test_no_program() {
new_ucmd!().fails().code_is(1);
}
#[test]
#[cfg(target_os = "linux")]
fn test_no_pid_found() {
new_ucmd!().arg("NO_THIS_PROGRAM").fails().code_is(1);
}