Skip to content

Commit

Permalink
Add test case for #32085
Browse files Browse the repository at this point in the history
  • Loading branch information
Stebalien committed Mar 7, 2016
1 parent 6ea8222 commit c516335
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/libstd/io/buffered.rs
Expand Up @@ -984,6 +984,34 @@ mod tests {
assert_eq!(v, []);
}

#[test]
fn test_line_buffer_fail_flush() {
// Issue #32085
struct FailFlushWriter<'a>(&'a mut Vec<u8>);

impl<'a> Write for FailFlushWriter<'a> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.0.extend_from_slice(buf);
Ok(buf.len())
}
fn flush(&mut self) -> io::Result<()> {
Err(io::Error::new(io::ErrorKind::Other, "flush failed"))
}
}

let mut buf = Vec::new();
{
let mut writer = LineWriter::new(FailFlushWriter(&mut buf));
let to_write = b"abc\ndef";
if let Ok(written) = writer.write(to_write) {
assert!(written < to_write.len(), "didn't flush on new line");
// PASS
return;
}
}
assert!(buf.is_empty(), "write returned an error but wrote data");
}

#[test]
fn test_line_buffer() {
let mut writer = LineWriter::new(Vec::new());
Expand Down

0 comments on commit c516335

Please sign in to comment.