@@ -117,6 +117,33 @@ final class SwiftPMWorkspaceTests: XCTestCase {
117
117
check ( aswift. asString, arguments: arguments)
118
118
}
119
119
120
+ func testManifestArgs( ) {
121
+ // FIXME: should be possible to use InMemoryFileSystem.
122
+ let fs = localFileSystem
123
+ let tempDir = try ! TemporaryDirectory ( removeTreeOnDeinit: true )
124
+ try ! fs. createFiles ( root: tempDir. path, files: [
125
+ " pkg/Sources/lib/a.swift " : " " ,
126
+ " pkg/Package.swift " : """
127
+ // swift-tools-version:4.2
128
+ import PackageDescription
129
+ let package = Package(name: " a " , products: [], dependencies: [],
130
+ targets: [.target(name: " lib " , dependencies: [])])
131
+ """
132
+ ] )
133
+ let packageRoot = tempDir. path. appending ( component: " pkg " )
134
+ let tr = ToolchainRegistry . shared
135
+ let ws = try ! SwiftPMWorkspace (
136
+ workspacePath: packageRoot,
137
+ toolchainRegistry: tr,
138
+ fileSystem: fs)
139
+
140
+ let source = packageRoot. appending ( component: " Package.swift " )
141
+ let arguments = ws. settings ( for: source. asURL, . swift) !. compilerArguments
142
+
143
+ check ( " -swift-version " , " 4.2 " , arguments: arguments)
144
+ check ( source. asString, arguments: arguments)
145
+ }
146
+
120
147
func testMultiFileSwift( ) {
121
148
// FIXME: should be possible to use InMemoryFileSystem.
122
149
let fs = localFileSystem
@@ -189,6 +216,36 @@ final class SwiftPMWorkspaceTests: XCTestCase {
189
216
checkNot ( " -I " , packageRoot. appending ( components: " Sources " , " libC " , " include " ) . asString, arguments: argumentsB)
190
217
}
191
218
219
+ func testUnknownFile( ) {
220
+ // FIXME: should be possible to use InMemoryFileSystem.
221
+ let fs = localFileSystem
222
+ let tempDir = try ! TemporaryDirectory ( removeTreeOnDeinit: true )
223
+ try ! fs. createFiles ( root: tempDir. path, files: [
224
+ " pkg/Sources/libA/a.swift " : " " ,
225
+ " pkg/Sources/libB/b.swift " : " " ,
226
+ " pkg/Package.swift " : """
227
+ // swift-tools-version:4.2
228
+ import PackageDescription
229
+ let package = Package(name: " a " , products: [], dependencies: [],
230
+ targets: [
231
+ .target(name: " libA " , dependencies: []),
232
+ ])
233
+ """
234
+ ] )
235
+ let packageRoot = tempDir. path. appending ( component: " pkg " )
236
+ let tr = ToolchainRegistry . shared
237
+ let ws = try ! SwiftPMWorkspace (
238
+ workspacePath: packageRoot,
239
+ toolchainRegistry: tr,
240
+ fileSystem: fs)
241
+
242
+ let aswift = packageRoot. appending ( components: " Sources " , " libA " , " a.swift " )
243
+ let bswift = packageRoot. appending ( components: " Sources " , " libB " , " b.swift " )
244
+ XCTAssertNotNil ( ws. settings ( for: aswift. asURL, . swift) )
245
+ XCTAssertNil ( ws. settings ( for: bswift. asURL, . swift) )
246
+ XCTAssertNil ( ws. settings ( for: URL ( string: " https://www.apple.com " ) !, . swift) )
247
+ }
248
+
192
249
func testBasicCXXArgs( ) {
193
250
// FIXME: should be possible to use InMemoryFileSystem.
194
251
let fs = localFileSystem
@@ -218,28 +275,37 @@ final class SwiftPMWorkspaceTests: XCTestCase {
218
275
219
276
XCTAssertEqual ( ws. buildPath, build)
220
277
XCTAssertNotNil ( ws. indexStorePath)
221
- let arguments = ws. settings ( for: acxx. asURL, . cpp) !. compilerArguments
222
278
223
- check ( " -MD " , " -MT " , " dependencies " ,
224
- " -MF " , build. appending ( components: " lib.build " , " a.cpp.d " ) . asString,
225
- arguments: arguments)
226
- check ( " -std=c++14 " , arguments: arguments)
279
+ let checkArgsCommon = { ( arguments: [ String ] ) in
280
+ check ( " -std=c++14 " , arguments: arguments)
227
281
228
- checkNot ( " -arch " , arguments: arguments)
229
- check ( " -target " , arguments: arguments) // Only one!
230
- #if os(macOS)
231
- check ( " -target " , " x86_64-apple-macosx10.10 " , arguments: arguments)
232
- check ( " -isysroot " , arguments: arguments)
233
- check ( " -F " , arguments: arguments)
234
- #else
235
- check ( " -target " , " x86_64-unknown-linux " , arguments: arguments)
236
- #endif
282
+ checkNot ( " -arch " , arguments: arguments)
283
+ check ( " -target " , arguments: arguments) // Only one!
284
+ #if os(macOS)
285
+ check ( " -target " , " x86_64-apple-macosx10.10 " , arguments: arguments)
286
+ check ( " -isysroot " , arguments: arguments)
287
+ check ( " -F " , arguments: arguments)
288
+ #else
289
+ check ( " -target " , " x86_64-unknown-linux " , arguments: arguments)
290
+ #endif
291
+
292
+ check ( " -I " , packageRoot. appending ( components: " Sources " , " lib " , " include " ) . asString, arguments: arguments)
293
+ checkNot ( " -I " , build. asString, arguments: arguments)
294
+ checkNot ( bcxx. asString, arguments: arguments)
295
+ }
296
+
297
+ let args = ws. settings ( for: acxx. asURL, . cpp) !. compilerArguments
298
+ checkArgsCommon ( args)
299
+ check ( " -MD " , " -MT " , " dependencies " ,
300
+ " -MF " , build. appending ( components: " lib.build " , " a.cpp.d " ) . asString,
301
+ arguments: args)
302
+ check ( " -c " , acxx. asString, arguments: args)
303
+ check ( " -o " , build. appending ( components: " lib.build " , " a.cpp.o " ) . asString, arguments: args)
237
304
238
- check ( " -I " , packageRoot. appending ( components: " Sources " , " lib " , " include " ) . asString, arguments: arguments)
239
- checkNot ( " -I " , build. asString, arguments: arguments)
240
- check ( " -c " , acxx. asString, arguments: arguments)
241
- checkNot ( bcxx. asString, arguments: arguments)
242
- check ( " -o " , build. appending ( components: " lib.build " , " a.cpp.o " ) . asString, arguments: arguments)
305
+ let header = packageRoot. appending ( components: " Sources " , " lib " , " include " , " a.h " )
306
+ let headerArgs = ws. settings ( for: header. asURL, . cpp) !. compilerArguments
307
+ checkArgsCommon ( headerArgs)
308
+ check ( " -c " , " -x " , " c++-header " , header. asString, arguments: headerArgs)
243
309
}
244
310
245
311
func testDeploymentTargetSwift( ) {
0 commit comments