simplify async-fn tests
This commit is contained in:
parent
d5294a5bf3
commit
fc06cb71bf
1 changed files with 25 additions and 28 deletions
|
|
@ -40,38 +40,35 @@ async fn includes_never(crash: bool, x: u32) -> u32 {
|
|||
result
|
||||
}
|
||||
|
||||
fn raw_waker_clone(_this: *const ()) -> RawWaker {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
fn raw_waker_wake(_this: *const ()) {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
fn raw_waker_wake_by_ref(_this: *const ()) {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
fn raw_waker_drop(_this: *const ()) {}
|
||||
fn run_fut(mut fut: impl Future<Output=u32>, output: u32) {
|
||||
fn raw_waker_clone(_this: *const ()) -> RawWaker {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
fn raw_waker_wake(_this: *const ()) {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
fn raw_waker_wake_by_ref(_this: *const ()) {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
fn raw_waker_drop(_this: *const ()) {}
|
||||
|
||||
static RAW_WAKER: RawWakerVTable = RawWakerVTable::new(
|
||||
raw_waker_clone,
|
||||
raw_waker_wake,
|
||||
raw_waker_wake_by_ref,
|
||||
raw_waker_drop,
|
||||
);
|
||||
static RAW_WAKER: RawWakerVTable = RawWakerVTable::new(
|
||||
raw_waker_clone,
|
||||
raw_waker_wake,
|
||||
raw_waker_wake_by_ref,
|
||||
raw_waker_drop,
|
||||
);
|
||||
|
||||
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
|
||||
let mut context = Context::from_waker(&waker);
|
||||
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(output));
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = 5;
|
||||
let mut fut = foo(&x, 7);
|
||||
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
|
||||
let mut context = Context::from_waker(&waker);
|
||||
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(31));
|
||||
run_fut(foo(&x, 7), 31);
|
||||
|
||||
let mut fut = build_aggregate(1, 2, 3, 4);
|
||||
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
|
||||
let mut context = Context::from_waker(&waker);
|
||||
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(10));
|
||||
run_fut(build_aggregate(1, 2, 3, 4), 10);
|
||||
|
||||
let mut fut = includes_never(false, 4);
|
||||
let waker = unsafe { Waker::from_raw(RawWaker::new(ptr::null(), &RAW_WAKER)) };
|
||||
let mut context = Context::from_waker(&waker);
|
||||
assert_eq!(unsafe { Pin::new_unchecked(&mut fut) }.poll(&mut context), Poll::Ready(16));
|
||||
run_fut(includes_never(false, 4), 16);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue