File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -984,6 +984,34 @@ mod tests {
984
984
assert_eq ! ( v, [ ] ) ;
985
985
}
986
986
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
+
987
1015
#[ test]
988
1016
fn test_line_buffer ( ) {
989
1017
let mut writer = LineWriter :: new ( Vec :: new ( ) ) ;
You can’t perform that action at this time.
0 commit comments