Skip to content

Commit

Permalink
Merge branch 'main' into feature/top-summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Krysztal112233 authored Jan 18, 2025
2 parents 2edff2e + eaf0ae2 commit a7c23e8
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions tests/by-util/test_pgrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.

#[cfg(target_os = "linux")]
use std::{
array,
process::{Child, Command},
};

use crate::common::util::TestScenario;
#[cfg(target_os = "linux")]
use regex::Regex;
Expand Down Expand Up @@ -151,37 +157,46 @@ fn test_valid_regex() {
new_ucmd!().arg("a*").succeeds();
}

#[cfg(target_os = "linux")]
fn spawn_2_dummy_sleep_processes() -> [Child; 2] {
array::from_fn(|_| Command::new("sleep").arg("2").spawn().unwrap())
}

#[cfg(target_os = "linux")]
#[test]
fn test_delimiter() {
let mut sleep_processes = spawn_2_dummy_sleep_processes();
for arg in ["-d", "--delimiter"] {
new_ucmd!()
.arg("sh")
.arg("sleep")
.arg(arg)
.arg("|")
.succeeds()
.stdout_contains("|");
}
sleep_processes.iter_mut().for_each(|p| drop(p.kill()));
}

#[cfg(target_os = "linux")]
#[test]
fn test_delimiter_last_wins() {
let mut sleep_processes = spawn_2_dummy_sleep_processes();
new_ucmd!()
.arg("sh")
.arg("sleep")
.arg("-d_")
.arg("-d:")
.succeeds()
.stdout_does_not_contain("_")
.stdout_contains(":");

new_ucmd!()
.arg("sh")
.arg("sleep")
.arg("-d:")
.arg("-d_")
.succeeds()
.stdout_does_not_contain(":")
.stdout_contains("_");
sleep_processes.iter_mut().for_each(|p| drop(p.kill()));
}

#[test]
Expand Down

0 comments on commit a7c23e8

Please sign in to comment.