Skip to content

Commit eba9508

Browse files
committed
[test] Add a test for BuildSetup
1 parent 80951b9 commit eba9508

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

Tests/SKSwiftPMWorkspaceTests/SwiftPMWorkspaceTests.swift

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,44 @@ final class SwiftPMWorkspaceTests: XCTestCase {
123123
check(aswift.asString, arguments: arguments)
124124
}
125125

126+
func testBuildSetup() {
127+
// FIXME: should be possible to use InMemoryFileSystem.
128+
let fs = localFileSystem
129+
let tempDir = try! TemporaryDirectory(removeTreeOnDeinit: true)
130+
try! fs.createFiles(root: tempDir.path, files: [
131+
"pkg/Sources/lib/a.swift": "",
132+
"pkg/Package.swift": """
133+
// swift-tools-version:4.2
134+
import PackageDescription
135+
let package = Package(name: "a", products: [], dependencies: [],
136+
targets: [.target(name: "lib", dependencies: [])])
137+
"""
138+
])
139+
let packageRoot = tempDir.path.appending(component: "pkg")
140+
let tr = ToolchainRegistry.shared
141+
142+
let config = BuildSetup(
143+
configuration: .release,
144+
path: packageRoot.appending(component: "non_default_build_path"),
145+
flags: BuildFlags(xcc: ["-m32"], xcxx: [], xswiftc: ["-typecheck"], xlinker: []))
146+
147+
let ws = try! SwiftPMWorkspace(
148+
workspacePath: packageRoot,
149+
toolchainRegistry: tr,
150+
fileSystem: fs,
151+
buildSetup: config)
152+
153+
let aswift = packageRoot.appending(components: "Sources", "lib", "a.swift")
154+
let build = buildPath(root: packageRoot, config: config)
155+
156+
XCTAssertEqual(ws.buildPath, build)
157+
let arguments = ws.settings(for: aswift.asURL, .swift)!.compilerArguments
158+
159+
check("-typecheck", arguments: arguments)
160+
check("-Xcc", "-m32", arguments: arguments)
161+
check("-O", arguments: arguments)
162+
}
163+
126164
func testManifestArgs() {
127165
// FIXME: should be possible to use InMemoryFileSystem.
128166
let fs = localFileSystem
@@ -384,18 +422,22 @@ private func check(
384422
}
385423
}
386424

387-
private func buildPath(root: AbsolutePath) -> AbsolutePath {
388-
if let absoluteBuildPath = TestSourceKitServer.buildSetup.path {
425+
private func buildPath(
426+
root: AbsolutePath,
427+
config: BuildSetup = TestSourceKitServer.buildSetup) -> AbsolutePath
428+
{
429+
let buildConfig = "\(config.configuration)"
430+
if let absoluteBuildPath = config.path {
389431
#if os(macOS)
390-
return absoluteBuildPath.appending(components: "x86_64-apple-macosx", "debug")
432+
return absoluteBuildPath.appending(components: "x86_64-apple-macosx", buildConfig)
391433
#else
392-
return absoluteBuildPath.appending(components: "x86_64-unknown-linux", "debug")
434+
return absoluteBuildPath.appending(components: "x86_64-unknown-linux", buildConfig)
393435
#endif
394436
} else {
395437
#if os(macOS)
396-
return root.appending(components: ".build", "x86_64-apple-macosx", "debug")
438+
return root.appending(components: ".build", "x86_64-apple-macosx", buildConfig)
397439
#else
398-
return root.appending(components: ".build", "x86_64-unknown-linux", "debug")
440+
return root.appending(components: ".build", "x86_64-unknown-linux", buildConfig)
399441
#endif
400442
}
401443
}

Tests/SKSwiftPMWorkspaceTests/XCTestManifests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ extension SwiftPMWorkspaceTests {
88
static let __allTests__SwiftPMWorkspaceTests = [
99
("testBasicCXXArgs", testBasicCXXArgs),
1010
("testBasicSwiftArgs", testBasicSwiftArgs),
11+
("testBuildSetup", testBuildSetup),
1112
("testDeploymentTargetSwift", testDeploymentTargetSwift),
1213
("testManifestArgs", testManifestArgs),
1314
("testMultiFileSwift", testMultiFileSwift),

0 commit comments

Comments
 (0)