Skip to content

Commit 785a2e3

Browse files
ahoppenallevato
authored andcommitted
Merge pull request #5 from spevans/pr_linux_fix
Linux: Use a DispatchSourceRead instead of a FileHandle.readabilityHandler
1 parent aa3f4bd commit 785a2e3

11 files changed

+93
-8
lines changed

Sources/SwiftSyntax/SwiftcInvocation.swift

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,21 @@ private func runCore(_ executable: URL, _ arguments: [String] = [])
5252
-> ProcessResult {
5353
let stdoutPipe = Pipe()
5454
var stdoutData = Data()
55-
stdoutPipe.fileHandleForReading.readabilityHandler = { file in
56-
stdoutData.append(file.availableData)
55+
let stdoutSource = DispatchSource.makeReadSource(
56+
fileDescriptor: stdoutPipe.fileHandleForReading.fileDescriptor)
57+
stdoutSource.setEventHandler {
58+
stdoutData.append(stdoutPipe.fileHandleForReading.availableData)
5759
}
60+
stdoutSource.resume()
5861

5962
let stderrPipe = Pipe()
6063
var stderrData = Data()
61-
stderrPipe.fileHandleForReading.readabilityHandler = { file in
62-
stderrData.append(file.availableData)
64+
let stderrSource = DispatchSource.makeReadSource(
65+
fileDescriptor: stderrPipe.fileHandleForReading.fileDescriptor)
66+
stderrSource.setEventHandler {
67+
stderrData.append(stderrPipe.fileHandleForReading.availableData)
6368
}
69+
stderrSource.resume()
6470

6571
let process = Process()
6672
process.launchPath = executable.path

Tests/LinuxMain.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import XCTest
2+
import SwiftSyntaxTest
3+
4+
XCTMain([
5+
testCase(AbsolutePositionTestCase.allTests),
6+
testCase(DecodeSyntaxTestCase.allTests),
7+
testCase(DiagnosticTestCase.allTests),
8+
testCase(LazyCachingTestCase.allTests),
9+
testCase(ParseFileTestCase.allTests),
10+
testCase(SyntaxChildrenAPITestCase.allTests),
11+
testCase(SyntaxCollectionsAPITestCase.allTests),
12+
testCase(SyntaxFactoryAPITestCase.allTests),
13+
testCase(SyntaxVisitorTestCase.allTests),
14+
])

Tests/SwiftSyntaxTest/AbsolutePosition.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ fileprivate class FuncRenamer: SyntaxRewriter {
99
}
1010

1111
public class AbsolutePositionTestCase: XCTestCase {
12+
13+
public static let allTests = [
14+
("testVisitor", testVisitor),
15+
("testClosure", testClosure),
16+
("testRename", testRename),
17+
("testCurrentFile", testCurrentFile),
18+
("testRecursion", testRecursion),
19+
("testTrivias", testTrivias),
20+
("testImplicit", testImplicit),
21+
("testWithoutSourceFileRoot", testWithoutSourceFileRoot),
22+
]
23+
1224
public func testVisitor() {
1325
XCTAssertNoThrow(try {
1426
let source = try String(contentsOf: getInput("visitor.swift"))

Tests/SwiftSyntaxTest/DeserializeFile.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import XCTest
22
import SwiftSyntax
33

4-
public class DecodeSytnaxTestCase: XCTestCase {
4+
public class DecodeSyntaxTestCase: XCTestCase {
5+
6+
public static let allTests = [
7+
("testBasic", testBasic),
8+
]
9+
510
public func testBasic() {
611
XCTAssertNoThrow(try {
712
let inputFile = getInput("visitor.swift")

Tests/SwiftSyntaxTest/DiagnosticTest.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ fileprivate extension Diagnostic.Message {
2828
}
2929

3030
public class DiagnosticTestCase: XCTestCase {
31+
32+
public static let allTests = [
33+
("testDiagnosticEmission", testDiagnosticEmission),
34+
("testSourceLocations", testSourceLocations),
35+
]
36+
3137
public func testDiagnosticEmission() {
3238
let startLoc = loc()
3339
let fixLoc = loc()

Tests/SwiftSyntaxTest/LazyCaching.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import XCTest
22
import SwiftSyntax
33

44
public class LazyCachingTestCase: XCTestCase {
5+
6+
public static let allTests = [
7+
("testPathological", testPathological),
8+
("testTwoAccesses", testTwoAccesses),
9+
]
10+
511
public func testPathological() {
612
let tuple = SyntaxFactory.makeVoidTupleType()
713

Tests/SwiftSyntaxTest/ParseFile.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ fileprivate class Test: NSObject {
1919
#endif
2020

2121
public class ParseFileTestCase: XCTestCase {
22+
23+
public static let allTests = [
24+
("testParseSingleFile", testParseSingleFile)
25+
]
26+
2227
public func testParseSingleFile() {
2328
let currentFile = URL(fileURLWithPath: #file)
2429
XCTAssertNoThrow(try {

Tests/SwiftSyntaxTest/SyntaxChildren.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import XCTest
22
import SwiftSyntax
33

4-
public class SyntaxChilderenTestCase: XCTestCase {
4+
public class SyntaxChildrenAPITestCase: XCTestCase {
5+
6+
public static let allTests = [
7+
("testIterateWithAllPresent", testIterateWithAllPresent),
8+
("testIterateWithSomeMissing", testIterateWithSomeMissing),
9+
("testIterateWithAllMissing", testIterateWithAllMissing),
10+
]
511

612
public func testIterateWithAllPresent() {
713
let returnStmt = SyntaxFactory.makeReturnStmt(

Tests/SwiftSyntaxTest/SyntaxCollections.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,18 @@ func integerLiteralElement(_ int: Int) -> ArrayElementSyntax {
88
trailingComma: nil)
99
}
1010

11-
public class SyntaxCollectionsTestCase: XCTestCase {
11+
public class SyntaxCollectionsAPITestCase: XCTestCase {
12+
13+
public static let allTests = [
14+
("testAppendingElement", testAppendingElement),
15+
("testInsertingElement", testInsertingElement),
16+
("testPrependingElement", testPrependingElement),
17+
("testRemovingFirstElement", testRemovingFirstElement),
18+
("testRemovingLastElement", testRemovingLastElement),
19+
("testRemovingElement", testRemovingElement),
20+
("testReplacingElement", testReplacingElement),
21+
]
22+
1223
public func testAppendingElement() {
1324
let arrayElementList = SyntaxFactory.makeArrayElementList([
1425
integerLiteralElement(0)

Tests/SwiftSyntaxTest/SyntaxFactory.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ func cannedStructDecl() -> StructDeclSyntax {
1616
}
1717
}
1818

19-
public class SyntaxFactoryTestCase: XCTestCase {
19+
public class SyntaxFactoryAPITestCase: XCTestCase {
20+
21+
public static let allTests = [
22+
("testGenerated", testGenerated),
23+
("testTokenSyntax", testTokenSyntax),
24+
("testFunctionCallSyntaxBuilder", testFunctionCallSyntaxBuilder),
25+
]
2026

2127
public func testGenerated() {
2228

Tests/SwiftSyntaxTest/VisitorTest.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@ import XCTest
22
import SwiftSyntax
33

44
public class SyntaxVisitorTestCase: XCTestCase {
5+
6+
public static let allTests = [
7+
("testBasic", testBasic),
8+
("testRewritingNodeWithEmptyChild", testRewritingNodeWithEmptyChild),
9+
("testSyntaxRewriterVisitAny", testSyntaxRewriterVisitAny),
10+
("testSyntaxRewriterVisitCollection", testSyntaxRewriterVisitCollection),
11+
]
12+
513
public func testBasic() {
614
class FuncCounter: SyntaxVisitor {
715
var funcCount = 0

0 commit comments

Comments
 (0)