1 unstable release
0.1.0 | Jun 25, 2019 |
---|
#205 in No standard library
59KB
739 lines
chek
: macros for checking things.
This is essentially a set of more fully-featured assert macros along the lines
of assert_eq!
, assert_ne!
, etc. It provides better output than just
performing a comparison in the assert!(...)
body, in that it includes the
values of the arguments on output. Unlike assert_eq!
/assert_ne!
, it also
will log the expression strings that produced the value.
It's the successor to my more-asserts
crate, which is somewhat unpleasant to use
in rust 2018 without a #[macro_use] extern crate ...
, due to the long module name.
Additionally, it is no_std compatible in all configurations.
Usage
Cargo features
inline_panics
This changes the assertions to panic directly, instead of calling a separate
function which performs the panic. This results in better error reporting in the
panic itself (it will report the correct line number / file instead of reporting
that the panic happened inside the chek
crate), at the cost of some additional
code bloat.
This is on by default.
Assertions
The following macros all take optional formatting message args as well, e.g.
check::lt!(a, b, "it should have been less because of: {}", thing)
. Note that
even if this is provided, a
and b
will still be logged, so you don't need to
do that manually.
-
chek::less!(a, b)
: Equivalent toassert!(a < b)
, but with better output on failure- A debug_assertions-only version is available:
chek::debug_less!
. - The following aliases are provided:
chek::lt!
andchek::debug_lt!
for the debug_assertions-only version.
- A debug_assertions-only version is available:
-
chek::less_or_equal!(a, b)
: Equivalent toassert!(a <= b)
, but with better output on failure- A debug_assertions-only version is available:
chek::less_or_equal!
. - The following aliases are provided:
chek::le!
andchek::debug_le!
for the debug_assertions-only version.
- A debug_assertions-only version is available:
-
chek::greater!(a, b)
: Equivalent toassert!(a > b)
, but with better output on failure- A debug_assertions-only version is available:
chek::debug_greater!
. - The following aliases are provided:
chek::gt!
andchek::debug_gt!
for the debug_assertions-only version.
- A debug_assertions-only version is available:
-
chek::greater_or_equal!(a, b)
: Equivalent toassert!(a >= b)
, but with better output on failure- A debug_assertions-only version is available:
chek::debug_greater_or_equal!
. - The following aliases are provided:
chek::ge!
andchek::debug_ge!
for the debug_assertions-only version.
- A debug_assertions-only version is available:
-
chek::equal!(a, b)
: Equivalent toassert_eq!(a, b)
, but with better output on failure.- A debug_assertions-only version is available:
chek::debug_equal!
. - The following aliases are provided:
chek::eq!
andchek::debug_eq!
for the debug_assertions-only version.
- A debug_assertions-only version is available:
-
chek::not_equal!(a, b)
: Equivalent toassert_ne!(a, b)
, but with better output on failure.- A debug_assertions-only version is available:
chek::debug_not_equal!
. - The following aliases are provided:
chek::ne!
andchek::debug_ne!
for the debug_assertions-only version.
- A debug_assertions-only version is available:
-
chek::almost_zero!(a)
: Similar toassert!(almost::zero(a))
, but with better output on failure.- A debug_assertions-only version is available:
chek::debug_almost_zero!
. - Uses the
almost
crate. See thealmost::zero
documentation documentation for more details.
- A debug_assertions-only version is available:
-
chek::not_almost_zero!(a)
: Similar toassert!(!almost::zero(a))
, but with better output on failure.- A debug_assertions-only version is available:
chek::debug_not_almost_zero!
. - Uses the
almost
crate. See thealmost::zero
documentation documentation for more details.
- A debug_assertions-only version is available:
-
chek::almost_equal!(a, b)
: Equivalent toassert!(almost::equal(a, b))
, but with better output on failure.- Important: Do not use if
a
orb
is a hard-coded constant zero! instead, usechek::almost_zero!(v)
. - A debug_assertions-only version is available:
chek::debug_almost_equal!
. - Uses the
almost
crate. See thealmost::equal
documentation documentation for more details.
- Important: Do not use if
-
chek::not_almost_equal!(a, b)
: Equivalent toassert!(!almost::equal(a, b))
, but with better output on failure.- Important: Do not use if
a
orb
is a hard-coded constant zero! instead, usechek::not_almost_zero!(v)
. - A debug_assertions-only version is available:
chek::debug_not_almost_equal!
. - Uses the
almost
crate. See thealmost::equal
documentation documentation for more details.
- Important: Do not use if
-
chek::almost_zero_with_tolerance!(a)
: Similar toassert!(almost::zero_with_tolerance(a, b, tol))
, but with better output on failure.- A debug_assertions-only version is available:
chek::debug_almost_zero_with_tolerance!
. - Uses the
almost
crate. See thealmost::zero_with_tolerance
documentation documentation for more details.
- A debug_assertions-only version is available:
-
chek::not_almost_zero_with_tolerance!(a)
: Similar toassert!(!almost::zero_with_tolerance(a, b, tol))
, but with better output on failure.- A debug_assertions-only version is available:
chek::debug_not_almost_zero_with_tolerance!
. - Uses the
almost
crate. See thealmost::zero_with_tolerance
documentation documentation for more details.
- A debug_assertions-only version is available:
-
chek::debug_unreachable_unchecked!()
: Unsafe. Similar tostd::hint::unreachable_unchecked
, but panics in debug builds if it's hit. -
chek::debug_unreachable!()
: Equivalent to theunreachable!
macro but replaced with a no-op in release builds.
License
Dependencies
~32KB