From 785a2e36ba0b8ad0bc23a2370751c40ec6b49f26 Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Wed, 12 Sep 2018 08:18:05 +0200 Subject: [PATCH] Merge pull request #5 from spevans/pr_linux_fix Linux: Use a DispatchSourceRead instead of a FileHandle.readabilityHandler --- Sources/SwiftSyntax/SwiftcInvocation.swift | 14 ++++++++++---- Tests/LinuxMain.swift | 14 ++++++++++++++ Tests/SwiftSyntaxTest/AbsolutePosition.swift | 12 ++++++++++++ Tests/SwiftSyntaxTest/DeserializeFile.swift | 7 ++++++- Tests/SwiftSyntaxTest/DiagnosticTest.swift | 6 ++++++ Tests/SwiftSyntaxTest/LazyCaching.swift | 6 ++++++ Tests/SwiftSyntaxTest/ParseFile.swift | 5 +++++ Tests/SwiftSyntaxTest/SyntaxChildren.swift | 8 +++++++- Tests/SwiftSyntaxTest/SyntaxCollections.swift | 13 ++++++++++++- Tests/SwiftSyntaxTest/SyntaxFactory.swift | 8 +++++++- Tests/SwiftSyntaxTest/VisitorTest.swift | 8 ++++++++ 11 files changed, 93 insertions(+), 8 deletions(-) create mode 100644 Tests/LinuxMain.swift diff --git a/Sources/SwiftSyntax/SwiftcInvocation.swift b/Sources/SwiftSyntax/SwiftcInvocation.swift index 50e2ecf3192..b187a8f76d4 100644 --- a/Sources/SwiftSyntax/SwiftcInvocation.swift +++ b/Sources/SwiftSyntax/SwiftcInvocation.swift @@ -52,15 +52,21 @@ private func runCore(_ executable: URL, _ arguments: [String] = []) -> ProcessResult { let stdoutPipe = Pipe() var stdoutData = Data() - stdoutPipe.fileHandleForReading.readabilityHandler = { file in - stdoutData.append(file.availableData) + let stdoutSource = DispatchSource.makeReadSource( + fileDescriptor: stdoutPipe.fileHandleForReading.fileDescriptor) + stdoutSource.setEventHandler { + stdoutData.append(stdoutPipe.fileHandleForReading.availableData) } + stdoutSource.resume() let stderrPipe = Pipe() var stderrData = Data() - stderrPipe.fileHandleForReading.readabilityHandler = { file in - stderrData.append(file.availableData) + let stderrSource = DispatchSource.makeReadSource( + fileDescriptor: stderrPipe.fileHandleForReading.fileDescriptor) + stderrSource.setEventHandler { + stderrData.append(stderrPipe.fileHandleForReading.availableData) } + stderrSource.resume() let process = Process() process.launchPath = executable.path diff --git a/Tests/LinuxMain.swift b/Tests/LinuxMain.swift new file mode 100644 index 00000000000..2385dc58522 --- /dev/null +++ b/Tests/LinuxMain.swift @@ -0,0 +1,14 @@ +import XCTest +import SwiftSyntaxTest + +XCTMain([ + testCase(AbsolutePositionTestCase.allTests), + testCase(DecodeSyntaxTestCase.allTests), + testCase(DiagnosticTestCase.allTests), + testCase(LazyCachingTestCase.allTests), + testCase(ParseFileTestCase.allTests), + testCase(SyntaxChildrenAPITestCase.allTests), + testCase(SyntaxCollectionsAPITestCase.allTests), + testCase(SyntaxFactoryAPITestCase.allTests), + testCase(SyntaxVisitorTestCase.allTests), +]) diff --git a/Tests/SwiftSyntaxTest/AbsolutePosition.swift b/Tests/SwiftSyntaxTest/AbsolutePosition.swift index c7a23a22c3e..df59b70af93 100644 --- a/Tests/SwiftSyntaxTest/AbsolutePosition.swift +++ b/Tests/SwiftSyntaxTest/AbsolutePosition.swift @@ -9,6 +9,18 @@ fileprivate class FuncRenamer: SyntaxRewriter { } public class AbsolutePositionTestCase: XCTestCase { + + public static let allTests = [ + ("testVisitor", testVisitor), + ("testClosure", testClosure), + ("testRename", testRename), + ("testCurrentFile", testCurrentFile), + ("testRecursion", testRecursion), + ("testTrivias", testTrivias), + ("testImplicit", testImplicit), + ("testWithoutSourceFileRoot", testWithoutSourceFileRoot), + ] + public func testVisitor() { XCTAssertNoThrow(try { let source = try String(contentsOf: getInput("visitor.swift")) diff --git a/Tests/SwiftSyntaxTest/DeserializeFile.swift b/Tests/SwiftSyntaxTest/DeserializeFile.swift index b0855e1ee5d..72589b143c2 100644 --- a/Tests/SwiftSyntaxTest/DeserializeFile.swift +++ b/Tests/SwiftSyntaxTest/DeserializeFile.swift @@ -1,7 +1,12 @@ import XCTest import SwiftSyntax -public class DecodeSytnaxTestCase: XCTestCase { +public class DecodeSyntaxTestCase: XCTestCase { + + public static let allTests = [ + ("testBasic", testBasic), + ] + public func testBasic() { XCTAssertNoThrow(try { let inputFile = getInput("visitor.swift") diff --git a/Tests/SwiftSyntaxTest/DiagnosticTest.swift b/Tests/SwiftSyntaxTest/DiagnosticTest.swift index 329c1b468bc..4f783ff7c1e 100644 --- a/Tests/SwiftSyntaxTest/DiagnosticTest.swift +++ b/Tests/SwiftSyntaxTest/DiagnosticTest.swift @@ -28,6 +28,12 @@ fileprivate extension Diagnostic.Message { } public class DiagnosticTestCase: XCTestCase { + + public static let allTests = [ + ("testDiagnosticEmission", testDiagnosticEmission), + ("testSourceLocations", testSourceLocations), + ] + public func testDiagnosticEmission() { let startLoc = loc() let fixLoc = loc() diff --git a/Tests/SwiftSyntaxTest/LazyCaching.swift b/Tests/SwiftSyntaxTest/LazyCaching.swift index 42b16bcaa2f..afaa9855702 100644 --- a/Tests/SwiftSyntaxTest/LazyCaching.swift +++ b/Tests/SwiftSyntaxTest/LazyCaching.swift @@ -2,6 +2,12 @@ import XCTest import SwiftSyntax public class LazyCachingTestCase: XCTestCase { + + public static let allTests = [ + ("testPathological", testPathological), + ("testTwoAccesses", testTwoAccesses), + ] + public func testPathological() { let tuple = SyntaxFactory.makeVoidTupleType() diff --git a/Tests/SwiftSyntaxTest/ParseFile.swift b/Tests/SwiftSyntaxTest/ParseFile.swift index fc71e8c8b1f..4cc6ffb40db 100644 --- a/Tests/SwiftSyntaxTest/ParseFile.swift +++ b/Tests/SwiftSyntaxTest/ParseFile.swift @@ -19,6 +19,11 @@ fileprivate class Test: NSObject { #endif public class ParseFileTestCase: XCTestCase { + + public static let allTests = [ + ("testParseSingleFile", testParseSingleFile) + ] + public func testParseSingleFile() { let currentFile = URL(fileURLWithPath: #file) XCTAssertNoThrow(try { diff --git a/Tests/SwiftSyntaxTest/SyntaxChildren.swift b/Tests/SwiftSyntaxTest/SyntaxChildren.swift index c3743787695..1bdebaabd83 100644 --- a/Tests/SwiftSyntaxTest/SyntaxChildren.swift +++ b/Tests/SwiftSyntaxTest/SyntaxChildren.swift @@ -1,7 +1,13 @@ import XCTest import SwiftSyntax -public class SyntaxChilderenTestCase: XCTestCase { +public class SyntaxChildrenAPITestCase: XCTestCase { + + public static let allTests = [ + ("testIterateWithAllPresent", testIterateWithAllPresent), + ("testIterateWithSomeMissing", testIterateWithSomeMissing), + ("testIterateWithAllMissing", testIterateWithAllMissing), + ] public func testIterateWithAllPresent() { let returnStmt = SyntaxFactory.makeReturnStmt( diff --git a/Tests/SwiftSyntaxTest/SyntaxCollections.swift b/Tests/SwiftSyntaxTest/SyntaxCollections.swift index 133f5ae34d5..b0e867139f1 100644 --- a/Tests/SwiftSyntaxTest/SyntaxCollections.swift +++ b/Tests/SwiftSyntaxTest/SyntaxCollections.swift @@ -8,7 +8,18 @@ func integerLiteralElement(_ int: Int) -> ArrayElementSyntax { trailingComma: nil) } -public class SyntaxCollectionsTestCase: XCTestCase { +public class SyntaxCollectionsAPITestCase: XCTestCase { + + public static let allTests = [ + ("testAppendingElement", testAppendingElement), + ("testInsertingElement", testInsertingElement), + ("testPrependingElement", testPrependingElement), + ("testRemovingFirstElement", testRemovingFirstElement), + ("testRemovingLastElement", testRemovingLastElement), + ("testRemovingElement", testRemovingElement), + ("testReplacingElement", testReplacingElement), + ] + public func testAppendingElement() { let arrayElementList = SyntaxFactory.makeArrayElementList([ integerLiteralElement(0) diff --git a/Tests/SwiftSyntaxTest/SyntaxFactory.swift b/Tests/SwiftSyntaxTest/SyntaxFactory.swift index df0b004a891..048f6783291 100644 --- a/Tests/SwiftSyntaxTest/SyntaxFactory.swift +++ b/Tests/SwiftSyntaxTest/SyntaxFactory.swift @@ -16,7 +16,13 @@ func cannedStructDecl() -> StructDeclSyntax { } } -public class SyntaxFactoryTestCase: XCTestCase { +public class SyntaxFactoryAPITestCase: XCTestCase { + + public static let allTests = [ + ("testGenerated", testGenerated), + ("testTokenSyntax", testTokenSyntax), + ("testFunctionCallSyntaxBuilder", testFunctionCallSyntaxBuilder), + ] public func testGenerated() { diff --git a/Tests/SwiftSyntaxTest/VisitorTest.swift b/Tests/SwiftSyntaxTest/VisitorTest.swift index f916fe2dadf..c1079154c0d 100644 --- a/Tests/SwiftSyntaxTest/VisitorTest.swift +++ b/Tests/SwiftSyntaxTest/VisitorTest.swift @@ -2,6 +2,14 @@ import XCTest import SwiftSyntax public class SyntaxVisitorTestCase: XCTestCase { + + public static let allTests = [ + ("testBasic", testBasic), + ("testRewritingNodeWithEmptyChild", testRewritingNodeWithEmptyChild), + ("testSyntaxRewriterVisitAny", testSyntaxRewriterVisitAny), + ("testSyntaxRewriterVisitCollection", testSyntaxRewriterVisitCollection), + ] + public func testBasic() { class FuncCounter: SyntaxVisitor { var funcCount = 0