Skip to content

Commit f73518e

Browse files
committed
SR-10639: Add test for connecting two Process with Pipe.
- The fix for SR-11699 also fixes connecting two processes with pipes.
1 parent 596e6ed commit f73518e

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

TestFoundation/TestProcess.swift

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,6 +724,46 @@ class TestProcess : XCTestCase {
724724
}
725725
}
726726

727+
func test_multiProcesses() {
728+
let source = Process()
729+
source.executableURL = xdgTestHelperURL()
730+
source.arguments = [ "--getcwd" ]
731+
732+
let cat1 = Process()
733+
cat1.executableURL = xdgTestHelperURL()
734+
cat1.arguments = [ "--cat" ]
735+
736+
let cat2 = Process()
737+
cat2.executableURL = xdgTestHelperURL()
738+
cat2.arguments = [ "--cat" ]
739+
740+
let pipe1 = Pipe()
741+
source.standardOutput = pipe1
742+
cat1.standardInput = pipe1
743+
744+
let pipe2 = Pipe()
745+
cat1.standardOutput = pipe2
746+
cat2.standardInput = pipe2
747+
748+
let pipe3 = Pipe()
749+
cat2.standardOutput = pipe3
750+
751+
XCTAssertNoThrow(try source.run())
752+
XCTAssertNoThrow(try cat1.run())
753+
XCTAssertNoThrow(try cat2.run())
754+
cat2.waitUntilExit()
755+
cat1.waitUntilExit()
756+
source.waitUntilExit()
757+
758+
do {
759+
let data = try XCTUnwrap(pipe3.fileHandleForReading.readToEnd())
760+
let pwd = String.init(decoding: data, as: UTF8.self).trimmingCharacters(in: CharacterSet(["\n", "\r"]))
761+
XCTAssertEqual(pwd, FileManager.default.currentDirectoryPath.standardizePath())
762+
} catch {
763+
XCTFail("\(error)")
764+
}
765+
}
766+
727767
static var allTests: [(String, (TestProcess) -> () throws -> Void)] {
728768
var tests = [
729769
("test_exit0" , test_exit0),
@@ -751,7 +791,8 @@ class TestProcess : XCTestCase {
751791
("test_redirect_all_using_nil", test_redirect_all_using_nil),
752792
("test_plutil", test_plutil),
753793
("test_currentDirectory", test_currentDirectory),
754-
("test_pipeCloseBeforeLaunch", test_pipeCloseBeforeLaunch)
794+
("test_pipeCloseBeforeLaunch", test_pipeCloseBeforeLaunch),
795+
("test_multiProcesses", test_multiProcesses),
755796
]
756797

757798
#if !os(Windows)

0 commit comments

Comments
 (0)