@@ -53,7 +53,7 @@ pub mod prelude {
5353 pub use super :: matchers:: * ;
5454 pub use super :: verify_current_test_outcome;
5555 pub use super :: GoogleTestSupport ;
56- pub use super :: IntoTestResult ;
56+ pub use super :: OrFail ;
5757 pub use super :: Result ;
5858 // Assert macros
5959 pub use super :: {
@@ -238,8 +238,8 @@ impl<T> GoogleTestSupport for std::result::Result<T, TestAssertionFailure> {
238238 }
239239}
240240
241- /// Provides an extension method for converting an arbitrary type into a
242- /// [`Result`].
241+ /// Provides an extension method for converting an arbitrary type into
242+ /// `googletest`'s [`Result`] type .
243243///
244244/// A type can implement this trait to provide an easy way to return immediately
245245/// from a test in conjunction with the `?` operator. This is useful for
@@ -252,41 +252,48 @@ impl<T> GoogleTestSupport for std::result::Result<T, TestAssertionFailure> {
252252/// ```ignore
253253/// #[test]
254254/// fn should_work() -> googletest::Result<()> {
255- /// let value = something_which_can_fail().into_test_result ()?;
256- /// let value = something_which_can_fail_with_option().into_test_result ()?;
255+ /// let value = something_which_can_fail().or_fail ()?;
256+ /// let value = something_which_can_fail_with_option().or_fail ()?;
257257/// ...
258258/// }
259259///
260260/// fn something_which_can_fail() -> std::result::Result<T, String> { ... }
261261/// fn something_which_can_fail_with_option() -> Option<T> { ... }
262262/// ```
263- pub trait IntoTestResult < T > {
264- /// Converts this instance into a [`Result`].
263+ pub trait OrFail {
264+ /// The success type of the test result.
265+ type Output ;
266+
267+ /// Converts a value into a [`Result`] containing
268+ /// either the [`Self::Output`] type or a [`TestAssertionFailure`].
265269 ///
266- /// Typically, the `Self` type is itself an implementation of the
267- /// [`std::ops::Try`] trait. This method should then map the `Residual`
268- /// variant to a [`TestAssertionFailure`] and leave the `Output` variant
269- /// unchanged.
270- fn into_test_result ( self ) -> Result < T > ;
270+ /// The most frequently used implementations convert
271+ /// `Result<T, E>` into `Result<T, TestAssertionFailure>` and
272+ /// `Option<T>` into `Result<T, TestAssertionFailure>`.
273+ fn or_fail ( self ) -> Result < Self :: Output > ;
271274}
272275
273- impl < T , E : std:: fmt:: Debug > IntoTestResult < T > for std:: result:: Result < T , E > {
276+ impl < T , E : std:: fmt:: Debug > OrFail for std:: result:: Result < T , E > {
277+ type Output = T ;
278+
274279 #[ track_caller]
275- fn into_test_result ( self ) -> std:: result:: Result < T , TestAssertionFailure > {
280+ fn or_fail ( self ) -> std:: result:: Result < T , TestAssertionFailure > {
276281 match self {
277282 Ok ( t) => Ok ( t) ,
278283 Err ( e) => Err ( TestAssertionFailure :: create ( format ! ( "{e:?}" ) ) ) ,
279284 }
280285 }
281286}
282287
283- impl < T > IntoTestResult < T > for Option < T > {
288+ impl < T > OrFail for Option < T > {
289+ type Output = T ;
290+
284291 #[ track_caller]
285- fn into_test_result ( self ) -> std:: result:: Result < T , TestAssertionFailure > {
292+ fn or_fail ( self ) -> std:: result:: Result < T , TestAssertionFailure > {
286293 match self {
287294 Some ( t) => Ok ( t) ,
288295 None => Err ( TestAssertionFailure :: create ( format ! (
289- "called `Option::into_test_result ()` on a `Option::<{}>::None` value" ,
296+ "called `Option::or_fail ()` on a `Option::<{}>::None` value" ,
290297 std:: any:: type_name:: <T >( )
291298 ) ) ) ,
292299 }
0 commit comments