File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -984,6 +984,34 @@ mod tests {
984984 assert_eq ! ( v, [ ] ) ;
985985 }
986986
987+ #[ test]
988+ fn test_line_buffer_fail_flush ( ) {
989+ // Issue #32085
990+ struct FailFlushWriter < ' a > ( & ' a mut Vec < u8 > ) ;
991+
992+ impl < ' a > Write for FailFlushWriter < ' a > {
993+ fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
994+ self . 0 . extend_from_slice ( buf) ;
995+ Ok ( buf. len ( ) )
996+ }
997+ fn flush ( & mut self ) -> io:: Result < ( ) > {
998+ Err ( io:: Error :: new ( io:: ErrorKind :: Other , "flush failed" ) )
999+ }
1000+ }
1001+
1002+ let mut buf = Vec :: new ( ) ;
1003+ {
1004+ let mut writer = LineWriter :: new ( FailFlushWriter ( & mut buf) ) ;
1005+ let to_write = b"abc\n def" ;
1006+ if let Ok ( written) = writer. write ( to_write) {
1007+ assert ! ( written < to_write. len( ) , "didn't flush on new line" ) ;
1008+ // PASS
1009+ return ;
1010+ }
1011+ }
1012+ assert ! ( buf. is_empty( ) , "write returned an error but wrote data" ) ;
1013+ }
1014+
9871015 #[ test]
9881016 fn test_line_buffer ( ) {
9891017 let mut writer = LineWriter :: new ( Vec :: new ( ) ) ;
You can’t perform that action at this time.
0 commit comments