@@ -71,27 +71,29 @@ impl IntegrationTests {
71
71
72
72
let mut last_file = None ;
73
73
for test in tests {
74
+ print_test_pre ( test. name , test. file . to_string ( ) , & mut last_file, false ) ;
74
75
let outcome = run_rust_test ( & test, & ctx) ;
75
76
76
77
self . update_stats ( & outcome) ;
77
- print_test ( test. file . to_string ( ) , test . name , outcome, & mut last_file ) ;
78
+ print_test_post ( test. name , outcome) ;
78
79
}
79
80
}
80
81
81
82
fn run_gdscript_tests ( & mut self , tests : VariantArray ) {
82
83
let mut last_file = None ;
83
84
for test in tests. iter_shared ( ) {
85
+ let test_file = get_property ( & test, "suite_name" ) ;
86
+ let test_case = get_property ( & test, "method_name" ) ;
87
+
88
+ print_test_pre ( & test_case, test_file, & mut last_file, true ) ;
84
89
let result = test. call ( "run" , & [ ] ) ;
85
90
let success = result. try_to :: < bool > ( ) . unwrap_or_else ( |_| {
86
91
panic ! ( "GDScript test case {test} returned non-bool: {result}" )
87
92
} ) ;
88
-
89
- let test_file = get_property ( & test, "suite_name" ) ;
90
- let test_case = get_property ( & test, "method_name" ) ;
91
93
let outcome = TestOutcome :: from_bool ( success) ;
92
94
93
95
self . update_stats ( & outcome) ;
94
- print_test ( test_file , & test_case, outcome, & mut last_file ) ;
96
+ print_test_post ( & test_case, outcome) ;
95
97
}
96
98
}
97
99
@@ -178,16 +180,7 @@ fn run_rust_test(test: &RustTestCase, ctx: &TestContext) -> TestOutcome {
178
180
TestOutcome :: from_bool ( success. is_some ( ) )
179
181
}
180
182
181
- /// Prints a test name and its outcome.
182
- ///
183
- /// Note that this is run after a test run, so stdout/stderr output during the test will be printed before.
184
- /// It would be possible to print the test name before and the outcome after, but that would split or duplicate the line.
185
- fn print_test (
186
- test_file : String ,
187
- test_case : & str ,
188
- outcome : TestOutcome ,
189
- last_file : & mut Option < String > ,
190
- ) {
183
+ fn print_test_pre ( test_case : & str , test_file : String , last_file : & mut Option < String > , flush : bool ) {
191
184
// Check if we need to open a new category for a file
192
185
let print_file = last_file
193
186
. as_ref ( )
@@ -203,12 +196,30 @@ fn print_test(
203
196
println ! ( "\n {file_subtitle}:" ) ;
204
197
}
205
198
206
- println ! ( " -- {test_case} ... {outcome}" ) ;
199
+ print ! ( " -- {test_case} ... " ) ;
200
+ if flush {
201
+ // Flush in GDScript, because its own print may come sooner than Rust prints otherwise
202
+ // (strictly speaking, this can also happen from Rust, when Godot prints something. So far, it didn't though...
203
+ godot:: private:: flush_stdout ( ) ;
204
+ }
207
205
208
206
// State update for file-category-print
209
207
* last_file = Some ( test_file) ;
210
208
}
211
209
210
+ /// Prints a test name and its outcome.
211
+ ///
212
+ /// Note that this is run after a test run, so stdout/stderr output during the test will be printed before.
213
+ /// It would be possible to print the test name before and the outcome after, but that would split or duplicate the line.
214
+ fn print_test_post ( test_case : & str , outcome : TestOutcome ) {
215
+ // If test failed, something was printed (e.g. assertion), so we can print the entire line again; otherwise just outcome on same line.
216
+ if matches ! ( outcome, TestOutcome :: Failed ) {
217
+ println ! ( " -- {test_case} ... {outcome}" ) ;
218
+ } else {
219
+ println ! ( "{outcome}" ) ;
220
+ }
221
+ }
222
+
212
223
fn get_property ( test : & Variant , property : & str ) -> String {
213
224
test. call ( "get" , & [ property. to_variant ( ) ] ) . to :: < String > ( )
214
225
}
0 commit comments