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