Skip to content

Commit

Permalink
add Count::GreaterThanOrEqual and Count::LessThanOrEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
rukai committed Oct 9, 2024
1 parent b78abde commit 9b78f40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tokio-bin-process/src/event_matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,17 @@ impl EventMatcher {

/// Defines how many times the [`EventMatcher`] must match to pass an assertion.
#[derive(Debug)]
#[non_exhaustive]
pub enum Count {
/// This matcher must match this many times to pass an assertion.
Times(usize),
/// This matcher may match 0 or more times and will still pass an assertion.
/// Use sparingly but useful for ignoring a warning or error that is not appearing deterministically.
Any,
/// This matcher must match this many times or more to pass an asssertion
GreaterThanOrEqual(usize),
/// This matcher must match this many times or fewer to pass an asssertion
LessThanOrEqual(usize),
}

impl From<usize> for Count {
Expand Down
10 changes: 10 additions & 0 deletions tokio-bin-process/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,16 @@ impl BinProcess {
panic!("Expected to find matches for {matcher:?}, {matcher_count} times but actually matched {count} times")
}
}
Count::GreaterThanOrEqual(x) => {
if *count < x {
panic!("Expected to find matches for {matcher:?}, greater than or equal to {x} times but actually matched {count} times")
}
}
Count::LessThanOrEqual(x) => {
if *count > x {
panic!("Expected to find matches for {matcher:?}, less than or equal to {x} times but actually matched {count} times")
}
}
}
}
}
Expand Down

0 comments on commit 9b78f40

Please sign in to comment.