Skip to content

Commit

Permalink
test: cover empty events from processing newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanbabcock committed Nov 24, 2024
1 parent 26d3236 commit 2694187
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/read_until_any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ pub fn read_until_any<R: BufRead + ?Sized>(
.position(|&b| delims.iter().any(|&d| d == b))
.map(|i| i + start_delims);

// println!("start_delims: {start_delims}, first_delim_index: {first_delim_index:?}");

match first_delim_index {
Some(i) => {
buf.extend_from_slice(&available[..=i]);
Expand All @@ -51,7 +49,17 @@ pub fn read_until_any<R: BufRead + ?Sized>(
};
r.consume(used);
read += used;
if done || used == 0 {

if done {
return Ok(read);
}

// Catch final trailing delimiters
if used == 0 && buf.iter().all(|&b| delims.iter().any(|&d| d == b)) {
return Ok(0);
}

if used == 0 {
return Ok(read);
}
}
Expand Down
19 changes: 19 additions & 0 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,3 +676,22 @@ fn test_stdout_interleaved_frames_fallback() -> anyhow::Result<()> {

Ok(())
}

/// Make sure consectuive new lines in logs don't result in empty events.
#[test]
fn test_no_empty_events() -> anyhow::Result<()> {
let empty_events = FfmpegCommand::new()
.testsrc()
.rawvideo()
.spawn()?
.iter()?
.filter(|event| match event {
FfmpegEvent::Log(_, msg) if msg.is_empty() => true,
_ => false,
})
.count();

assert!(empty_events == 0);

Ok(())
}

0 comments on commit 2694187

Please sign in to comment.