@@ -23,14 +23,19 @@ import func TSCBasic.withTemporaryFile
23
23
import func TSCTestSupport. withCustomEnv
24
24
25
25
final class AsyncProcessTests : XCTestCase {
26
+ #if os(Windows)
27
+ let executableExt = " .exe "
28
+ #else
29
+ let executableExt = " "
30
+ #endif
26
31
27
- override func setUp( ) async throws {
28
- try skipOnWindowsAsTestCurrentlyFails ( )
29
- }
30
-
31
32
func testBasics( ) throws {
33
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
34
+ threw error " missingExecutableProgram(program: " echo.exe " ) "
35
+ """ )
36
+
32
37
do {
33
- let process = AsyncProcess ( args: " echo " , " hello " )
38
+ let process = AsyncProcess ( args: " echo \( executableExt ) " , " hello " )
34
39
try process. launch ( )
35
40
let result = try process. waitUntilExit ( )
36
41
XCTAssertEqual ( try result. utf8Output ( ) , " hello \n " )
@@ -46,27 +51,26 @@ final class AsyncProcessTests: XCTestCase {
46
51
}
47
52
}
48
53
49
- func testPopen( ) throws {
50
- #if os(Windows)
51
- let echo = " echo.exe "
52
- #else
53
- let echo = " echo "
54
- #endif
54
+ func testPopenBasic( ) throws {
55
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
56
+ threw error " missingExecutableProgram(program: " echo.exe " ) "
57
+ """ )
58
+
55
59
// Test basic echo.
56
- XCTAssertEqual ( try AsyncProcess . popen ( arguments: [ echo, " hello " ] ) . utf8Output ( ) , " hello \n " )
60
+ XCTAssertEqual ( try AsyncProcess . popen ( arguments: [ " echo \( executableExt) " , " hello " ] ) . utf8Output ( ) , " hello \n " )
61
+ }
57
62
63
+ func testPopenWithBufferLargerThanAllocated( ) throws {
64
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
65
+ threw error " missingExecutableProgram(program: " cat.exe " ) "
66
+ """ )
58
67
// Test buffer larger than that allocated.
59
68
try withTemporaryFile { file in
60
69
let count = 10000
61
70
let stream = BufferedOutputByteStream ( )
62
71
stream. send ( Format . asRepeating ( string: " a " , count: count) )
63
72
try localFileSystem. writeFileContents ( file. path, bytes: stream. bytes)
64
- #if os(Windows)
65
- let cat = " cat.exe "
66
- #else
67
- let cat = " cat "
68
- #endif
69
- let outputCount = try AsyncProcess . popen ( args: cat, file. path. pathString) . utf8Output ( ) . count
73
+ let outputCount = try AsyncProcess . popen ( args: " cat \( executableExt) " , file. path. pathString) . utf8Output ( ) . count
70
74
XCTAssert ( outputCount == count)
71
75
}
72
76
}
@@ -119,8 +123,12 @@ final class AsyncProcessTests: XCTestCase {
119
123
}
120
124
121
125
func testCheckNonZeroExit( ) throws {
126
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
127
+ threw error " missingExecutableProgram(program: " echo.exe " ) "
128
+ """ )
129
+
122
130
do {
123
- let output = try AsyncProcess . checkNonZeroExit ( args: " echo " , " hello " )
131
+ let output = try AsyncProcess . checkNonZeroExit ( args: " echo \( executableExt ) " , " hello " )
124
132
XCTAssertEqual ( output, " hello \n " )
125
133
}
126
134
@@ -134,8 +142,12 @@ final class AsyncProcessTests: XCTestCase {
134
142
135
143
@available ( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * )
136
144
func testCheckNonZeroExitAsync( ) async throws {
145
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
146
+ threw error " missingExecutableProgram(program: " echo.exe " ) "
147
+ """ )
148
+
137
149
do {
138
- let output = try await AsyncProcess . checkNonZeroExit ( args: " echo " , " hello " )
150
+ let output = try await AsyncProcess . checkNonZeroExit ( args: " echo \( executableExt ) " , " hello " )
139
151
XCTAssertEqual ( output, " hello \n " )
140
152
}
141
153
@@ -148,6 +160,8 @@ final class AsyncProcessTests: XCTestCase {
148
160
}
149
161
150
162
func testFindExecutable( ) throws {
163
+ try skipOnWindowsAsTestCurrentlyFails ( because: " Assertion failure when trying to find ls executable " )
164
+
151
165
try testWithTemporaryDirectory { tmpdir in
152
166
// This process should always work.
153
167
XCTAssertTrue ( AsyncProcess . findExecutable ( " ls " ) != nil )
@@ -192,7 +206,11 @@ final class AsyncProcessTests: XCTestCase {
192
206
}
193
207
194
208
func testThreadSafetyOnWaitUntilExit( ) throws {
195
- let process = AsyncProcess ( args: " echo " , " hello " )
209
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
210
+ threw error " missingExecutableProgram(program: " echo.exe " ) "
211
+ """ )
212
+
213
+ let process = AsyncProcess ( args: " echo \( executableExt) " , " hello " )
196
214
try process. launch ( )
197
215
198
216
var result1 = " "
@@ -217,7 +235,11 @@ final class AsyncProcessTests: XCTestCase {
217
235
218
236
@available ( macOS 12 . 0 , iOS 15 . 0 , tvOS 15 . 0 , watchOS 8 . 0 , * )
219
237
func testThreadSafetyOnWaitUntilExitAsync( ) async throws {
220
- let process = AsyncProcess ( args: " echo " , " hello " )
238
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
239
+ threw error " missingExecutableProgram(program: " echo.exe " ) "
240
+ """ )
241
+
242
+ let process = AsyncProcess ( args: " echo \( executableExt) " , " hello " )
221
243
try process. launch ( )
222
244
223
245
let t1 = Task {
@@ -236,6 +258,10 @@ final class AsyncProcessTests: XCTestCase {
236
258
}
237
259
238
260
func testStdin( ) throws {
261
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
262
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
263
+ """ )
264
+
239
265
var stdout = [ UInt8] ( )
240
266
let process = AsyncProcess ( scriptName: " in-to-out " , outputRedirection: . stream( stdout: { stdoutBytes in
241
267
stdout += stdoutBytes
@@ -253,6 +279,10 @@ final class AsyncProcessTests: XCTestCase {
253
279
}
254
280
255
281
func testStdoutStdErr( ) throws {
282
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
283
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
284
+ """ )
285
+
256
286
// A simple script to check that stdout and stderr are captured separatly.
257
287
do {
258
288
let result = try AsyncProcess . popen ( scriptName: " simple-stdout-stderr " )
@@ -279,6 +309,10 @@ final class AsyncProcessTests: XCTestCase {
279
309
280
310
@available ( macOS 10 . 15 , iOS 13 . 0 , tvOS 13 . 0 , watchOS 6 . 0 , * )
281
311
func testStdoutStdErrAsync( ) async throws {
312
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
313
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
314
+ """ )
315
+
282
316
// A simple script to check that stdout and stderr are captured separatly.
283
317
do {
284
318
let result = try await AsyncProcess . popen ( scriptName: " simple-stdout-stderr " )
@@ -304,6 +338,10 @@ final class AsyncProcessTests: XCTestCase {
304
338
}
305
339
306
340
func testStdoutStdErrRedirected( ) throws {
341
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
342
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
343
+ """ )
344
+
307
345
// A simple script to check that stdout and stderr are captured in the same location.
308
346
do {
309
347
let process = AsyncProcess (
@@ -332,6 +370,10 @@ final class AsyncProcessTests: XCTestCase {
332
370
}
333
371
334
372
func testStdoutStdErrStreaming( ) throws {
373
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
374
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
375
+ """ )
376
+
335
377
var stdout = [ UInt8] ( )
336
378
var stderr = [ UInt8] ( )
337
379
let process = AsyncProcess ( scriptName: " long-stdout-stderr " , outputRedirection: . stream( stdout: { stdoutBytes in
@@ -348,6 +390,10 @@ final class AsyncProcessTests: XCTestCase {
348
390
}
349
391
350
392
func testStdoutStdErrStreamingRedirected( ) throws {
393
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
394
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
395
+ """ )
396
+
351
397
var stdout = [ UInt8] ( )
352
398
var stderr = [ UInt8] ( )
353
399
let process = AsyncProcess ( scriptName: " long-stdout-stderr " , outputRedirection: . stream( stdout: { stdoutBytes in
@@ -364,6 +410,10 @@ final class AsyncProcessTests: XCTestCase {
364
410
}
365
411
366
412
func testWorkingDirectory( ) throws {
413
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
414
+ threw error " missingExecutableProgram(program: " cat.exe " ) "
415
+ """ )
416
+
367
417
guard #available( macOS 10 . 15 , * ) else {
368
418
// Skip this test since it's not supported in this OS.
369
419
return
@@ -385,7 +435,7 @@ final class AsyncProcessTests: XCTestCase {
385
435
try localFileSystem. writeFileContents ( childPath, bytes: ByteString ( " child " ) )
386
436
387
437
do {
388
- let process = AsyncProcess ( arguments: [ " cat " , " file " ] , workingDirectory: tempDirPath)
438
+ let process = AsyncProcess ( arguments: [ " cat \( executableExt ) " , " file " ] , workingDirectory: tempDirPath)
389
439
try process. launch ( )
390
440
let result = try process. waitUntilExit ( )
391
441
XCTAssertEqual ( try result. utf8Output ( ) , " parent " )
@@ -403,12 +453,15 @@ final class AsyncProcessTests: XCTestCase {
403
453
func testAsyncStream( ) async throws {
404
454
// rdar://133548796
405
455
try XCTSkipIfCI ( )
456
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
457
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
458
+ """ )
406
459
407
460
let ( stdoutStream, stdoutContinuation) = AsyncProcess . ReadableStream. makeStream ( )
408
461
let ( stderrStream, stderrContinuation) = AsyncProcess . ReadableStream. makeStream ( )
409
462
410
463
let process = AsyncProcess (
411
- scriptName: " echo " ,
464
+ scriptName: " echo \( executableExt ) " ,
412
465
outputRedirection: . stream {
413
466
stdoutContinuation. yield ( $0)
414
467
} stderr: {
@@ -460,9 +513,12 @@ final class AsyncProcessTests: XCTestCase {
460
513
func testAsyncStreamHighLevelAPI( ) async throws {
461
514
// rdar://133548796
462
515
try XCTSkipIfCI ( )
516
+ try skipOnWindowsAsTestCurrentlyFails ( because: """
517
+ threw error " Error Domain=NSCocoaErrorDomain Code=3584 " (null) " UserInfo={NSUnderlyingError=Error Domain=org.swift.Foundation.WindowsError Code=193 " (null) " } "
518
+ """ )
463
519
464
520
let result = try await AsyncProcess . popen (
465
- scriptName: " echo " ,
521
+ scriptName: " echo \( executableExt ) " ,
466
522
stdout: { stdin, stdout in
467
523
var counter = 0
468
524
stdin. write ( " Hello \( counter) \n " )
0 commit comments