@@ -43,6 +43,7 @@ pub mod matchers;
4343pub mod prelude {
4444 pub use super :: matcher:: Matcher ;
4545 pub use super :: matchers:: * ;
46+ pub use super :: verify_current_test_outcome;
4647 pub use super :: GoogleTestSupport ;
4748 pub use super :: IntoTestResult ;
4849 pub use super :: Result ;
@@ -83,6 +84,37 @@ use internal::test_outcome::{TestAssertionFailure, TestOutcome};
8384/// failed but allow it to continue running, are not encoded in this type.
8485pub type Result < T > = std:: result:: Result < T , TestAssertionFailure > ;
8586
87+ /// Returns a [`Result`] corresponding to the outcome of the currently running
88+ /// test.
89+ ///
90+ /// This returns `Result::Err` precisely if the current test has recorded at
91+ /// least one test assertion failure via [`expect_that!`][crate::expect_that],
92+ /// [`expect_pred!`][crate::expect_pred], or
93+ /// [`GoogleTestSupport::and_log_failure`]. It can be used in concert with the
94+ /// `?` operator to continue execution of the test conditionally on there not
95+ /// having been any failure yet.
96+ ///
97+ /// This requires the use of the [`#[googletest::test]`][crate::test] attribute
98+ /// macro.
99+ ///
100+ /// ```
101+ /// # use googletest::prelude::*;
102+ /// # /* Make sure this also compiles as a doctest.
103+ /// #[googletest::test]
104+ /// # */
105+ /// fn should_fail_and_not_execute_last_assertion() -> Result<()> {
106+ /// # googletest::internal::test_outcome::TestOutcome::init_current_test_outcome();
107+ /// let value = 1;
108+ /// expect_that!(value, eq(2)); // Fails but does not abort the test.
109+ /// verify_current_test_outcome()?; // Aborts the test due to the previous failure.
110+ /// verify_that!(value, eq(1)) // Does not execute.
111+ /// }
112+ /// # verify_that!(should_fail_and_not_execute_last_assertion(), err(displays_as(contains_substring("Test failed")))).unwrap();
113+ /// ```
114+ pub fn verify_current_test_outcome ( ) -> Result < ( ) > {
115+ TestOutcome :: get_current_test_outcome ( )
116+ }
117+
86118/// Adds to `Result` support for GoogleTest Rust functionality.
87119pub trait GoogleTestSupport {
88120 /// If `self` is a `Result::Err`, writes to `stdout` a failure report
0 commit comments