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 {
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 > ( result : Result < ( ) , E > ) -> Result < ( ) , ( ) > {
65
+ pub fn close_current_test_outcome < E : Display > ( inner_result : Result < ( ) , E > ) -> Result < ( ) , ( ) > {
66
66
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 {
69
69
Ok ( ( ) ) => Ok ( ( ) ) ,
70
- Err ( f) => {
71
- print ! ( "{}" , f) ;
72
- Err ( ( ) )
73
- }
70
+ Err ( _) => Err ( ( ) ) ,
74
71
} ,
75
72
Some ( TestOutcome :: Failure ) => Err ( ( ) ) ,
76
73
None => {
77
74
panic ! ( "No test context found. This indicates a bug in GoogleTest." )
78
75
}
79
76
} ;
77
+ if let Err ( fatal_assertion_failure) = inner_result {
78
+ println ! ( "{fatal_assertion_failure}" ) ;
79
+ }
80
80
* outcome = None ;
81
- result
81
+ outer_result
82
82
} )
83
83
}
84
84
Original file line number Diff line number Diff line change @@ -94,6 +94,11 @@ name = "failure_due_to_returned_error"
94
94
path = " src/failure_due_to_returned_error.rs"
95
95
test = false
96
96
97
+ [[bin ]]
98
+ name = " fatal_and_non_fatal_failure"
99
+ path = " src/fatal_and_non_fatal_failure.rs"
100
+ test = false
101
+
97
102
[[bin ]]
98
103
name = " first_failure_aborts"
99
104
path = " 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 {
126
126
}
127
127
128
128
#[ 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 < ( ) > {
131
131
let output = run_external_process_in_tests_directory ( "two_expect_that_failures" ) ?;
132
132
133
133
verify_that ! (
@@ -220,6 +220,27 @@ mod tests {
220
220
)
221
221
}
222
222
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
+
223
244
#[ test]
224
245
fn should_abort_after_first_failure ( ) -> Result < ( ) > {
225
246
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=(
35
35
" failure_due_to_fail_macro_with_empty_message"
36
36
" failure_due_to_fail_macro_with_format_arguments"
37
37
" failure_due_to_returned_error"
38
+ " fatal_and_non_fatal_failure"
38
39
" first_failure_aborts"
39
40
" google_test_with_rstest"
40
41
" non_fatal_failure_in_subroutine"
You can’t perform that action at this time.
0 commit comments