10
10
#if !os(Android)
11
11
class TestProcess : XCTestCase {
12
12
13
- func test_exit0( ) {
13
+ func test_exit0( ) throws {
14
14
let process = Process ( )
15
15
let executableURL = xdgTestHelperURL ( )
16
16
if #available( OSX 10 . 13 , * ) {
@@ -21,57 +21,57 @@ class TestProcess : XCTestCase {
21
21
}
22
22
XCTAssertEqual ( executableURL. path, process. launchPath)
23
23
process. arguments = [ " --exit " , " 0 " ]
24
- process. launch ( )
24
+ try ? process. run ( )
25
25
process. waitUntilExit ( )
26
26
27
27
XCTAssertEqual ( process. terminationStatus, 0 )
28
28
XCTAssertEqual ( process. terminationReason, . exit)
29
29
}
30
30
31
- func test_exit1( ) {
31
+ func test_exit1( ) throws {
32
32
let process = Process ( )
33
33
process. executableURL = xdgTestHelperURL ( )
34
34
process. arguments = [ " --exit " , " 1 " ]
35
35
36
- process. launch ( )
36
+ try ? process. run ( )
37
37
process. waitUntilExit ( )
38
38
XCTAssertEqual ( process. terminationStatus, 1 )
39
39
XCTAssertEqual ( process. terminationReason, . exit)
40
40
}
41
41
42
- func test_exit100( ) {
42
+ func test_exit100( ) throws {
43
43
let process = Process ( )
44
44
process. executableURL = xdgTestHelperURL ( )
45
45
process. arguments = [ " --exit " , " 100 " ]
46
46
47
- process. launch ( )
47
+ try ? process. run ( )
48
48
process. waitUntilExit ( )
49
49
XCTAssertEqual ( process. terminationStatus, 100 )
50
50
XCTAssertEqual ( process. terminationReason, . exit)
51
51
}
52
52
53
- func test_sleep2( ) {
53
+ func test_sleep2( ) throws {
54
54
let process = Process ( )
55
55
process. executableURL = xdgTestHelperURL ( )
56
56
process. arguments = [ " --sleep " , " 2 " ]
57
57
58
- process. launch ( )
58
+ try ? process. run ( )
59
59
process. waitUntilExit ( )
60
60
XCTAssertEqual ( process. terminationStatus, 0 )
61
61
XCTAssertEqual ( process. terminationReason, . exit)
62
62
}
63
63
64
- func test_terminationReason_uncaughtSignal( ) {
64
+ func test_terminationReason_uncaughtSignal( ) throws {
65
65
let process = Process ( )
66
66
process. executableURL = xdgTestHelperURL ( )
67
67
process. arguments = [ " --signal-self " , SIGTERM . description]
68
- process. launch ( )
68
+ try ? process. run ( )
69
69
process. waitUntilExit ( )
70
70
XCTAssertEqual ( process. terminationStatus, SIGTERM)
71
71
XCTAssertEqual ( process. terminationReason, . uncaughtSignal)
72
72
}
73
73
74
- func test_pipe_stdin( ) {
74
+ func test_pipe_stdin( ) throws {
75
75
let process = Process ( )
76
76
77
77
process. executableURL = xdgTestHelperURL ( )
@@ -81,7 +81,7 @@ class TestProcess : XCTestCase {
81
81
82
82
let inputPipe = Pipe ( )
83
83
process. standardInput = inputPipe
84
- process. launch ( )
84
+ try ? process. run ( )
85
85
inputPipe. fileHandleForWriting. write ( " Hello, 🐶. \n " . data ( using: . utf8) !)
86
86
87
87
// Close the input pipe to send EOF to cat.
@@ -98,7 +98,7 @@ class TestProcess : XCTestCase {
98
98
XCTAssertEqual ( string, " Hello, 🐶. \n " )
99
99
}
100
100
101
- func test_pipe_stdout( ) {
101
+ func test_pipe_stdout( ) throws {
102
102
let process = Process ( )
103
103
104
104
process. executableURL = xdgTestHelperURL ( )
@@ -107,7 +107,7 @@ class TestProcess : XCTestCase {
107
107
process. standardOutput = pipe
108
108
process. standardError = nil
109
109
110
- process. launch ( )
110
+ try ? process. run ( )
111
111
process. waitUntilExit ( )
112
112
XCTAssertEqual ( process. terminationStatus, 0 )
113
113
@@ -119,7 +119,7 @@ class TestProcess : XCTestCase {
119
119
XCTAssertEqual ( string. trimmingCharacters ( in: CharacterSet ( [ " \n " ] ) ) , FileManager . default. currentDirectoryPath)
120
120
}
121
121
122
- func test_pipe_stderr( ) {
122
+ func test_pipe_stderr( ) throws {
123
123
let process = Process ( )
124
124
125
125
process. executableURL = xdgTestHelperURL ( )
@@ -128,7 +128,7 @@ class TestProcess : XCTestCase {
128
128
let errorPipe = Pipe ( )
129
129
process. standardError = errorPipe
130
130
131
- process. launch ( )
131
+ try ? process. run ( )
132
132
process. waitUntilExit ( )
133
133
XCTAssertEqual ( process. terminationStatus, 1 )
134
134
@@ -142,7 +142,7 @@ class TestProcess : XCTestCase {
142
142
XCTAssertEqual ( errMsg, " cat: invalid_file_name: No such file or directory " )
143
143
}
144
144
145
- func test_pipe_stdout_and_stderr_same_pipe( ) {
145
+ func test_pipe_stdout_and_stderr_same_pipe( ) throws {
146
146
let process = Process ( )
147
147
148
148
process. executableURL = xdgTestHelperURL ( )
@@ -155,7 +155,7 @@ class TestProcess : XCTestCase {
155
155
// Clear the environment to stop the malloc debug flags used in Xcode debug being
156
156
// set in the subprocess.
157
157
process. environment = [ : ]
158
- process. launch ( )
158
+ try ? process. run ( )
159
159
process. waitUntilExit ( )
160
160
XCTAssertEqual ( process. terminationStatus, 1 )
161
161
@@ -170,7 +170,7 @@ class TestProcess : XCTestCase {
170
170
XCTAssertEqual ( errMsg, " cat: invalid_file_name: No such file or directory " )
171
171
}
172
172
173
- func test_file_stdout( ) {
173
+ func test_file_stdout( ) throws {
174
174
let process = Process ( )
175
175
176
176
process. executableURL = xdgTestHelperURL ( )
@@ -184,7 +184,7 @@ class TestProcess : XCTestCase {
184
184
185
185
process. standardOutput = handle
186
186
187
- process. launch ( )
187
+ try ? process. run ( )
188
188
process. waitUntilExit ( )
189
189
XCTAssertEqual ( process. terminationStatus, 0 )
190
190
0 commit comments