Files
core/test/rust/runtime/task/panic.rs
T
2026-11-03 03:32:07 +00:00

40 lines
892 B
Rust

use super::{Error, runtime};
use dever_runtime::task::Scope;
use std::{
future::Future,
pin::Pin,
task::{Context, Poll},
};
fn failed_factory(_: &Scope<'_>) -> std::future::Ready<()> {
panic!("future construction failed");
}
struct FailedDrop;
impl Future for FailedDrop {
type Output = ();
fn poll(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<()> {
Poll::Ready(())
}
}
impl Drop for FailedDrop {
fn drop(&mut self) {
panic!("completed future destruction failed");
}
}
fn failed_drop(_: &Scope<'_>) -> FailedDrop {
FailedDrop
}
#[test]
fn entry_catches_future_construction_and_completed_destruction_panics() {
let runtime = runtime();
assert_eq!(runtime.run(failed_factory), Err(Error::Panicked));
assert_eq!(runtime.run(failed_drop), Err(Error::Panicked));
assert_eq!(runtime.run(async |_| 42), Ok(42));
}