summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs')
-rw-r--r--third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs29
1 files changed, 29 insertions, 0 deletions
diff --git a/third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs b/third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs
new file mode 100644
index 0000000000..a06748d09a
--- /dev/null
+++ b/third_party/rust/futures-0.1.31/tests/stream_catch_unwind.rs
@@ -0,0 +1,29 @@
+extern crate futures;
+
+use futures::stream;
+use futures::prelude::*;
+
+#[test]
+fn panic_in_the_middle_of_the_stream() {
+ let stream = stream::iter_ok::<_, bool>(vec![Some(10), None, Some(11)]);
+
+ // panic on second element
+ let stream_panicking = stream.map(|o| o.unwrap());
+ let mut iter = stream_panicking.catch_unwind().wait();
+
+ assert_eq!(Ok(10), iter.next().unwrap().ok().unwrap());
+ assert!(iter.next().unwrap().is_err());
+ assert!(iter.next().is_none());
+}
+
+#[test]
+fn no_panic() {
+ let stream = stream::iter_ok::<_, bool>(vec![10, 11, 12]);
+
+ let mut iter = stream.catch_unwind().wait();
+
+ assert_eq!(Ok(10), iter.next().unwrap().ok().unwrap());
+ assert_eq!(Ok(11), iter.next().unwrap().ok().unwrap());
+ assert_eq!(Ok(12), iter.next().unwrap().ok().unwrap());
+ assert!(iter.next().is_none());
+}