Crates.io | assertables |
lib.rs | assertables |
version | 9.8.0 |
source | src |
created_at | 2021-04-03 19:32:43.093705+00 |
updated_at | 2025-06-23 22:32:29.010265+00 |
description | Assertables: assert macros for better testing, debugging, quality assurance, and runtime reliability. |
homepage | |
repository | https://github.com/sixarm/assertables-rust-crate/ |
max_upload_size | |
id | 378431 |
size | 7,196,947 |
Assertables is a Rust crate of assert macros to improve your compile-time tests and run-time reliability.
documentation • source • llms.txt • crate • email
The Assertables Rust crate provides many assert macros that can help you develop, test, and debug.
This documentation is also available as llms.txt.
To use this crate, add it to your file Cargo.toml
:
assertables = "9.8.0"
Benefits:
Learning: FAQ, docs, examples, changes, upgrades, developing.
Comparisons: more_asserts, cool_asserts, assert2, claims, etc.
Examples with numbers:
let i = 1;
assert_lt!(i, 5);
assert_diff_eq_x!(i, 5, 4);
assert_in_range!(&i, &(1..5));
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);
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:
Nearness:
assert_approx_eq!(a, b)
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.
All the macros have forms for an optional message:
assert_gt!(a, b)
// default message
assert_gt!(a, b, "your text")
// custom message
All the macros have forms for different outcomes:
assert_gt!(1, 2)
// panic
assert_gt_as_result!(1, 2)
return Result
debug_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' '])