@@ -46,12 +46,14 @@ enum TestUtils {
46
46
@discardableResult
47
47
func introspection< Entity: AnyObject & Sendable > (
48
48
of type: Entity . Type ,
49
+ timeout: TimeInterval = 3 ,
50
+ sourceLocation: SourceLocation = #_sourceLocation,
49
51
@ViewBuilder view: (
50
52
_ spy1: @escaping ( Entity ) -> Void
51
53
) -> some View
52
54
) async throws -> Entity {
53
55
var entity1 : Entity ?
54
- return try await confirmation ( expectedCount: 1 ... ) { confirmation1 in
56
+ return try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation1 in
55
57
let view = view (
56
58
{
57
59
confirmation1 ( )
@@ -61,27 +63,33 @@ func introspection<Entity: AnyObject & Sendable>(
61
63
62
64
TestUtils . present ( view: view)
63
65
64
- while entity1 == nil {
66
+ let startInstant = Date ( )
67
+ while
68
+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
69
+ entity1 == nil
70
+ {
65
71
await Task . yield ( )
66
72
}
67
73
68
- return try #require( entity1)
74
+ return try #require( entity1, sourceLocation : sourceLocation )
69
75
}
70
76
}
71
77
72
78
@MainActor
73
79
@discardableResult
74
80
func introspection< Entity: AnyObject & Sendable > (
75
81
of type: Entity . Type ,
82
+ timeout: TimeInterval = 3 ,
83
+ sourceLocation: SourceLocation = #_sourceLocation,
76
84
@ViewBuilder view: (
77
85
_ spy1: @escaping ( Entity ) -> Void ,
78
86
_ spy2: @escaping ( Entity ) -> Void
79
87
) -> some View
80
88
) async throws -> ( Entity , Entity ) {
81
89
var entity1 : Entity ?
82
90
var entity2 : Entity ?
83
- return try await confirmation ( expectedCount: 1 ... ) { confirmation1 in
84
- try await confirmation ( expectedCount: 1 ... ) { confirmation2 in
91
+ return try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation1 in
92
+ try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation2 in
85
93
let view = view (
86
94
{
87
95
confirmation1 ( )
@@ -95,16 +103,18 @@ func introspection<Entity: AnyObject & Sendable>(
95
103
96
104
TestUtils . present ( view: view)
97
105
106
+ let startInstant = Date ( )
98
107
while
108
+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
99
109
entity1 == nil ||
100
110
entity2 == nil
101
111
{
102
112
await Task . yield ( )
103
113
}
104
114
105
115
return try (
106
- #require( entity1) ,
107
- #require( entity2) ,
116
+ #require( entity1, sourceLocation : sourceLocation ) ,
117
+ #require( entity2, sourceLocation : sourceLocation ) ,
108
118
)
109
119
}
110
120
}
@@ -114,6 +124,8 @@ func introspection<Entity: AnyObject & Sendable>(
114
124
@discardableResult
115
125
func introspection< Entity: AnyObject & Sendable > (
116
126
of type: Entity . Type ,
127
+ timeout: TimeInterval = 3 ,
128
+ sourceLocation: SourceLocation = #_sourceLocation,
117
129
@ViewBuilder view: (
118
130
_ spy1: @escaping ( Entity ) -> Void ,
119
131
_ spy2: @escaping ( Entity ) -> Void ,
@@ -123,9 +135,9 @@ func introspection<Entity: AnyObject & Sendable>(
123
135
var entity1 : Entity ?
124
136
var entity2 : Entity ?
125
137
var entity3 : Entity ?
126
- return try await confirmation ( expectedCount: 1 ... ) { confirmation1 in
127
- try await confirmation ( expectedCount: 1 ... ) { confirmation2 in
128
- try await confirmation ( expectedCount: 1 ... ) { confirmation3 in
138
+ return try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation1 in
139
+ try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation2 in
140
+ try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation3 in
129
141
let view = view (
130
142
{
131
143
confirmation1 ( )
@@ -143,7 +155,9 @@ func introspection<Entity: AnyObject & Sendable>(
143
155
144
156
TestUtils . present ( view: view)
145
157
158
+ let startInstant = Date ( )
146
159
while
160
+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
147
161
entity1 == nil ||
148
162
entity2 == nil ||
149
163
entity3 == nil
@@ -152,9 +166,9 @@ func introspection<Entity: AnyObject & Sendable>(
152
166
}
153
167
154
168
return try (
155
- #require( entity1) ,
156
- #require( entity2) ,
157
- #require( entity3) ,
169
+ #require( entity1, sourceLocation : sourceLocation ) ,
170
+ #require( entity2, sourceLocation : sourceLocation ) ,
171
+ #require( entity3, sourceLocation : sourceLocation ) ,
158
172
)
159
173
}
160
174
}
@@ -165,6 +179,8 @@ func introspection<Entity: AnyObject & Sendable>(
165
179
@discardableResult
166
180
func introspection< Entity: AnyObject & Sendable > (
167
181
of type: Entity . Type ,
182
+ timeout: TimeInterval = 3 ,
183
+ sourceLocation: SourceLocation = #_sourceLocation,
168
184
@ViewBuilder view: (
169
185
_ spy1: @escaping ( Entity ) -> Void ,
170
186
_ spy2: @escaping ( Entity ) -> Void ,
@@ -176,10 +192,10 @@ func introspection<Entity: AnyObject & Sendable>(
176
192
var entity2 : Entity ?
177
193
var entity3 : Entity ?
178
194
var entity4 : Entity ?
179
- return try await confirmation ( expectedCount: 1 ... ) { confirmation1 in
180
- try await confirmation ( expectedCount: 1 ... ) { confirmation2 in
181
- try await confirmation ( expectedCount: 1 ... ) { confirmation3 in
182
- try await confirmation ( expectedCount: 1 ... ) { confirmation4 in
195
+ return try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation1 in
196
+ try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation2 in
197
+ try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation3 in
198
+ try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation4 in
183
199
let view = view (
184
200
{
185
201
confirmation1 ( )
@@ -201,7 +217,9 @@ func introspection<Entity: AnyObject & Sendable>(
201
217
202
218
TestUtils . present ( view: view)
203
219
220
+ let startInstant = Date ( )
204
221
while
222
+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
205
223
entity1 == nil ||
206
224
entity2 == nil ||
207
225
entity3 == nil ||
@@ -211,10 +229,10 @@ func introspection<Entity: AnyObject & Sendable>(
211
229
}
212
230
213
231
return try (
214
- #require( entity1) ,
215
- #require( entity2) ,
216
- #require( entity3) ,
217
- #require( entity4) ,
232
+ #require( entity1, sourceLocation : sourceLocation ) ,
233
+ #require( entity2, sourceLocation : sourceLocation ) ,
234
+ #require( entity3, sourceLocation : sourceLocation ) ,
235
+ #require( entity4, sourceLocation : sourceLocation ) ,
218
236
)
219
237
}
220
238
}
0 commit comments