xpct
xpct is an assertions library for Rust. It's designed to be ergonomic, batteries-included, and test framework agnostic.
About
xpct is extensible. In addition to allowing you to write custom matchers, it separates the logic of matchers from how they format their output, meaning you can:
- Hook into existing formatters to write custom matchers with pretty output without having to worry about formatting.
- Customize the formatting of existing matchers without having to reimplement their logic.
Want to get started? Check out the tutorial.
How do you pronounce "xpct"?
However you choose to pronounce it is how it's pronounced! I pronounce it like "expect."
Examples
A simple equality assertion, like assert_eq:
use ;
expect!.to;
[src/main.rs:4:5] = "disco"
Expected:
"disco"
to equal:
"Disco"
Asserting that every element in a vec is Some and unwrapping it to a
Vec<&str>:
use ;
let items = vec!;
let output: = expect!
.to
.into_inner;
[src/main.rs:6:29] = items
Expected all of these to be OK:
[0] OK
[1] OK
[2] FAILED
Expected this to be Some(_)
Asserting that the given string does not match any of the given matchers:
use ;
let location = Stringfrom;
expect!.to_not;
[src/main.rs:6:5] = location
Expected all of these to be OK:
[0] OK
[1] FAILED
Expected:
"Central Jamrock"
to not contain the substring:
"Jamrock"
[2] OK
Making assertions about individual fields of a struct:
use ;
expect!
.to
.to;
[src/main.rs:22:5] = get_person()
Expected all of these to be OK:
my_crate::main::Person {
name: FAILED
Expected this to be Some(_)
age: OK
id: FAILED
🛈 all IDs must have this prefix
Expected:
"12-62-05-JAM41"
to have the prefix:
"REV"
is_superstar: OK
}
MSRV Policy
The last two stable Rust releases are supported, but older releases may or may not also be supported.
The MSRV will only be increased when necessary to take advantage of new Rust features, not every time there is a new Rust release. An increase in the MSRV will be accompanied by a minor semver bump if >1.0.0 or a patch semver bump if <1.0.0.
Semver Policy
Prior to version 1.0.0, breaking changes will be accompanied by a minor version bump and new features will be accompanied by a patch version bump. This is something that is not specified in the semver spec.