1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//! # Testing errors
//!
//! Matchers that check the parts of a
//! [`BunsenError`](crate::errors::BunsenError) a test cares about, in the style
//! of hamcrest: the kind, the message, a frame, the details, a typed cause. A
//! test pins what it is about and nothing else, and a failure says what was
//! expected, what missed, and prints the error's full report.
//!
//! This module exists with the `testing` feature, and in bunsen's own unit
//! tests.
//!
//! ```
//! use bunsen::errors::{
//! BunsenError,
//! BunsenErrorKind,
//! BunsenResult,
//! LookupError,
//! LookupProblem,
//! ResultContext,
//! testing::{
//! ErrorMatcher,
//! predicate,
//! },
//! };
//!
//! fn lookup_set(name: &str) -> BunsenResult<()> {
//! Err(BunsenError::lookup(
//! LookupError::missing("shard set", name)
//! .with_candidates(["tiny", "small"]),
//! ))
//! .context("loading the corpus")
//! }
//!
//! ErrorMatcher::kind(BunsenErrorKind::Lookup)
//! .message_contains("no shard set")
//! .frame_contains("loading")
//! .cause(predicate("a missing \"large\"", |c: &LookupError| {
//! c.problem == LookupProblem::Missing && c.key == "large"
//! }))
//! .assert_err(&lookup_set("large"));
//! ```
//!
//! [`ErrorMatcher`] is a fluent builder of clauses, each a [`Matcher`] on one
//! part of the error. The building blocks are plain functions returning
//! matchers: [`text`] on strings, [`value`] on values, and the combinators
//! [`all_of`], [`any_of`], [`not`], [`anything`] and [`predicate`]. A
//! `predicate` takes any closure, which is where a test binds the fields of a
//! typed cause it cares about.
pub use *;
pub use *;