Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.2] Merge pull request #5 from spevans/pr_linux_fix #14

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions Sources/SwiftSyntax/SwiftcInvocation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions Tests/LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -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),
])
12 changes: 12 additions & 0 deletions Tests/SwiftSyntaxTest/AbsolutePosition.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
7 changes: 6 additions & 1 deletion Tests/SwiftSyntaxTest/DeserializeFile.swift
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
6 changes: 6 additions & 0 deletions Tests/SwiftSyntaxTest/DiagnosticTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 6 additions & 0 deletions Tests/SwiftSyntaxTest/LazyCaching.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
5 changes: 5 additions & 0 deletions Tests/SwiftSyntaxTest/ParseFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion Tests/SwiftSyntaxTest/SyntaxChildren.swift
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
13 changes: 12 additions & 1 deletion Tests/SwiftSyntaxTest/SyntaxCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion Tests/SwiftSyntaxTest/SyntaxFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
8 changes: 8 additions & 0 deletions Tests/SwiftSyntaxTest/VisitorTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down