Skip to content

Commit

Permalink
Merge pull request #303 from cakebaker/clippy_fix_warnings_rust_1_84
Browse files Browse the repository at this point in the history
tests: compile regexes outside of loop
  • Loading branch information
sylvestre authored Jan 10, 2025
2 parents 7c176ed + f292587 commit 69d4a7e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 26 deletions.
47 changes: 22 additions & 25 deletions tests/by-util/test_pgrep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ fn test_help() {
#[test]
#[cfg(target_os = "linux")]
fn test_oldest() {
let re = &Regex::new(SINGLE_PID).unwrap();

for arg in ["-o", "--oldest"] {
new_ucmd!()
.arg(arg)
.succeeds()
.stdout_matches(&Regex::new(SINGLE_PID).unwrap());
new_ucmd!().arg(arg).succeeds().stdout_matches(re);
}
}

Expand All @@ -77,11 +76,10 @@ fn test_oldest_non_matching_pattern() {
#[test]
#[cfg(target_os = "linux")]
fn test_newest() {
let re = &Regex::new(SINGLE_PID).unwrap();

for arg in ["-n", "--newest"] {
new_ucmd!()
.arg(arg)
.succeeds()
.stdout_matches(&Regex::new(SINGLE_PID).unwrap());
new_ucmd!().arg(arg).succeeds().stdout_matches(re);
}
}

Expand All @@ -99,12 +97,10 @@ fn test_newest_non_matching_pattern() {
#[test]
#[cfg(target_os = "linux")]
fn test_older() {
let re = &Regex::new(MULTIPLE_PIDS).unwrap();

for arg in ["-O", "--older"] {
new_ucmd!()
.arg(arg)
.arg("0")
.succeeds()
.stdout_matches(&Regex::new(MULTIPLE_PIDS).unwrap());
new_ucmd!().arg(arg).arg("0").succeeds().stdout_matches(re);
}
}

Expand Down Expand Up @@ -199,13 +195,16 @@ fn test_ignore_case() {
#[test]
#[cfg(target_os = "linux")]
fn test_list_full() {
// (?m) enables multi-line mode
let re = &Regex::new("(?m)^[1-9][0-9]* .+$").unwrap();

for arg in ["-a", "--list-full"] {
new_ucmd!()
.arg("sh")
.arg(arg)
.succeeds()
// (?m) enables multi-line mode
.stdout_matches(&Regex::new("(?m)^[1-9][0-9]* .+$").unwrap());
.stdout_matches(re);
}
}

Expand Down Expand Up @@ -246,13 +245,15 @@ fn test_count_with_non_matching_pattern() {
#[test]
#[cfg(target_os = "linux")]
fn test_terminal() {
let re = &Regex::new(MULTIPLE_PIDS).unwrap();

for arg in ["-t", "--terminal"] {
new_ucmd!()
.arg(arg)
.arg("tty1")
.arg("--inverse") // XXX hack to make test pass in CI
.succeeds()
.stdout_matches(&Regex::new(MULTIPLE_PIDS).unwrap());
.stdout_matches(re);
}
}

Expand Down Expand Up @@ -286,12 +287,10 @@ fn test_terminal_invalid_terminal() {
#[test]
#[cfg(target_os = "linux")]
fn test_runstates() {
let re = &Regex::new(MULTIPLE_PIDS).unwrap();

for arg in ["-r", "--runstates"] {
new_ucmd!()
.arg(arg)
.arg("S")
.succeeds()
.stdout_matches(&Regex::new(MULTIPLE_PIDS).unwrap());
new_ucmd!().arg(arg).arg("S").succeeds().stdout_matches(re);
}
}

Expand All @@ -308,12 +307,10 @@ fn test_runstates_invalid_runstate() {
#[test]
#[cfg(target_os = "linux")]
fn test_parent() {
let re = &Regex::new(MULTIPLE_PIDS).unwrap();

for arg in ["-P", "--parent"] {
new_ucmd!()
.arg(arg)
.arg("0")
.succeeds()
.stdout_matches(&Regex::new(MULTIPLE_PIDS).unwrap());
new_ucmd!().arg(arg).arg("0").succeeds().stdout_matches(re);
}
}

Expand Down
4 changes: 3 additions & 1 deletion tests/by-util/test_pidof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,12 @@ fn test_omit_pid() {
fn test_separator() {
use regex::Regex;

let re = &Regex::new("^[1-9][0-9]*separator[1-9][0-9]*\n$").unwrap();

for arg in ["-S", "-d", "--separator"] {
new_ucmd!()
.args(&[arg, "separator", "kthreadd", "kthreadd"])
.succeeds()
.stdout_matches(&Regex::new("^[1-9][0-9]*separator[1-9][0-9]*\n$").unwrap());
.stdout_matches(re);
}
}

0 comments on commit 69d4a7e

Please sign in to comment.