Skip to content

Commit 6188a35

Browse files
committed
Removed the libdispatch dependency
Since pipes can buffer the bytes just fine the asynchronous call was not really necessary for such a simple test anyway.
1 parent a8e08be commit 6188a35

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

TestFoundation/TestNSPipe.swift

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@ import SwiftXCTest
2020
class TestNSPipe : XCTestCase {
2121

2222
func test_NSPipe() {
23-
let expectation = self.expectationWithDescription("Should read data")
2423
let aPipe = NSPipe()
25-
2624
let text = "test-pipe"
2725

28-
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) { () -> Void in
29-
let data = aPipe.fileHandleForReading.readDataOfLength(text.characters.count)
30-
if String(data: data, encoding: NSUTF8StringEncoding) == text {
31-
expectation.fulfill()
32-
}
33-
}
34-
26+
// First write some data into the pipe
3527
aPipe.fileHandleForWriting.writeData(text.dataUsingEncoding(NSUTF8StringEncoding)!)
3628

37-
waitForExpectationsWithTimeout(1.0, handler: nil)
29+
// Then read it out again
30+
let data = aPipe.fileHandleForReading.readDataOfLength(text.characters.count)
31+
32+
// Make sure we *did* get data
33+
XCTAssertNotNil(data)
34+
35+
// Make sure the data can be converted
36+
let convertedData = String(data: data, encoding: NSUTF8StringEncoding)
37+
XCTAssertNotNil(convertedData)
38+
39+
// Make sure we did get back what we wrote in
40+
XCTAssertEqual(text, convertedData)
3841
}
3942
}

0 commit comments

Comments
 (0)