@@ -24,10 +24,12 @@ pub use godot::test::{bench, itest};
24
24
25
25
// Registers all the `#[itest]` tests and `#[bench]` benchmarks.
26
26
sys:: plugin_registry!( pub ( crate ) __GODOT_ITEST: RustTestCase ) ;
27
+ #[ cfg( since_api = "4.2" ) ]
28
+ sys:: plugin_registry!( pub ( crate ) __GODOT_ASYNC_ITEST: AsyncRustTestCase ) ;
27
29
sys:: plugin_registry!( pub ( crate ) __GODOT_BENCH: RustBenchmark ) ;
28
30
29
31
/// Finds all `#[itest]` tests.
30
- fn collect_rust_tests ( filters : & [ String ] ) -> ( Vec < RustTestCase > , usize , bool ) {
32
+ fn collect_rust_tests ( filters : & [ String ] ) -> ( Vec < RustTestCase > , HashSet < & str > , bool ) {
31
33
let mut all_files = HashSet :: new ( ) ;
32
34
let mut tests: Vec < RustTestCase > = vec ! [ ] ;
33
35
let mut is_focus_run = false ;
@@ -50,7 +52,38 @@ fn collect_rust_tests(filters: &[String]) -> (Vec<RustTestCase>, usize, bool) {
50
52
// Sort alphabetically for deterministic run order
51
53
tests. sort_by_key ( |test| test. file ) ;
52
54
53
- ( tests, all_files. len ( ) , is_focus_run)
55
+ ( tests, all_files, is_focus_run)
56
+ }
57
+
58
+ /// Finds all `#[itest(async)]` tests.
59
+ #[ cfg( since_api = "4.2" ) ]
60
+ fn collect_async_rust_tests (
61
+ filters : & [ String ] ,
62
+ sync_focus_run : bool ,
63
+ ) -> ( Vec < AsyncRustTestCase > , HashSet < & str > , bool ) {
64
+ let mut all_files = HashSet :: new ( ) ;
65
+ let mut tests = vec ! [ ] ;
66
+ let mut is_focus_run = sync_focus_run;
67
+
68
+ sys:: plugin_foreach!( __GODOT_ASYNC_ITEST; |test: & AsyncRustTestCase | {
69
+ // First time a focused test is encountered, switch to "focused" mode and throw everything away.
70
+ if !is_focus_run && test. focused {
71
+ tests. clear( ) ;
72
+ all_files. clear( ) ;
73
+ is_focus_run = true ;
74
+ }
75
+
76
+ // Only collect tests if normal mode, or focus mode and test is focused.
77
+ if ( !is_focus_run || test. focused) && passes_filter( filters, test. name) {
78
+ all_files. insert( test. file) ;
79
+ tests. push( * test) ;
80
+ }
81
+ } ) ;
82
+
83
+ // Sort alphabetically for deterministic run order
84
+ tests. sort_by_key ( |test| test. file ) ;
85
+
86
+ ( tests, all_files, is_focus_run)
54
87
}
55
88
56
89
/// Finds all `#[bench]` benchmarks.
@@ -71,7 +104,7 @@ fn collect_rust_benchmarks() -> (Vec<RustBenchmark>, usize) {
71
104
72
105
// ----------------------------------------------------------------------------------------------------------------------------------------------
73
106
// Shared types
74
-
107
+ # [ derive ( Clone ) ]
75
108
pub struct TestContext {
76
109
pub scene_tree : Gd < Node > ,
77
110
pub property_tests : Gd < Node > ,
@@ -108,6 +141,19 @@ pub struct RustTestCase {
108
141
pub function : fn ( & TestContext ) ,
109
142
}
110
143
144
+ #[ cfg( since_api = "4.2" ) ]
145
+ #[ derive( Copy , Clone ) ]
146
+ pub struct AsyncRustTestCase {
147
+ pub name : & ' static str ,
148
+ pub file : & ' static str ,
149
+ pub skipped : bool ,
150
+ /// If one or more tests are focused, only they will be executed. Helpful for debugging and working on specific features.
151
+ pub focused : bool ,
152
+ #[ allow( dead_code) ]
153
+ pub line : u32 ,
154
+ pub function : fn ( & TestContext ) -> godot:: builtin:: TaskHandle ,
155
+ }
156
+
111
157
#[ derive( Copy , Clone ) ]
112
158
pub struct RustBenchmark {
113
159
pub name : & ' static str ,
0 commit comments