#testing-debugging #assertions #assert #macro #test #assertable

assertables

Assertables: assert macros for better testing, debugging, quality assurance, and runtime reliability

51 stable releases (6 major)

new 9.5.0 Dec 7, 2024
9.4.0 Nov 18, 2024
9.2.0 Oct 31, 2024
8.18.0 Oct 9, 2024
3.2.2 May 13, 2021

#70 in Rust patterns

Download history 5035/week @ 2024-08-21 4993/week @ 2024-08-28 5820/week @ 2024-09-04 3973/week @ 2024-09-11 4293/week @ 2024-09-18 4331/week @ 2024-09-25 4395/week @ 2024-10-02 3798/week @ 2024-10-09 3499/week @ 2024-10-16 3173/week @ 2024-10-23 3251/week @ 2024-10-30 4713/week @ 2024-11-06 4628/week @ 2024-11-13 4660/week @ 2024-11-20 3659/week @ 2024-11-27 4505/week @ 2024-12-04

18,169 downloads per month
Used in 14 crates (13 directly)

MIT OR Apache-2…

3MB
47K SLoC

Assertables: Rust crate of assert macros for testing

Assertables is a Rust crate of assert macros to improve you compile-time testing and run-time reliability.

Introduction

The Assertables Rust crate provides many assert macros that can help you develop, test, and debug.

To use this crate, add it to your file Cargo.toml:

assertables = "9.5.0"

Benefits:

  • You can write better tests to improve reliability and maintainability.
  • You can handle more corner cases without needing to write custom code.
  • You can troubleshoot faster because error messages show more detail.

Learning: FAQ, docs, examples, changes, upgrades, developing.

Comparisons: more_asserts, cool_asserts, assert2, claims, etc.

Examples

Examples with numbers:

let i = 10;
assert_lt!(i, 11);
assert_in_range!(i, 1..100);
assert_abs_diff_eq!(i, 12, 2);

Examples with strings:

let s = "hello";
assert_starts_with!(s, "h");
assert_contains!(s, "e");
assert_is_match!(Regex::new(r"h.*o").unwrap(), s);

Examples with arrays:

let a = [1, 2, 3];
assert_not_empty!(a);
assert_len_eq_x!(a, 3);
assert_all!(a.into_iter(), |i: i32| i < 4);

Highlights

Values:

Approximations:

Groups:

Matching:

Results:

Options:

Polls:

Readers:

Collections:

Commands:

Status:

Infix:

For a complete list of modules and macros, see the docs.

Forms

All the macros have forms for an optional message:

All the macros have forms for different outcomes:

Many of the macros have a form "compare left item to right item" that compares items of the same kind, and a form "compare left item to right expression" that compares one item to any arbitrary expression:

Many of the macros has a "success return", which means the macro returns data that you can optionally use for more testing.

Tracking

  • Package: assertables-rust-crate
  • Version: 9.5.0
  • Created: 2021-03-30T15:47:49Z
  • Updated: 2024-11-05T16:40:19Z
  • License: MIT or Apache-2.0 or GPL-2.0 or GPL-3.0 or contact us for more
  • Contact: Joel Parker Henderson (joel@joelparkerhenderson.com)

No runtime deps