@@ -62,14 +62,16 @@ impl TestOutcome {
62
62
///
63
63
/// **For internal use only. API stablility is not guaranteed!**
64
64
#[ doc( hidden) ]
65
- pub fn close_current_test_outcome < E : Display > ( inner_result : Result < ( ) , E > ) -> Result < ( ) , ( ) > {
65
+ pub fn close_current_test_outcome < E : Display > (
66
+ inner_result : Result < ( ) , E > ,
67
+ ) -> Result < ( ) , TestFailure > {
66
68
TestOutcome :: with_current_test_outcome ( |mut outcome| {
67
69
let outer_result = match & * outcome {
68
70
Some ( TestOutcome :: Success ) => match inner_result {
69
71
Ok ( ( ) ) => Ok ( ( ) ) ,
70
- Err ( _) => Err ( ( ) ) ,
72
+ Err ( _) => Err ( TestFailure ) ,
71
73
} ,
72
- Some ( TestOutcome :: Failure ) => Err ( ( ) ) ,
74
+ Some ( TestOutcome :: Failure ) => Err ( TestFailure ) ,
73
75
None => {
74
76
panic ! ( "No test context found. This indicates a bug in GoogleTest." )
75
77
}
@@ -114,6 +116,29 @@ No test context found.
114
116
}
115
117
}
116
118
119
+ /// A marking struct indicating that a test has failed.
120
+ ///
121
+ /// This exists to implement the [Error][std::error::Error] trait. It displays
122
+ /// to a message indicating that the actual test assertion failure messages are
123
+ /// in the text above.
124
+ pub struct TestFailure ;
125
+
126
+ impl std:: error:: Error for TestFailure { }
127
+
128
+ impl std:: fmt:: Debug for TestFailure {
129
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result < ( ) , Error > {
130
+ writeln ! ( f, "See failure output above" ) ?;
131
+ Ok ( ( ) )
132
+ }
133
+ }
134
+
135
+ impl std:: fmt:: Display for TestFailure {
136
+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> Result < ( ) , Error > {
137
+ writeln ! ( f, "See failure output above" ) ?;
138
+ Ok ( ( ) )
139
+ }
140
+ }
141
+
117
142
/// A report that a single test assertion failed.
118
143
///
119
144
/// **For internal use only. API stablility is not guaranteed!**
0 commit comments