coverage: Add a test for async
blocks
We have coverage tests that use async functions, but none that use async blocks.
This commit is contained in:
parent
5810deef69
commit
4ae792036e
3 changed files with 104 additions and 0 deletions
35
tests/coverage/async_block.rs
Normal file
35
tests/coverage/async_block.rs
Normal file
|
@ -0,0 +1,35 @@
|
|||
#![feature(coverage_attribute)]
|
||||
#![feature(noop_waker)]
|
||||
// edition: 2021
|
||||
|
||||
fn main() {
|
||||
for i in 0..16 {
|
||||
let future = async {
|
||||
if i >= 12 {
|
||||
println!("big");
|
||||
} else {
|
||||
println!("small");
|
||||
}
|
||||
};
|
||||
executor::block_on(future);
|
||||
}
|
||||
}
|
||||
|
||||
mod executor {
|
||||
use core::future::Future;
|
||||
use core::pin::pin;
|
||||
use core::task::{Context, Poll, Waker};
|
||||
|
||||
#[coverage(off)]
|
||||
pub fn block_on<F: Future>(mut future: F) -> F::Output {
|
||||
let mut future = pin!(future);
|
||||
let waker = Waker::noop();
|
||||
let mut context = Context::from_waker(&waker);
|
||||
|
||||
loop {
|
||||
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
|
||||
break val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue