Skip to content

Commit

Permalink
Add the test child command line to the failure regex logs
Browse files Browse the repository at this point in the history
  • Loading branch information
teor2345 committed Mar 18, 2022
1 parent f82ea1d commit 7cc555f
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions zebra-test/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,17 @@ pub struct TestChild<T> {
bypass_test_capture: bool,
}

/// Checks command output against a failure regex set.
/// Checks command output log `line` from `cmd` against a `failure_regexes` regex set,
/// and panics if any regex matches the log line.
///
/// # Panics
///
/// - if any stdout or stderr lines match any failure regex
pub fn check_failure_regexes(line: &std::io::Result<String>, failure_regexes: &RegexSet) {
pub fn check_failure_regexes(
line: &std::io::Result<String>,
failure_regexes: &RegexSet,
cmd: &str,
) {
if let Ok(line) = line {
let failure_matches = failure_regexes.matches(line);
let failure_matches: Vec<&str> = failure_matches
Expand All @@ -229,10 +234,14 @@ pub fn check_failure_regexes(line: &std::io::Result<String>, failure_regexes: &R

assert!(
failure_matches.is_empty(),
"test command output a failure message:\n\n\
"test command:\n\
{cmd}\n\n\
Logged a failure message:\n\
{line}\n\n\
Matching: {failure_matches:#?}\n\
Match Regexes: {:#?}\n",
Matching failure regex: \
{failure_matches:#?}\n\n\
All Failure regexes: \
{:#?}\n",
failure_regexes.patterns(),
);
}
Expand Down Expand Up @@ -329,10 +338,11 @@ impl<T> TestChild<T> {
R: Read + Debug + 'static,
{
let failure_regexes = self.failure_regexes.clone();
let cmd = self.cmd.clone();

let reader = BufReader::new(reader);
let lines = BufRead::lines(reader)
.inspect(move |line| check_failure_regexes(line, &failure_regexes));
.inspect(move |line| check_failure_regexes(line, &failure_regexes, &cmd));

Box::new(lines) as _
}
Expand Down

0 comments on commit 7cc555f

Please sign in to comment.