Skip to content

Commit 8d8db42

Browse files
authored
Merge pull request #48 from DougGregor/self-hosting
Add test for self-hosting
2 parents 09337e9 + 3faebc3 commit 8d8db42

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ let package = Package(
2222
dependencies: ["SwiftToolsSupport-auto", "llbuildSwift"]),
2323
.testTarget(
2424
name: "SwiftDriverTests",
25-
dependencies: ["SwiftDriver"]),
25+
dependencies: ["SwiftDriver", "swift-driver"]),
2626

2727
/// The primary driver executable.
2828
.target(

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ $ swift build -Xcc -I/path/to/build/Ninja-ReleaseAssert/swift-.../include --prod
2424
2525
```
2626

27+
## Testing
28+
29+
Test using command-line SwiftPM or Xcode.
30+
31+
```
32+
$ swift test --parallel
33+
```
34+
35+
Integration tests are costly to run and are disable by default. Enable them
36+
using `SWIFT_DRIVER_ENABLE_INTEGRATION_TESTS` environment variable. In Xcode,
37+
you can set this variable in the scheme's test action.
38+
39+
```
40+
$ SWIFT_DRIVER_ENABLE_INTEGRATION_TESTS=1 swift test --parallel
41+
```
42+
2743
## Using with SwiftPM
2844

2945
Create a symlink of the `swift-driver` binary called `swiftc` and export that
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import XCTest
2+
import TSCBasic
3+
4+
import SwiftDriver
5+
6+
#if os(macOS)
7+
private func bundleRoot() -> AbsolutePath {
8+
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
9+
return AbsolutePath(bundle.bundlePath).parentDirectory
10+
}
11+
fatalError()
12+
}
13+
#endif
14+
15+
16+
final class IntegrationTests: IntegrationTestCase {
17+
func testSelfHosting() throws {
18+
#if os(macOS)
19+
try withTemporaryDirectory() { path in
20+
let binDir = bundleRoot()
21+
let driver = binDir.appending(component: "swift-driver")
22+
let compiler = path.appending(component: "swiftc")
23+
try createSymlink(compiler, pointingAt: driver, relative: false)
24+
25+
let pkg = AbsolutePath(#file).parentDirectory.parentDirectory.parentDirectory
26+
27+
var env = ProcessEnv.vars
28+
env["SWIFT_EXEC"] = compiler.pathString
29+
30+
let buildPath = path.appending(component: "build")
31+
let result = try TSCBasic.Process.checkNonZeroExit(
32+
arguments: [
33+
"swift", "build", "--package-path", pkg.pathString,
34+
"--build-path", buildPath.pathString
35+
],
36+
environment: env
37+
)
38+
39+
XCTAssertTrue(localFileSystem.isExecutableFile(buildPath.appending(RelativePath("debug/swift-driver"))), result)
40+
}
41+
#endif
42+
}
43+
}
44+
45+
/// A helper class for optionally running integration tests.
46+
open class IntegrationTestCase: XCTestCase {
47+
override open class var defaultTestSuite: XCTestSuite {
48+
if ProcessEnv.vars.keys.contains("SWIFT_DRIVER_ENABLE_INTEGRATION_TESTS") {
49+
return super.defaultTestSuite
50+
}
51+
return XCTestSuite(name: String(describing: type(of: self)))
52+
}
53+
}

0 commit comments

Comments
 (0)