Originally used internally as the testing framework for my microkernel project. Before this, I tried follow another os dev blog to incorporate #![feature(custom_test_framework)]
to customize my [no_std]
test. Unfortunately, that RFC was closed, see discussion.
This little crate uses linkme to allow user to distributedly submit unit test within the crate.
- Define registry at crate root with
declare_registry!(global)
- Submit unit test anywhere within the crate. The current registry boundary is crate. Different crate can share the same registry name.
#[kernel_test(global)]
fn testme() -> bool {...}
- run test:
let test_result: (usize, Vec<TestFnInfo>) = test_all!(global)
- if not specified, fn to be registered should have prototype
fn() -> bool
, wheretrue
indicates that test is passed. User can declare their own fn registry with different prototype, for exampledeclare_registry(my_registry: [fn() -> Option<()>])
- User can also provide their own runner routine (either in form of fn path or closure) as parameter of
test_all
macro, for exampletest_all!(my_registry, |f: fn() -> Option<()>| f().is_some())
. My own usage of custom runner is that I use the catch_unwind function within my kernel to capture the potential panic from the unit test, so that I may writeassert!
in unit test fns as people usually with std support.
linkme
and extern crate alloc