@@ -289,21 +289,45 @@ class TestProcess : XCTestCase {
289
289
}
290
290
291
291
func test_run( ) {
292
+ let fm = FileManager . default
293
+ let cwd = fm. currentDirectoryPath
294
+
292
295
do {
293
296
let process = try Process . run ( URL ( fileURLWithPath: " /bin/sh " , isDirectory: false ) , arguments: [ " -c " , " exit 123 " ] , terminationHandler: nil )
294
297
process. waitUntilExit ( )
295
298
XCTAssertEqual ( process. terminationReason, . exit)
296
299
XCTAssertEqual ( process. terminationStatus, 123 )
297
300
} catch {
298
- XCTFail ( " Cant execute /bin/sh: error " )
301
+ XCTFail ( " Cant execute /bin/sh: \( error) " )
302
+ }
303
+ XCTAssertEqual ( fm. currentDirectoryPath, cwd)
304
+
305
+ do {
306
+ let process = Process ( )
307
+ process. executableURL = URL ( fileURLWithPath: " /bin/sh " , isDirectory: false )
308
+ process. arguments = [ " -c " , " exit 0 " ]
309
+ process. currentDirectoryURL = URL ( fileURLWithPath: " /.../_no_such_directory " , isDirectory: true )
310
+ try process. run ( )
311
+ XCTFail ( " Executed /bin/sh with invalid currentDirectoryURL " )
312
+ process. terminate ( )
313
+ process. waitUntilExit ( )
314
+ } catch {
299
315
}
316
+ XCTAssertEqual ( fm. currentDirectoryPath, cwd)
300
317
301
318
do {
302
- let process = try Process . run ( URL ( fileURLWithPath: " /.. " , isDirectory: false ) , arguments: [ ] , terminationHandler: nil )
319
+ let process = Process ( )
320
+ process. executableURL = URL ( fileURLWithPath: " /.. " , isDirectory: false )
321
+ process. arguments = [ ]
322
+ process. currentDirectoryURL = URL ( fileURLWithPath: " /tmp " )
323
+ try process. run ( )
303
324
XCTFail ( " Somehow executed a directory! " )
304
325
process. terminate ( )
326
+ process. waitUntilExit ( )
305
327
} catch {
306
328
}
329
+ XCTAssertEqual ( fm. currentDirectoryPath, cwd)
330
+ fm. changeCurrentDirectoryPath ( cwd)
307
331
}
308
332
309
333
#endif
0 commit comments