Crate wookie[][src]

Expand description

Async test/bench toolkit including single stepping executors. No-std compatible.

The primary user interface is the wookie! macro, which wraps a future with an executor and pins it on the stack.:

use core::task::Poll;
use wookie::wookie;
wookie!(future: async { true });
assert_eq!(future.poll(), Poll::Ready(true));

// you can also just give a variable name if you have one:
let future = async { true };
wookie!(future);
assert_eq!(future.poll(), Poll::Ready(true));

// we can find out about the state of wakers any time:
assert_eq!(future.cloned(), 0);
assert_eq!(future.dropped(), 0);
assert_eq!(future.woken(), 0);
// or equivalently...
future.stats().assert(0, 0, 0);

If you do not have access to an allocator, you can use the local! macro instead, however, polling is unsafe and you must be very careful to maintain the invariants described in the safety sections of the Local methods.

use core::task::Poll;
use wookie::local;
local!(future: async { true });
assert_eq!(unsafe { future.poll() }, Poll::Ready(true));

// you can also just give a variable name if you have one:
let future = async { true };
local!(future);
assert_eq!(unsafe { future.poll() }, Poll::Ready(true));

// we can find out about the state of wakers any time:
assert_eq!(future.cloned(), 0);
assert_eq!(future.dropped(), 0);
assert_eq!(future.woken(), 0);
// or equivalently...
future.stats().assert(0, 0, 0);

For benchmarking, we provide the dummy! macro, whose waker does nothing, but quite quickly.

use core::task::Poll;
use wookie::dummy;
dummy!(future: async { true });
assert_eq!(future.poll(), Poll::Ready(true));

We have assert_pending! and assert_ready! to save some typing in assertions:

use wookie::*;
use core::task::Poll;
assert_pending!(Poll::<i32>::Pending); // pass
// assert_pending!(Poll::Ready(())); // would fail

// With 1 arg, assert_ready will returning the unwrapped value.
assert_eq!(42, assert_ready!(Poll::Ready(42)));
// assert_ready!(Poll::<i32>::Pending); // would fail

// With 2 args, it's like [`assert_eq`] on the unwrapped value.
assert_ready!(42, Poll::Ready(42));
// assert_ready!(Poll::<i32>::Pending); // would fail
// assert_ready!(42, Poll::Ready(420)); // would fail

Features

Default features: alloc.

  • alloc - enables use of an allocator. Required by Wookie / wookie!.

Macros

Asserts that a [Poll] is a [Poll::Pending]

Asserts that a [Poll] is a [Poll::Ready]

Wraps a future in a single-stepping executor whose waker does nothing and pins it to the stack.

Like dummy! but wraps in a ManuallyDrop.

Wraps a future in a single-stepping executor that tracks wakers and pins it on the stack.

Wraps a future in a single-future stepping executor for test suites that tracks wakers and pins it on the stack.

Structs

A single-stepping executor whose waker does absolutely nothing, but quite quickly.

An allocator-less single-future stepping executor for test suites that tracks wakers.

Statistics of waker activity for Wookie or Local.

A single-future stepping executor for test suites that tracks wakers.