Skip to content

Commit 8043670

Browse files
authored
Merge pull request #2262 from compnerd/dust-yourself-off-and-try-again
TestFoundation: force `process.run()` to succeed
2 parents 6411b81 + 308d3e9 commit 8043670

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

Diff for: TestFoundation/TestProcess.swift

+20-20
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#if !os(Android)
1111
class TestProcess : XCTestCase {
1212

13-
func test_exit0() {
13+
func test_exit0() throws {
1414
let process = Process()
1515
let executableURL = xdgTestHelperURL()
1616
if #available(OSX 10.13, *) {
@@ -21,57 +21,57 @@ class TestProcess : XCTestCase {
2121
}
2222
XCTAssertEqual(executableURL.path, process.launchPath)
2323
process.arguments = ["--exit", "0"]
24-
process.launch()
24+
try? process.run()
2525
process.waitUntilExit()
2626

2727
XCTAssertEqual(process.terminationStatus, 0)
2828
XCTAssertEqual(process.terminationReason, .exit)
2929
}
3030

31-
func test_exit1() {
31+
func test_exit1() throws {
3232
let process = Process()
3333
process.executableURL = xdgTestHelperURL()
3434
process.arguments = ["--exit", "1"]
3535

36-
process.launch()
36+
try? process.run()
3737
process.waitUntilExit()
3838
XCTAssertEqual(process.terminationStatus, 1)
3939
XCTAssertEqual(process.terminationReason, .exit)
4040
}
4141

42-
func test_exit100() {
42+
func test_exit100() throws {
4343
let process = Process()
4444
process.executableURL = xdgTestHelperURL()
4545
process.arguments = ["--exit", "100"]
4646

47-
process.launch()
47+
try? process.run()
4848
process.waitUntilExit()
4949
XCTAssertEqual(process.terminationStatus, 100)
5050
XCTAssertEqual(process.terminationReason, .exit)
5151
}
5252

53-
func test_sleep2() {
53+
func test_sleep2() throws {
5454
let process = Process()
5555
process.executableURL = xdgTestHelperURL()
5656
process.arguments = ["--sleep", "2"]
5757

58-
process.launch()
58+
try? process.run()
5959
process.waitUntilExit()
6060
XCTAssertEqual(process.terminationStatus, 0)
6161
XCTAssertEqual(process.terminationReason, .exit)
6262
}
6363

64-
func test_terminationReason_uncaughtSignal() {
64+
func test_terminationReason_uncaughtSignal() throws {
6565
let process = Process()
6666
process.executableURL = xdgTestHelperURL()
6767
process.arguments = ["--signal-self", SIGTERM.description]
68-
process.launch()
68+
try? process.run()
6969
process.waitUntilExit()
7070
XCTAssertEqual(process.terminationStatus, SIGTERM)
7171
XCTAssertEqual(process.terminationReason, .uncaughtSignal)
7272
}
7373

74-
func test_pipe_stdin() {
74+
func test_pipe_stdin() throws {
7575
let process = Process()
7676

7777
process.executableURL = xdgTestHelperURL()
@@ -81,7 +81,7 @@ class TestProcess : XCTestCase {
8181

8282
let inputPipe = Pipe()
8383
process.standardInput = inputPipe
84-
process.launch()
84+
try? process.run()
8585
inputPipe.fileHandleForWriting.write("Hello, 🐶.\n".data(using: .utf8)!)
8686

8787
// Close the input pipe to send EOF to cat.
@@ -98,7 +98,7 @@ class TestProcess : XCTestCase {
9898
XCTAssertEqual(string, "Hello, 🐶.\n")
9999
}
100100

101-
func test_pipe_stdout() {
101+
func test_pipe_stdout() throws {
102102
let process = Process()
103103

104104
process.executableURL = xdgTestHelperURL()
@@ -107,7 +107,7 @@ class TestProcess : XCTestCase {
107107
process.standardOutput = pipe
108108
process.standardError = nil
109109

110-
process.launch()
110+
try? process.run()
111111
process.waitUntilExit()
112112
XCTAssertEqual(process.terminationStatus, 0)
113113

@@ -119,7 +119,7 @@ class TestProcess : XCTestCase {
119119
XCTAssertEqual(string.trimmingCharacters(in: CharacterSet(["\n"])), FileManager.default.currentDirectoryPath)
120120
}
121121

122-
func test_pipe_stderr() {
122+
func test_pipe_stderr() throws {
123123
let process = Process()
124124

125125
process.executableURL = xdgTestHelperURL()
@@ -128,7 +128,7 @@ class TestProcess : XCTestCase {
128128
let errorPipe = Pipe()
129129
process.standardError = errorPipe
130130

131-
process.launch()
131+
try? process.run()
132132
process.waitUntilExit()
133133
XCTAssertEqual(process.terminationStatus, 1)
134134

@@ -142,7 +142,7 @@ class TestProcess : XCTestCase {
142142
XCTAssertEqual(errMsg, "cat: invalid_file_name: No such file or directory")
143143
}
144144

145-
func test_pipe_stdout_and_stderr_same_pipe() {
145+
func test_pipe_stdout_and_stderr_same_pipe() throws {
146146
let process = Process()
147147

148148
process.executableURL = xdgTestHelperURL()
@@ -155,7 +155,7 @@ class TestProcess : XCTestCase {
155155
// Clear the environment to stop the malloc debug flags used in Xcode debug being
156156
// set in the subprocess.
157157
process.environment = [:]
158-
process.launch()
158+
try? process.run()
159159
process.waitUntilExit()
160160
XCTAssertEqual(process.terminationStatus, 1)
161161

@@ -170,7 +170,7 @@ class TestProcess : XCTestCase {
170170
XCTAssertEqual(errMsg, "cat: invalid_file_name: No such file or directory")
171171
}
172172

173-
func test_file_stdout() {
173+
func test_file_stdout() throws {
174174
let process = Process()
175175

176176
process.executableURL = xdgTestHelperURL()
@@ -184,7 +184,7 @@ class TestProcess : XCTestCase {
184184

185185
process.standardOutput = handle
186186

187-
process.launch()
187+
try? process.run()
188188
process.waitUntilExit()
189189
XCTAssertEqual(process.terminationStatus, 0)
190190

0 commit comments

Comments
 (0)