- Rust 100%
| .claude | ||
| .github/workflows | ||
| bin | ||
| doc | ||
| help | ||
| src | ||
| tests | ||
| .gitignore | ||
| alfa.txt | ||
| assertables.md | ||
| bravo.txt | ||
| build.rs | ||
| Cargo.toml | ||
| CHANGES.md | ||
| CITATION.cff | ||
| CODE_OF_CONDUCT.md | ||
| CODEOWNERS | ||
| CONTRIBUTING.md | ||
| cspell.json | ||
| deny.toml | ||
| funding.json | ||
| LICENSE.md | ||
| llms.json | ||
| llms.txt | ||
| README.md | ||
Assertables: assert macros for better testing
Assertables is a Rust crate of assert macros to improve your compile-time tests and run-time reliability.
documentation • comparisons • llms • email • codeberg • crates.io • github • gitlab
Introduction
The Assertables Rust crate provides many assert macros that can help you develop, test, and debug.
This documentation is also available as llms.txt.
- Test values with assert_lt, assert_gt, assert_in, …
- Test groups with assert_all, assert_any, assert_iter, …
- Test wrappers with assert_ok, assert_some, assert_ready, …
- Test matching with assert_matches, assert_is_match, …
- Test approximations with assert_approx, assert_abs_diff, …
- Test programs with assert_command, assert_status, …
- Many more below.
To use this crate, add it to your file Cargo.toml:
assertables = "10.0.0"
To enable all the assert macros everywhere in your code, add it to your src/lib.rs:
#[cfg(test)]
#[macro_use] extern crate assertables;
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 = 1;
assert_lt!(i, 2);
assert_in_range!(&i, 0..2);
Examples with strings:
let s = "hello";
assert_starts_with!(s, "h");
assert_is_match!(Regex::new(r"e.*o").unwrap(), s);
Examples with arrays:
let a = [1, 2, 3];
assert_contains!(a, &2);
assert_all!(a.iter(), |i: i32| i < 4);
Highlights
Values:
assert_eq!(a, b)assert_ne!(a, b)assert_ge!(a, b)assert_gt!(a, b)assert_le!(a, b)assert_lt!(a, b)
Floats:
Approximations:
assert_approx_eq!(a, b)assert_approx_eq_with_absolute_error!(a, b, err)assert_approx_eq_with_relative_error!(a, b, err)
Nearness:
assert_in_delta!(a, b, delta)assert_in_epsilon!(a, b, epsilon)assert_in_range!(a, range)assert_diff_eq_x!(a, b, x)assert_abs_diff_eq_x!(a, b, x)
Groups:
assert_all!(group, predicate)assert_any!(group, predicate)assert_is_empty!(group)assert_len_eq!(a, b)assert_count_eq!(a, b)
Matching:
assert_starts_with!(sequence, x)assert_ends_with!(sequence, x)assert_contains!(container, x)assert_is_match!(matcher, x)assert_matches!(expr, pattern)assert_email_address!(string)
Results:
Options:
Polls:
Readers:
Iterators:
assert_iter_eq!(a, b)assert_iter_ne!(a, b)assert_iter_ge!(a, b)assert_iter_gt!(a, b)assert_iter_le!(a, b)assert_iter_lt!(a, b)
Sets:
Bags:
Commands:
Status:
assert_status_success!(a)assert_status_code_value_eq_x!(a, x)assert_status_code_value_ne_x!(a, x)assert_status_failure!(a)
Infix values:
assert_infix!(a == b)assert_infix!(a != b)assert_infix!(a < b)assert_infix!(a <= b)assert_infix!(a > b)assert_infix!(a >= b)
Infix logic:
assert_infix!(a & b)assert_infix!(a | b)assert_infix!(a ^ b)assert_infix!(a && b)assert_infix!(a || b)
For a complete list of modules and macros, see the docs.
Forms
All the macros have forms for an optional message:
assert_gt!(a, b)// default messageassert_gt!(a, b, "your text")// custom message
All the macros have forms for different outcomes:
assert_gt!(1, 2)// panicassert_gt_as_result!(1, 2)return Resultdebug_assert_gt!(a, b)// panic in debug mode
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:
assert_len_eq!(a, b)// a.len() = b.len()assert_len_eq_x!(a, x)// a.len() = x
Many of the macros has a "success return", which means the macro returns data that you can optionally use for more testing.
let inner = assert_ok!(result)let string = assert_fs_read_to_string_ne!("alfa.txt", "")let stdout = assert_command_stdout_gt!("ls", vec![b' '])
Tracking
- Package: assertables-rust-crate
- Version: 10.0.0
- Created: 2021-03-30T15:47:49Z
- Updated: 2026-05-23T16:03:31Z
- License: MIT or BSD or Apache-2.0 or GPL-2.0 or GPL-3.0 or contact us for more
- Contact: Joel Parker Henderson joel@joelparkerhenderson.com