Kernal
Kernal (Kernal Extensive Rust Natural Assertion Language) allows you to use fluent assertions in
Rust tests. That is, instead of writing assert_eq!(my_vec.len(), 10), you can write
assert_that!(my_vec).has_length(10), making your tests more readable and enabling the framework to
provide more expressive error messages. Kernal aims to provide specialized assertions for as many
commonly tested properties as possible.
Writing an assertion
To write an assertion over a value, start with assert_that!(<your value>), which gives you an
instance on which you can call associated functions to make your assertions. Import the specialized
extension traits, such as StringAssertions for special assertions for Strings, from the
prelude module. This gives you all imports you need to write every assertion supported by Kernal.
use *;
assert_that!.contains;
Chaining
Every assertion returns the same asserter instance to continue writing assertions on the same value. In addition, some extension traits define mapping methods that manipulate the data in some way and return asserter instances on the new data.
assert_that!
.has_char_length
.ends_with
.to_chars
.is_sorted_in_strictly_ascending_order;
Creating custom assertions
Kernal allows the creation of custom assertions to test instances of your types in a more natural
way. This is achieved by grouping assertions you want to offer for specific types into traits, which
are then implemented on the output type of the assert_that macro. For more details, view the
crate-level documentation. The example below demonstrates this process.
// Our type for which we want to write assertions.
// The custom assertion trait we will later implement on `AssertThat`.