File tree Expand file tree Collapse file tree 5 files changed +65
-10
lines changed
Expand file tree Collapse file tree 5 files changed +65
-10
lines changed Original file line number Diff line number Diff line change @@ -62,23 +62,23 @@ impl TestOutcome {
6262 ///
6363 /// **For internal use only. API stablility is not guaranteed!**
6464 #[ doc( hidden) ]
65- pub fn close_current_test_outcome < E : Display > ( result : Result < ( ) , E > ) -> Result < ( ) , ( ) > {
65+ pub fn close_current_test_outcome < E : Display > ( inner_result : Result < ( ) , E > ) -> Result < ( ) , ( ) > {
6666 TestOutcome :: with_current_test_outcome ( |mut outcome| {
67- let result = match & * outcome {
68- Some ( TestOutcome :: Success ) => match result {
67+ let outer_result = match & * outcome {
68+ Some ( TestOutcome :: Success ) => match inner_result {
6969 Ok ( ( ) ) => Ok ( ( ) ) ,
70- Err ( f) => {
71- print ! ( "{}" , f) ;
72- Err ( ( ) )
73- }
70+ Err ( _) => Err ( ( ) ) ,
7471 } ,
7572 Some ( TestOutcome :: Failure ) => Err ( ( ) ) ,
7673 None => {
7774 panic ! ( "No test context found. This indicates a bug in GoogleTest." )
7875 }
7976 } ;
77+ if let Err ( fatal_assertion_failure) = inner_result {
78+ println ! ( "{fatal_assertion_failure}" ) ;
79+ }
8080 * outcome = None ;
81- result
81+ outer_result
8282 } )
8383 }
8484
Original file line number Diff line number Diff line change @@ -94,6 +94,11 @@ name = "failure_due_to_returned_error"
9494path = " src/failure_due_to_returned_error.rs"
9595test = false
9696
97+ [[bin ]]
98+ name = " fatal_and_non_fatal_failure"
99+ path = " src/fatal_and_non_fatal_failure.rs"
100+ test = false
101+
97102[[bin ]]
98103name = " first_failure_aborts"
99104path = " src/first_failure_aborts.rs"
Original file line number Diff line number Diff line change 1+ // Copyright 2022 Google LLC
2+ //
3+ // Licensed under the Apache License, Version 2.0 (the "License");
4+ // you may not use this file except in compliance with the License.
5+ // You may obtain a copy of the License at
6+ //
7+ // http://www.apache.org/licenses/LICENSE-2.0
8+ //
9+ // Unless required by applicable law or agreed to in writing, software
10+ // distributed under the License is distributed on an "AS IS" BASIS,
11+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ // See the License for the specific language governing permissions and
13+ // limitations under the License.
14+
15+ fn main ( ) { }
16+
17+ #[ cfg( test) ]
18+ mod tests {
19+ use googletest:: prelude:: * ;
20+
21+ #[ googletest:: test]
22+ fn fatal_and_non_fatal_failure ( ) -> Result < ( ) > {
23+ let value = 2 ;
24+ verify_that ! ( value, eq( 3 ) ) . and_log_failure ( ) ;
25+ verify_that ! ( value, eq( 4 ) ) ?;
26+ Ok ( ( ) )
27+ }
28+ }
Original file line number Diff line number Diff line change @@ -126,8 +126,8 @@ mod tests {
126126 }
127127
128128 #[ test]
129- fn should_output_second_failure_message_on_second_assertion_failure_with_expect_that ( )
130- -> Result < ( ) > {
129+ fn should_output_second_failure_message_on_second_assertion_failure_with_expect_that (
130+ ) -> Result < ( ) > {
131131 let output = run_external_process_in_tests_directory ( "two_expect_that_failures" ) ?;
132132
133133 verify_that ! (
@@ -220,6 +220,27 @@ mod tests {
220220 )
221221 }
222222
223+ #[ test]
224+ fn should_log_fatal_and_non_fatal_errors_to_stdout ( ) -> Result < ( ) > {
225+ let output = run_external_process_in_tests_directory ( "fatal_and_non_fatal_failure" ) ?;
226+
227+ verify_that ! (
228+ output,
229+ all!(
230+ contains_substring( indoc! { "
231+ Expected: is equal to 3
232+ Actual: 2,
233+ which isn't equal to 3
234+ " } ) ,
235+ contains_substring( indoc! { "
236+ Expected: is equal to 4
237+ Actual: 2,
238+ which isn't equal to 4
239+ " } )
240+ )
241+ )
242+ }
243+
223244 #[ test]
224245 fn should_abort_after_first_failure ( ) -> Result < ( ) > {
225246 let output = run_external_process_in_tests_directory ( "first_failure_aborts" ) ?;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ INTEGRATION_TEST_BINARIES=(
3535 " failure_due_to_fail_macro_with_empty_message"
3636 " failure_due_to_fail_macro_with_format_arguments"
3737 " failure_due_to_returned_error"
38+ " fatal_and_non_fatal_failure"
3839 " first_failure_aborts"
3940 " google_test_with_rstest"
4041 " non_fatal_failure_in_subroutine"
You can’t perform that action at this time.
0 commit comments