From fc06cb71bfa606ed602969868abd9623c27464e9 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 9 Aug 2019 10:26:48 +0200 Subject: [PATCH] simplify async-fn tests --- tests/run-pass/async-fn.rs | 53 ++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/tests/run-pass/async-fn.rs b/tests/run-pass/async-fn.rs index 25b9b9ac5ba4..3f3729d70834 100644 --- a/tests/run-pass/async-fn.rs +++ b/tests/run-pass/async-fn.rs @@ -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) { + 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); }