@@ -333,15 +333,26 @@ class TestProcess : XCTestCase {
333
333
XCTAssertEqual ( fm. currentDirectoryPath, cwd)
334
334
335
335
do {
336
+ // Check running the process twice throws an error.
336
337
let process = Process ( )
337
338
process. executableURL = xdgTestHelperURL ( )
338
339
process. arguments = [ " --exit " , " 0 " ]
339
- process. currentDirectoryURL = URL ( fileURLWithPath: " /.../_no_such_directory " , isDirectory: true )
340
- try process. run ( )
341
- XCTFail ( " Executed \( xdgTestHelperURL ( ) . path) with invalid currentDirectoryURL " )
342
- process. terminate ( )
340
+ XCTAssertNoThrow ( try process. run ( ) )
343
341
process. waitUntilExit ( )
344
- } catch {
342
+ XCTAssertThrowsError ( try process. run ( ) ) {
343
+ let nserror = ( $0 as! NSError )
344
+ XCTAssertEqual ( nserror. domain, NSCocoaErrorDomain)
345
+ let code = CocoaError ( _nsError: nserror) . code
346
+ XCTAssertEqual ( code, . executableLoad)
347
+ }
348
+ }
349
+
350
+ do {
351
+ let process = Process ( )
352
+ process. executableURL = xdgTestHelperURL ( )
353
+ process. arguments = [ " --exit " , " 0 " ]
354
+ process. currentDirectoryURL = URL ( fileURLWithPath: " /.../_no_such_directory " , isDirectory: true )
355
+ XCTAssertThrowsError ( try process. run ( ) )
345
356
}
346
357
XCTAssertEqual ( fm. currentDirectoryPath, cwd)
347
358
@@ -350,11 +361,7 @@ class TestProcess : XCTestCase {
350
361
process. executableURL = URL ( fileURLWithPath: " /.. " , isDirectory: false )
351
362
process. arguments = [ ]
352
363
process. currentDirectoryURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
353
- try process. run ( )
354
- XCTFail ( " Somehow executed a directory! " )
355
- process. terminate ( )
356
- process. waitUntilExit ( )
357
- } catch {
364
+ XCTAssertThrowsError ( try process. run ( ) )
358
365
}
359
366
XCTAssertEqual ( fm. currentDirectoryPath, cwd)
360
367
fm. changeCurrentDirectoryPath ( cwd)
0 commit comments