1
0
mirror of https://github.com/bspeice/qadapt synced 2024-11-24 06:48:09 -05:00

Add an async demonstration

This commit is contained in:
Bradlee Speice 2018-12-08 18:05:46 -05:00
parent 26ebd50fc0
commit 9e5b2b0f7a
4 changed files with 60 additions and 24 deletions

View File

@ -24,3 +24,6 @@ spin = { git = "https://github.com/bspeice/spin-rs.git" }
thread-id = "3.3"
qadapt-macro = { version = "0.7.1", path = "./qadapt-macro" }
[dev-dependencies]
futures = "0.1"

33
tests/async.rs Normal file
View File

@ -0,0 +1,33 @@
use futures::future::ok;
use futures::prelude::*;
use qadapt::assert_no_alloc;
use qadapt::no_alloc;
use qadapt::QADAPT;
#[global_allocator]
static Q: QADAPT = QADAPT;
#[no_alloc]
fn async_box() -> impl Future<Item = Box<u8>, Error = ()> {
ok(12).and_then(|e| Ok(Box::new(e)))
}
#[test]
fn raw_call() {
async_box();
}
#[test]
fn guarded_call() {
assert_no_alloc!(async_box());
}
#[test]
#[should_panic]
fn guarded_poll() {
if cfg!(debug_assertions) {
assert_no_alloc!(async_box().poll().unwrap());
} else {
panic!("Intentional")
}
}