@@ -141,24 +141,95 @@ final class SourceKitLSPAPITests: XCTestCase {
141
141
)
142
142
let description = BuildDescription ( buildPlan: plan)
143
143
144
- struct Result {
145
- let parent : ( any BuildTarget ) ?
146
- let module : any BuildTarget
147
- let depth : Int
144
+ struct Result : Equatable {
145
+ let moduleName : String
146
+ let moduleDestination : BuildDestination
147
+ let parentName : String ?
148
+ let parentDestination : BuildDestination ?
148
149
}
149
150
150
151
var results : [ Result ] = [ ]
151
- description. traverseModules { current, parent, depth in
152
- results. append ( Result ( parent: parent, module: current, depth: depth) )
152
+ description. traverseModules { current, parent in
153
+ results. append (
154
+ Result (
155
+ moduleName: current. name,
156
+ moduleDestination: current. destination,
157
+ parentName: parent? . name,
158
+ parentDestination: parent? . destination
159
+ )
160
+ )
153
161
}
154
162
155
- XCTAssertEqual ( results. count, 6 )
163
+ XCTAssertEqual (
164
+ results,
165
+ [
166
+ Result ( moduleName: " lib " , moduleDestination: . target, parentName: nil , parentDestination: nil ) ,
167
+ Result ( moduleName: " plugin " , moduleDestination: . host, parentName: nil , parentDestination: nil ) ,
168
+ Result ( moduleName: " exe " , moduleDestination: . host, parentName: " plugin " , parentDestination: . host) ,
169
+ Result ( moduleName: " lib " , moduleDestination: . host, parentName: " exe " , parentDestination: . host) ,
170
+ Result ( moduleName: " exe " , moduleDestination: . target, parentName: nil , parentDestination: nil ) ,
171
+ Result ( moduleName: " lib " , moduleDestination: . target, parentName: " exe " , parentDestination: . target) ,
172
+ ]
173
+ )
174
+ }
175
+
176
+ func testModuleTraversalRecordsDependencyOfVisitedNode( ) async throws {
177
+ let fs = InMemoryFileSystem (
178
+ emptyFiles:
179
+ " /Pkg/Sources/exe/main.swift " ,
180
+ " /Pkg/Sources/lib/lib.swift "
181
+ )
182
+
183
+ let observability = ObservabilitySystem . makeForTesting ( )
184
+ let graph = try loadModulesGraph (
185
+ fileSystem: fs,
186
+ manifests: [
187
+ Manifest . createRootManifest (
188
+ displayName: " Pkg " ,
189
+ path: " /Pkg " ,
190
+ targets: [
191
+ TargetDescription ( name: " exe " , dependencies: [ " lib " ] ) ,
192
+ TargetDescription ( name: " lib " , dependencies: [ ] )
193
+ ]
194
+ ) ,
195
+ ] ,
196
+ observabilityScope: observability. topScope
197
+ )
198
+ XCTAssertNoDiagnostics ( observability. diagnostics)
199
+
200
+ let plan = try await BuildPlan (
201
+ destinationBuildParameters: mockBuildParameters (
202
+ destination: . target,
203
+ shouldLinkStaticSwiftStdlib: true
204
+ ) ,
205
+ toolsBuildParameters: mockBuildParameters (
206
+ destination: . host,
207
+ shouldLinkStaticSwiftStdlib: true
208
+ ) ,
209
+ graph: graph,
210
+ fileSystem: fs,
211
+ observabilityScope: observability. topScope
212
+ )
213
+ let description = BuildDescription ( buildPlan: plan)
156
214
157
- // "lib" is the most interesting here because it appears on multiple depths due to
158
- // "exe" being a dependency of the "plugin".
159
- XCTAssertEqual ( results. filter { $0. module. name == " lib " } . reduce ( into: Set < Int > ( ) ) {
160
- $0. insert ( $1. depth)
161
- } . sorted ( ) , [ 1 , 2 , 3 ] )
215
+ struct Result : Equatable {
216
+ let moduleName : String
217
+ let parentName : String ?
218
+ }
219
+
220
+ var results : [ Result ] = [ ]
221
+ description. traverseModules { current, parent in
222
+ results. append ( Result ( moduleName: current. name, parentName: parent? . name) )
223
+ }
224
+
225
+ XCTAssertEqual (
226
+ results,
227
+ [
228
+ Result ( moduleName: " lib " , parentName: nil ) ,
229
+ Result ( moduleName: " exe " , parentName: nil ) ,
230
+ Result ( moduleName: " lib " , parentName: " exe " ) ,
231
+ ]
232
+ )
162
233
}
163
234
}
164
235
0 commit comments