Lines Matching +full:test +full:- +full:docs
3 [![crates.io][crates-badge]][crates-url]
4 [![docs.rs][docs-badge]][docs-url]
5 [![Apache licensed][license-badge]][license-url]
6 [![Build Status][actions-badge]][actions-url]
8 [crates-badge]: https://img.shields.io/crates/v/googletest.svg
9 [crates-url]: https://crates.io/crates/googletest
10 [docs-badge]: https://img.shields.io/badge/docs.rs-googletest-66c2a5
11 [docs-url]: https://docs.rs/googletest/*/googletest/
12 [license-badge]: https://img.shields.io/badge/license-Apache-blue.svg
13 [license-url]: https://github.com/google/googletest-rust/blob/main/LICENSE
14 [actions-badge]: https://github.com/google/googletest-rust/workflows/CI/badge.svg
15 [actions-url]: https://github.com/google/googletest-rust/actions?query=workflow%3ACI+branch%3Amain
40 actual value one is asserting: (in-)equality, containment, regular expression
45 * [`assert_that!`] panics if the assertion fails, aborting the test.
46 * [`expect_that!`] logs an assertion failure, marking the test as having
47 failed, but allows the test to continue running (called a _non-fatal
48 assertion_). It requires the use of the [`googletest::test`] attribute macro
49 on the test itself.
53 …[`?` operator](https://doc.rust-lang.org/reference/expressions/operator-expr.html#the-question-mar…
54 this can be used to abort the test on assertion failure without panicking. It
62 #[test]
68 #[googletest::test]
71 expect_that!(value, eq(4)); // Test now failed, but continues executing.
75 #[test]
76 fn fails_immediately_without_panic() -> Result<()> {
78 verify_that!(value, eq(4))?; // Test fails and aborts.
83 #[test]
84 fn simple_assertion() -> Result<()> {
94 * Containers and set-theoretic matching.
101 #[googletest::test]
113 #[googletest::test]
120 ## Pattern-matching
134 #[test]
162 fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
166 fn describe(&self, matcher_result: MatcherResult) -> String {
182 pub fn eq_my_way<T: PartialEq + Debug>(expected: T) -> impl Matcher<ActualT = T> {
190 #[googletest::test]
196 ## Non-fatal assertions
198 Using non-fatal assertions, a single test is able to log multiple assertion
199 failures. Any single assertion failure causes the test to be considered having
200 failed, but execution continues until the test completes or otherwise aborts.
204 To make a non-fatal assertion, use the macro [`expect_that!`]. The test must
205 also be marked with [`googletest::test`] instead of the Rust-standard `#[test]`.
210 #[googletest::test]
213 expect_that!(value, eq(2)); // Passes; test still considered passing.
214 expect_that!(value, eq(3)); // Fails; logs failure and marks the test failed.
219 This can be used in the same tests as `verify_that!`, in which case the test
225 #[googletest::test]
226 fn failing_non_fatal_assertion() -> Result<()> {
228 expect_that!(value, eq(3)); // Just marks the test as having failed.
229 verify_that!(value, eq(2))?; // Passes, so does not abort the test.
231 // test fails despite returning Ok(())
238 #[googletest::test]
239 fn failing_fatal_assertion_after_non_fatal_assertion() -> Result<()> {
241 verify_that!(value, eq(3))?; // Fails and aborts the test.
242 expect_that!(value, eq(3)); // Never executes, since the test already aborted.
249 You can use the `#[googletest::test]` macro together with many other libraries
251 macros to the test:
254 #[googletest::test]
259 fn rstest_works_with_google_test(#[case] value: u32) -> Result<()> {
264 Make sure to put `#[googletest::test]` *before* `#[rstest]`. Otherwise the
265 annotated test will run twice, since both macros will attempt to register a test
266 with the Rust test harness.
269 [async tests with Tokio](https://docs.rs/tokio/latest/tokio/attr.test.html) in
273 #[googletest::test]
274 #[tokio::test]
275 async fn should_work_with_tokio() -> Result<()> {
280 There is one caveat when running async tests: test failure reporting through
282 thread than runs the test.
288 in a `verify_pred!` invocation to turn that into a test assertion which passes
292 fn stuff_is_correct(x: i32, y: i32) -> bool {
311 [`verify_that!`]. There is also a macro [`expect_pred!`] to make a non-fatal
314 ## Unconditionally generating a test failure
316 The macro [`fail!`] unconditionally evaluates to a `Result` indicating a test
318 cause a test to fail, with an optional formatted message:
321 #[test]
322 fn always_fails() -> Result<()> {
323 fail!("This test must fail with {}", "today")
330 configuration does not impact whether a test fails or not but how a failure is
332 `~/.cargo/config.toml` instead of in the project-scoped `Cargo.toml`.
337 | ------------- | ------------------------------------------------------- |
338 | NO_COLOR | Disables colored output. See <https://no-color.org/>. |
346 [`and_log_failure()`]: https://docs.rs/googletest/*/googletest/trait.GoogleTestSupport.html#tymetho…
347 [`assert_that!`]: https://docs.rs/googletest/*/googletest/macro.assert_that.html
348 [`expect_pred!`]: https://docs.rs/googletest/*/googletest/macro.expect_pred.html
349 [`expect_that!`]: https://docs.rs/googletest/*/googletest/macro.expect_that.html
350 [`fail!`]: https://docs.rs/googletest/*/googletest/macro.fail.html
351 [`googletest::test`]: https://docs.rs/googletest/*/googletest/attr.test.html
352 [`matches_pattern!`]: https://docs.rs/googletest/*/googletest/macro.matches_pattern.html
353 [`verify_pred!`]: https://docs.rs/googletest/*/googletest/macro.verify_pred.html
354 [`verify_that!`]: https://docs.rs/googletest/*/googletest/macro.verify_that.html
355 [`Describe`]: https://docs.rs/googletest/*/googletest/matcher/trait.Describe.html
356 [`Matcher`]: https://docs.rs/googletest/*/googletest/matcher/trait.Matcher.html
357 [`Result<()>`]: https://docs.rs/googletest/*/googletest/type.Result.html