Skip to content

Commit fda780c

Browse files
committed
Add a new test
1 parent f91d424 commit fda780c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Tests/ProcessInvocationTests/ProcessInvocationTests.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,27 @@ final class ProcessInvocationTests : XCTestCase {
540540
/* LINUXASYNC STOP --------- */
541541
}
542542

543+
func testBashPipeLikeFlow() throws {
544+
/* LINUXASYNC START --------- */
545+
let group = DispatchGroup()
546+
group.enter()
547+
Task{do{
548+
/* LINUXASYNC STOP --------- */
549+
550+
let (fdRead, fdWrite) = try ProcessInvocation.unownedPipe()
551+
let invocation1 = ProcessInvocation("printf", "%s", "1+2", stdoutRedirect: .toFd(fdWrite, giveOwnership: true))
552+
_ = try invocation1.invoke(outputHandler: { _, _, _ in })
553+
let invocation2 = ProcessInvocation("bc", stdinRedirect: .sendFromReader(FileDescriptorReader(stream: fdRead, bufferSize: 3, bufferSizeIncrement: 1)))
554+
let output = try await invocation2.invokeAndGetOutput()
555+
XCTAssertEqual(output, [.init(line: "3", eol: "\n", fd: .standardOutput)])
556+
557+
/* LINUXASYNC START --------- */
558+
group.leave()
559+
} catch {XCTFail("Error thrown during async test: \(error)"); group.leave()}}
560+
group.wait()
561+
/* LINUXASYNC STOP --------- */
562+
}
563+
543564
/* Works, but so slow. */
544565
// func testSendBiggerDataToStdin() throws {
545566
// /* LINUXASYNC START --------- */

0 commit comments

Comments
 (0)