@@ -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,35 @@ 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 ( filters : & [ String ] ) -> ( Vec < AsyncRustTestCase > , HashSet < & str > , bool ) {
61
+ let mut all_files = HashSet :: new ( ) ;
62
+ let mut tests = vec ! [ ] ;
63
+ let mut is_focus_run = false ;
64
+
65
+ sys:: plugin_foreach!( __GODOT_ASYNC_ITEST; |test: & AsyncRustTestCase | {
66
+ // First time a focused test is encountered, switch to "focused" mode and throw everything away.
67
+ if !is_focus_run && test. focused {
68
+ tests. clear( ) ;
69
+ all_files. clear( ) ;
70
+ is_focus_run = true ;
71
+ }
72
+
73
+ // Only collect tests if normal mode, or focus mode and test is focused.
74
+ if ( !is_focus_run || test. focused) && passes_filter( filters, test. name) {
75
+ all_files. insert( test. file) ;
76
+ tests. push( * test) ;
77
+ }
78
+ } ) ;
79
+
80
+ // Sort alphabetically for deterministic run order
81
+ tests. sort_by_key ( |test| test. file ) ;
82
+
83
+ ( tests, all_files, is_focus_run)
54
84
}
55
85
56
86
/// Finds all `#[bench]` benchmarks.
@@ -71,7 +101,7 @@ fn collect_rust_benchmarks() -> (Vec<RustBenchmark>, usize) {
71
101
72
102
// ----------------------------------------------------------------------------------------------------------------------------------------------
73
103
// Shared types
74
-
104
+ # [ derive ( Clone ) ]
75
105
pub struct TestContext {
76
106
pub scene_tree : Gd < Node > ,
77
107
pub property_tests : Gd < Node > ,
@@ -108,6 +138,19 @@ pub struct RustTestCase {
108
138
pub function : fn ( & TestContext ) ,
109
139
}
110
140
141
+ #[ cfg( since_api = "4.2" ) ]
142
+ #[ derive( Copy , Clone ) ]
143
+ pub struct AsyncRustTestCase {
144
+ pub name : & ' static str ,
145
+ pub file : & ' static str ,
146
+ pub skipped : bool ,
147
+ /// If one or more tests are focused, only they will be executed. Helpful for debugging and working on specific features.
148
+ pub focused : bool ,
149
+ #[ allow( dead_code) ]
150
+ pub line : u32 ,
151
+ pub function : fn ( & TestContext ) -> godot:: builtin:: TaskHandle ,
152
+ }
153
+
111
154
#[ derive( Copy , Clone ) ]
112
155
pub struct RustBenchmark {
113
156
pub name : & ' static str ,
0 commit comments