@@ -46,12 +46,14 @@ enum TestUtils {
4646@discardableResult
4747func introspection< Entity: AnyObject & Sendable > (
4848 of type: Entity . Type ,
49+ timeout: TimeInterval = 3 ,
50+ sourceLocation: SourceLocation = #_sourceLocation,
4951 @ViewBuilder view: (
5052 _ spy1: @escaping ( Entity ) -> Void
5153 ) -> some View
5254) async throws -> Entity {
5355 var entity1 : Entity ?
54- return try await confirmation ( expectedCount: 1 ... ) { confirmation1 in
56+ return try await confirmation ( expectedCount: 1 ... , sourceLocation : sourceLocation ) { confirmation1 in
5557 let view = view (
5658 {
5759 confirmation1 ( )
@@ -61,27 +63,33 @@ func introspection<Entity: AnyObject & Sendable>(
6163
6264 TestUtils . present ( view: view)
6365
64- while entity1 == nil {
66+ let startInstant = Date ( )
67+ while
68+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
69+ entity1 == nil
70+ {
6571 await Task . yield ( )
6672 }
6773
68- return try #require( entity1)
74+ return try #require( entity1, sourceLocation : sourceLocation )
6975 }
7076}
7177
7278@MainActor
7379@discardableResult
7480func introspection< Entity: AnyObject & Sendable > (
7581 of type: Entity . Type ,
82+ timeout: TimeInterval = 3 ,
83+ sourceLocation: SourceLocation = #_sourceLocation,
7684 @ViewBuilder view: (
7785 _ spy1: @escaping ( Entity ) -> Void ,
7886 _ spy2: @escaping ( Entity ) -> Void
7987 ) -> some View
8088) async throws -> ( Entity , Entity ) {
8189 var entity1 : Entity ?
8290 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
8593 let view = view (
8694 {
8795 confirmation1 ( )
@@ -95,16 +103,18 @@ func introspection<Entity: AnyObject & Sendable>(
95103
96104 TestUtils . present ( view: view)
97105
106+ let startInstant = Date ( )
98107 while
108+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
99109 entity1 == nil ||
100110 entity2 == nil
101111 {
102112 await Task . yield ( )
103113 }
104114
105115 return try (
106- #require( entity1) ,
107- #require( entity2) ,
116+ #require( entity1, sourceLocation : sourceLocation ) ,
117+ #require( entity2, sourceLocation : sourceLocation ) ,
108118 )
109119 }
110120 }
@@ -114,6 +124,8 @@ func introspection<Entity: AnyObject & Sendable>(
114124@discardableResult
115125func introspection< Entity: AnyObject & Sendable > (
116126 of type: Entity . Type ,
127+ timeout: TimeInterval = 3 ,
128+ sourceLocation: SourceLocation = #_sourceLocation,
117129 @ViewBuilder view: (
118130 _ spy1: @escaping ( Entity ) -> Void ,
119131 _ spy2: @escaping ( Entity ) -> Void ,
@@ -123,9 +135,9 @@ func introspection<Entity: AnyObject & Sendable>(
123135 var entity1 : Entity ?
124136 var entity2 : Entity ?
125137 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
129141 let view = view (
130142 {
131143 confirmation1 ( )
@@ -143,7 +155,9 @@ func introspection<Entity: AnyObject & Sendable>(
143155
144156 TestUtils . present ( view: view)
145157
158+ let startInstant = Date ( )
146159 while
160+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
147161 entity1 == nil ||
148162 entity2 == nil ||
149163 entity3 == nil
@@ -152,9 +166,9 @@ func introspection<Entity: AnyObject & Sendable>(
152166 }
153167
154168 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 ) ,
158172 )
159173 }
160174 }
@@ -165,6 +179,8 @@ func introspection<Entity: AnyObject & Sendable>(
165179@discardableResult
166180func introspection< Entity: AnyObject & Sendable > (
167181 of type: Entity . Type ,
182+ timeout: TimeInterval = 3 ,
183+ sourceLocation: SourceLocation = #_sourceLocation,
168184 @ViewBuilder view: (
169185 _ spy1: @escaping ( Entity ) -> Void ,
170186 _ spy2: @escaping ( Entity ) -> Void ,
@@ -176,10 +192,10 @@ func introspection<Entity: AnyObject & Sendable>(
176192 var entity2 : Entity ?
177193 var entity3 : Entity ?
178194 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
183199 let view = view (
184200 {
185201 confirmation1 ( )
@@ -201,7 +217,9 @@ func introspection<Entity: AnyObject & Sendable>(
201217
202218 TestUtils . present ( view: view)
203219
220+ let startInstant = Date ( )
204221 while
222+ Date ( ) . timeIntervalSince ( startInstant) < timeout,
205223 entity1 == nil ||
206224 entity2 == nil ||
207225 entity3 == nil ||
@@ -211,10 +229,10 @@ func introspection<Entity: AnyObject & Sendable>(
211229 }
212230
213231 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 ) ,
218236 )
219237 }
220238 }
0 commit comments