1use futures::executor::block_on_stream;
2use futures::stream::{self, StreamExt};
3
4#[test]
5fn panic_in_the_middle_of_the_stream() {
6 let stream = stream::iter(vec![Some(10), None, Some(11)]);
7
8 // panic on second element
9 let stream_panicking = stream.map(|o| o.unwrap());
10 let mut iter = block_on_stream(stream_panicking.catch_unwind());
11
12 assert_eq!(10, iter.next().unwrap().ok().unwrap());
13 assert!(iter.next().unwrap().is_err());
14 assert!(iter.next().is_none());
15}
16
17#[test]
18fn no_panic() {
19 let stream = stream::iter(vec![10, 11, 12]);
20
21 let mut iter = block_on_stream(stream.catch_unwind());
22
23 assert_eq!(10, iter.next().unwrap().ok().unwrap());
24 assert_eq!(11, iter.next().unwrap().ok().unwrap());
25 assert_eq!(12, iter.next().unwrap().ok().unwrap());
26 assert!(iter.next().is_none());
27}
28