#[static_test]
```rust use statictest::statictest;
fn testslicegetwillalwayssucceediflengthisknown( buffer: &[u8] ) -> u8 { assume!( buffer.len() == 1 ); match buffer.get( 0 ) { Some( &value ) => value, None => staticunreachable!() } }
fn testmultiplication( value: u8 ) { assume!( value == 2 ); staticassert!( value * 10 == 20 ); } ```
You can specify arbitrary types as parameters and as the return type of every
function you mark as #[static_test]
. The bodies of those functions will never
actually be executed, however every static_assert!
and static_unreachable!
will still be indirectly checked.
If the compiler can't prove that every static_assert!
will always hold true
and that every static_unreachable!
will always be unreachable then an error
will be generated at link time.
Every function marked as #[static_test]
will be turned into a #[test]
function.
The assume!
, static_assert!
and static_unreachable!
macros are defined
by the procedural macro and are only available inside functions marked as #[static_test]
.
cargo check
.static_assert!
s and static_unreachable!
s.This is inspired by the no_panic crate.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.