Skip to content

Commit

Permalink
pkill: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MCredbear committed Jan 1, 2025
1 parent 1a21770 commit dd39789
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
50 changes: 50 additions & 0 deletions tests/by-util/test_pkill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// This file is part of the uutils procps package.
//
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

use crate::common::util::TestScenario;

#[cfg(target_os = "linux")]
#[test]
fn test_no_args() {
new_ucmd!()
.fails()
.code_is(2)
.no_stdout()
.stderr_contains("no matching criteria specified");
}

#[cfg(target_os = "linux")]
#[test]
fn test_non_matching_pattern() {
new_ucmd!()
.arg("THIS_PATTERN_DOES_NOT_MATCH")
.fails()
.code_is(1)
.no_output();
}

#[cfg(target_os = "linux")]
#[test]
fn test_too_many_patterns() {
new_ucmd!()
.arg("sh")
.arg("sh")
.fails()
.code_is(2)
.no_stdout()
.stderr_contains("only one pattern can be provided");
}

#[cfg(target_os = "linux")]
#[test]
fn test_invalid_arg() {
new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
}

#[cfg(target_os = "linux")]
#[test]
fn test_help() {
new_ucmd!().arg("--help").succeeds();
}
4 changes: 4 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ mod test_top;
#[cfg(feature = "snice")]
#[path = "by-util/test_snice.rs"]
mod test_snice;

#[cfg(feature = "pkill")]
#[path = "by-util/test_pkill.rs"]
mod test_pkill;

0 comments on commit dd39789

Please sign in to comment.