8 releases
0.1.7 | Dec 31, 2020 |
---|---|
0.1.6 | Dec 24, 2020 |
#15 in #safe
49 downloads per month
Used in 3 crates
13KB
safina-async-test
A macro for running async fn
tests.
It is part of safina
, a safe async runtime.
Runs tests with safina_executor::block_on
.
Features
forbid(unsafe_code)
- Straightforward implementation
Limitations
- Requires Rust
nightly
because safina-executor does
Examples
use safina_async_test::async_test;
#[async_test]
async fn test1() {
an_async_fn().await.unwrap();
}
use safina_async_test::async_test;
#[async_test]
async fn test2() {
// Make your test an `async fn` and await in it.
assert_eq!(42, do_request().await.unwrap());
// The macro creates an Executor and runs the test through it.
// You can spawn async tasks on it:
safina_executor::spawn(background_task());
// You can schedule blocking jobs to run on the Executor:
let result = safina_executor::schedule_blocking(|| blocking_work());
assert_eq!(3, result.await.unwrap());
// The macro also starts the timer thread, so this works:
safina_timer::sleep_for(Duration::from_millis(10)).await;
}
Documentation
https://docs.rs/safina-async-test
Alternatives
Changelog
- v0.1.8 - Start an Executor for each test
- v0.1.7 - Update to safina-executor v0.1.4
- v0.1.6 - Start
safina-timer
thread - v0.1.5 - Use
safina-executor
v0.1.3 API - v0.1.4 - Upgrade to new
safina-executor
version which removes need forBox::pin
. - v0.1.3 - Rename
safina
package tosafina-executor
. - v0.1.2 - Update docs
- v0.1.1 - First published version
TO DO
- DONE - Implement as declarative macro. UX is bad.
- DONE - Implement as procedural macro.
- DONE - Report errors nicely
- DONE - Publish on crates.io
- Let users depend only on safina-async-test:
- Move proc macro to its own crate.
- Make
safina_async_test
re-export the macro andsafina_executor::block_on
. - Change the macro to call
safina_async_test::block_on
.
- Automatically start a worker thread and timer thread.
Release Process
- Edit
Cargo.toml
and bump version number. - Run
./release.sh
License: Apache-2.0
Dependencies
~120KB