assertor/
lib.rs

1// Copyright 2021 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Assertor makes test assertions and failure messages more human-readable.
16//!
17//! Assertor is heavy affected by [Java Truth](https://github.com/google/truth) in terms of API
18//! design and error messages.
19//!
20//! # Example
21//! ```
22//! use assertor::*;
23//!
24//! assert_that!("foobarbaz").contains("bar");
25//! assert_that!("foobarbaz").ends_with("baz");
26//!
27//! assert_that!(0.5).with_abs_tol(0.2).is_approx_equal_to(0.6);
28//!
29//! assert_that!(vec!["a", "b"]).contains("a");
30//! assert_that!(vec!["a", "b"]).has_length(2);
31//! assert_that!(vec!["a", "b"]).contains_exactly(vec!["a", "b"]);
32//!
33//! assert_that!(Option::Some("Foo")).has_value("Foo");
34//! ```
35//!
36//! ## Failure cases
37//! ```should_panic
38//! use assertor::*;
39//! assert_that!(vec!["a", "b", "c"]).contains_exactly(vec!["b", "c", "d"]);
40//! // missing (1)   : ["d"]
41//! // unexpected (1): ["a"]
42//! // ---
43//! // expected      : ["b", "c", "d"]
44//! // actual        : ["a", "b", "c"]
45//! ```
46#![warn(missing_docs)]
47
48#[cfg(feature = "float")]
49extern crate num_traits;
50
51#[cfg(feature = "anyhow")]
52pub use assertions::anyhow::AnyhowErrorAssertion;
53pub use assertions::basic::{ComparableAssertion, EqualityAssertion};
54pub use assertions::boolean::BooleanAssertion;
55pub use assertions::cow::CowAssertion;
56#[cfg(feature = "float")]
57pub use assertions::float::FloatAssertion;
58pub use assertions::iterator::IteratorAssertion;
59pub use assertions::map::MapAssertion;
60pub use assertions::map::OrderedMapAssertion;
61pub use assertions::option::OptionAssertion;
62pub use assertions::result::ResultAssertion;
63pub use assertions::set::OrderedSetAssertion;
64pub use assertions::set::SetAssertion;
65pub use assertions::string::StringAssertion;
66pub use assertions::vec::VecAssertion;
67pub use base::{AssertionResult, AssertionStrategy, Fact, Location, Subject};
68
69mod assertions;
70mod base;
71mod diff;
72
73/// Module for testing the assertor library itself. Expected to be used by library developers.
74#[cfg(any(test, doc, feature = "testing"))]
75pub mod testing;