@@ -360,5 +360,62 @@ fn always_fails() -> Result<()> {
360360# always_fails().unwrap_err();
361361```
362362
363+ ## Integrations with other crates
364+
365+ GoogleTest Rust includes integrations with the
366+ [ Anyhow] ( https://crates.io/crates/anyhow ) and
367+ [ Proptest] ( https://crates.io/crates/proptest ) crates to simplify turning
368+ errors from those crates into test failures.
369+
370+ To use this, activate the ` anyhow ` , respectively ` proptest ` feature in
371+ GoogleTest Rust and invoke the extension method [ ` into_test_result() ` ] on a
372+ ` Result ` value in your test. For example:
373+
374+ ```
375+ # use googletest::prelude::*;
376+ # #[cfg(feature = "anyhow")]
377+ # use anyhow::anyhow;
378+ # #[cfg(feature = "anyhow")]
379+ # /* The attribute macro would prevent the function from being compiled in a doctest.
380+ #[test]
381+ # */
382+ fn has_anyhow_failure() -> Result<()> {
383+ Ok(just_return_error().into_test_result()?)
384+ }
385+
386+ # #[cfg(feature = "anyhow")]
387+ fn just_return_error() -> anyhow::Result<()> {
388+ anyhow::Result::Err(anyhow!("This is an error"))
389+ }
390+ # #[cfg(feature = "anyhow")]
391+ # has_anyhow_failure().unwrap_err();
392+ ```
393+
394+ One can convert Proptest test failures into GoogleTest test failures when the
395+ test is invoked with
396+ [ ` TestRunner::run ` ] ( https://docs.rs/proptest/latest/proptest/test_runner/struct.TestRunner.html#method.run ) :
397+
398+ ```
399+ # use googletest::prelude::*;
400+ # #[cfg(feature = "proptest")]
401+ # use proptest::test_runner::{Config, TestRunner};
402+ # #[cfg(feature = "proptest")]
403+ # /* The attribute macro would prevent the function from being compiled in a doctest.
404+ #[test]
405+ # */
406+ fn numbers_are_greater_than_zero() -> Result<()> {
407+ let mut runner = TestRunner::new(Config::default());
408+ runner.run(&(1..100i32), |v| Ok(verify_that!(v, gt(0))?)).into_test_result()
409+ }
410+ # #[cfg(feature = "proptest")]
411+ # numbers_are_greater_than_zero().unwrap();
412+ ```
413+
414+ Similarly, when the ` proptest ` feature is enabled, GoogleTest assertion failures
415+ can automatically be converted into Proptest
416+ [ ` TestCaseError ` ] ( https://docs.rs/proptest/latest/proptest/test_runner/enum.TestCaseError.html )
417+ through the ` ? ` operator as the example above shows.
418+
363419[ `and_log_failure()` ] : GoogleTestSupport::and_log_failure
420+ [ `into_test_result()` ] : IntoTestResult::into_test_result
364421[ `Matcher` ] : matcher::Matcher
0 commit comments