Skip to content

Commit a6bfbe0

Browse files
authored
Merge pull request #2237 from compnerd/handle-pipes-with-care
TestFoundation: make TestPipe pass on Windows
2 parents 8238d23 + 156c6e8 commit a6bfbe0

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

TestFoundation/TestPipe.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,19 @@
1111
class TestPipe: XCTestCase {
1212

1313
static var allTests: [(String, (TestPipe) -> () throws -> Void)] {
14-
return [
15-
("test_MaxPipes", test_MaxPipes),
14+
var tests: [(String, (TestPipe) -> () throws -> Void)] = [
1615
("test_Pipe", test_Pipe),
1716
]
17+
18+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
19+
tests.append(contentsOf: [
20+
("test_MaxPipes", test_MaxPipes),
21+
])
22+
#endif
23+
return tests
1824
}
1925

26+
#if NS_FOUNDATION_ALLOWS_TESTABLE_IMPORT
2027
func test_MaxPipes() {
2128
// Try and create enough pipes to exhaust the process's limits. 1024 is a reasonable
2229
// hard limit for the test. This is reached when testing on Linux (at around 488 pipes)
@@ -27,14 +34,15 @@ class TestPipe: XCTestCase {
2734
pipes.reserveCapacity(maxPipes)
2835
for _ in 1...maxPipes {
2936
let pipe = Pipe()
30-
if pipe.fileHandleForReading.fileDescriptor == -1 {
37+
if !pipe.fileHandleForReading._isPlatformHandleValid {
3138
XCTAssertEqual(pipe.fileHandleForReading.fileDescriptor, pipe.fileHandleForWriting.fileDescriptor)
3239
break
3340
}
3441
pipes.append(pipe)
3542
}
3643
pipes = []
3744
}
45+
#endif
3846

3947
func test_Pipe() throws {
4048
let aPipe = Pipe()

0 commit comments

Comments
 (0)