Assertables: Rust crate of assert macros for testing

The assertables Rust crate provides many assert macros to improve your compile-time tests and run-time reliability.

Crate: https://crates.io/crates/assertables

Docs: https://docs.rs/assertables/

Repo: https://github.com/sixarm/assertables-rust-crate/

Why use this?

When you write Rust tests, then you can use Rust assert macros, such as:

rust assert_eq!(value1, value2)

The assertables Rust crate provides many more assert macros for values, strings, vectors, readers, commands, and more, such as:

rust assert_gt!(value1, value2); // value1 ≥ value2 assert_starts_with!(string1, string2); // string1 starts with string2 assert_is_match!(regex, string); // regex is match of string assert_set_subset!(vector1, vector2); // vector1 as set ⊆ vector2 as set assert_fn_ok_eq!(function1, function2); // function1 ok = function2 ok assert_read_to_string_eq!(reader1, reader2); // reader1 as string = reader2 as string assert_command_stdout_eq!(command1, command2); // command1 standard output = command2 standard output

See below for the complete list of all the assert macros.

Benefits

Features

Complete list of assert macros

assert_* for values

Compare values:

Compare values by using nearness:

assert_* for strings and matchers

These macros help with strings and also other structures that provide matchers such as starts_with, ends_width, contains, and is_match.

assertset* for set collection comparisons

These macros help with comparison of set parameters, such as two arrays or two vectors. where the item order does not matter, and the item count does not matter. These macros convert their inputs into HashSet iterators.

assertbag* for bag collection comparisons

These macros help with comparison of bag parameters, such as comparison of two arrays or two vectors, where the item order does not matter, and the item count does matter. These macros convert their inputs into HashMap iterators.

assertfn* for function return-value comparisons

Compare a function with another function:

Compare a function with an expression:

assertfnok_* for Result Ok() comparisons

Compare a function Ok() with another function Ok():

Compare a function Ok() with an expression:

assertfnerr_* for function Err() comparisons

Compare a function Err() with another function Err():

Compare a function Err() with an expression:

assertreadtostring* for std::io::Read comparisons

These macros help with readers, such as file handles, byte arrays, input streams, and the trait std::io::Read.

Compare a reader with another reader:

Compare a reader with an expression:

assertcommand* for process command comparisons

Compare command standard output string:

Compare command standard error string:

assertprogramargs_* for process command comparisons created via program name and args interator

Compare command using program and arguments to standard output:

Compare command using program and arguments to standard output:

Naming conventions

Abbreviations:

Shorthands:

Forms

Forms for panic! versus Err()

The assert macros have three forms that you can use depending on your goals:

```rust assert_gt!(a, b); // return () or panic!(…), for typical compile-time testing

debugassertgt!(a, b); // return () or panic!(…), for a non-optimized runtime

assertgtas_result!(a, b); // return Result Ok(()) or Err(…), for any runtime ```

Forms for messages

The assert macros have forms for default messages versus custom messages.

```rust assertgt!(1, 2); // panic!("assertion failed: assertgt(1, 2)…")

assert_gt!(1, 2, "message"); // panic!("message") ```

Forms for comparing an other versus an expression

Some assert macros have forms for comparing an other versus an expression:

```rust assertreadtostringeq!(reader1, reader2); // reader1.readtostring() = reader2.readtostring()

assertreadtostringeqexpr!(reader, expr); // reader1.readto_string() = expr ```

Changes summary

Version 7.x top changes

Version 6.x top changes

Tracking