Skip to content

Commit 71ea529

Browse files
committed
changes to run function for stdin pipe
1 parent b671068 commit 71ea529

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

Tests/CLITests/Subcommands/Build/CLIBuildBase.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,7 @@ class TestCLIBuildBase: CLITest {
171171

172172
args.append(contentsOf: otherArgs)
173173

174-
let stdinPipe = Pipe()
175-
try stdinPipe.fileHandleForWriting.write(contentsOf: Data(dockerfileContents.utf8))
176-
stdinPipe.fileHandleForWriting.closeFile()
177-
178-
let response = try run(arguments: args, stdin: stdinPipe)
174+
let response = try run(arguments: args, stdin: dockerfileContents)
179175
if response.status != 0 {
180176
throw CLIError.executionFailed("build failed: stdout=\(response.output) stderr=\(response.error)")
181177
}

Tests/CLITests/Utilities/CLITest.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,25 @@ class CLITest {
110110
}
111111
}
112112

113-
func run(arguments: [String], stdin: Pipe? = nil, currentDirectory: URL? = nil) throws -> (output: String, error: String, status: Int32) {
113+
func run(arguments: [String], stdin: String? = nil, currentDirectory: URL? = nil) throws -> (output: String, error: String, status: Int32) {
114114
let process = Process()
115115
process.executableURL = try executablePath
116116
process.arguments = arguments
117117
if let directory = currentDirectory {
118118
process.currentDirectoryURL = directory
119119
}
120120

121+
let inputPipe = Pipe()
121122
let outputPipe = Pipe()
122123
let errorPipe = Pipe()
124+
process.standardInput = inputPipe
123125
process.standardOutput = outputPipe
124126
process.standardError = errorPipe
125127

126-
if let stdin = stdin {
127-
process.standardInput = stdin
128+
if let data = stdin?.data(using: .utf8) {
129+
inputPipe.fileHandleForWriting.write(data)
128130
}
131+
inputPipe.fileHandleForWriting.closeFile()
129132

130133
do {
131134
try process.run()

0 commit comments

Comments
 (0)