Add test case for #32085

This commit is contained in:
Steven Allen 2016-03-07 18:00:22 -05:00
parent 6ea8222913
commit c516335815

View File

@ -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());