@@ -116,7 +116,8 @@ class TestProcess : XCTestCase {
116
116
XCTFail ( " Could not read stdout " )
117
117
return
118
118
}
119
- XCTAssertEqual ( string. trimmingCharacters ( in: CharacterSet ( [ " \n " ] ) ) , FileManager . default. currentDirectoryPath)
119
+
120
+ XCTAssertEqual ( string. trimmingCharacters ( in: CharacterSet ( [ " \n " , " \r " ] ) ) , FileManager . default. currentDirectoryPath)
120
121
}
121
122
122
123
func test_pipe_stderr( ) throws {
@@ -194,7 +195,7 @@ class TestProcess : XCTestCase {
194
195
XCTFail ( " Could not read stdout " )
195
196
return
196
197
}
197
- XCTAssertEqual ( string. trimmingCharacters ( in: CharacterSet ( [ " \n " ] ) ) , FileManager . default. currentDirectoryPath)
198
+ XCTAssertEqual ( string. trimmingCharacters ( in: CharacterSet ( [ " \r " , " \ n" ] ) ) , FileManager . default. currentDirectoryPath)
198
199
}
199
200
200
201
func test_passthrough_environment( ) {
@@ -213,7 +214,12 @@ class TestProcess : XCTestCase {
213
214
do {
214
215
let ( output, _) = try runTask ( [ xdgTestHelperURL ( ) . path, " --env " ] , environment: [ : ] )
215
216
let env = try parseEnv ( output)
217
+ #if os(Windows)
218
+ // On Windows, Path is always passed to the sub process
219
+ XCTAssertEqual ( env. count, 1 )
220
+ #else
216
221
XCTAssertEqual ( env. count, 0 )
222
+ #endif
217
223
} catch {
218
224
XCTFail ( " Test failed: \( error) " )
219
225
}
@@ -223,15 +229,23 @@ class TestProcess : XCTestCase {
223
229
do {
224
230
let input = [ " HELLO " : " WORLD " , " HOME " : " CUPERTINO " ]
225
231
let ( output, _) = try runTask ( [ xdgTestHelperURL ( ) . path, " --env " ] , environment: input)
226
- let env = try parseEnv ( output)
232
+ var env = try parseEnv ( output)
233
+ #if os(Windows)
234
+ // On Windows, Path is always passed to the sub process, remove it
235
+ // before comparing.
236
+ env. removeValue ( forKey: " Path " )
237
+ #endif
227
238
XCTAssertEqual ( env, input)
228
239
} catch {
229
240
XCTFail ( " Test failed: \( error) " )
230
241
}
231
242
}
232
243
233
- func test_current_working_directory( ) {
234
- let tmpDir = " /tmp " //.standardizingPath
244
+ func test_current_working_directory( ) throws {
245
+ var tmpDir = NSTemporaryDirectory ( )
246
+ if let lastChar = tmpDir. last, lastChar == " / " || lastChar == " \\ " {
247
+ tmpDir. removeLast ( )
248
+ }
235
249
236
250
let fm = FileManager . default
237
251
let previousWorkingDirectory = fm. currentDirectoryPath
@@ -310,7 +324,7 @@ class TestProcess : XCTestCase {
310
324
let process = Process ( )
311
325
process. executableURL = URL ( fileURLWithPath: " /.. " , isDirectory: false )
312
326
process. arguments = [ ]
313
- process. currentDirectoryURL = URL ( fileURLWithPath: " /tmp " )
327
+ process. currentDirectoryURL = URL ( fileURLWithPath: NSTemporaryDirectory ( ) )
314
328
try process. run ( )
315
329
XCTFail ( " Somehow executed a directory! " )
316
330
process. terminate ( )
@@ -537,12 +551,12 @@ class TestProcess : XCTestCase {
537
551
if let d = try stdoutPipe. fileHandleForReading. readToEnd ( ) {
538
552
stdoutData. append ( d)
539
553
}
540
- XCTAssertEqual ( String ( data: stdoutData, encoding: . utf8) , " No files specified. \n " )
554
+ XCTAssertEqual ( String ( data: stdoutData, encoding: . utf8) ? . trimmingCharacters ( in : . whitespacesAndNewlines ) , " No files specified. " )
541
555
}
542
556
543
557
544
558
static var allTests : [ ( String , ( TestProcess ) -> ( ) throws -> Void ) ] {
545
- return [
559
+ var tests = [
546
560
( " test_exit0 " , test_exit0) ,
547
561
( " test_exit1 " , test_exit1) ,
548
562
( " test_exit100 " , test_exit100) ,
@@ -559,9 +573,7 @@ class TestProcess : XCTestCase {
559
573
( " test_custom_environment " , test_custom_environment) ,
560
574
( " test_run " , test_run) ,
561
575
( " test_preStartEndState " , test_preStartEndState) ,
562
- ( " test_interrupt " , test_interrupt) ,
563
576
( " test_terminate " , test_terminate) ,
564
- ( " test_suspend_resume " , test_suspend_resume) ,
565
577
( " test_redirect_stdin_using_null " , test_redirect_stdin_using_null) ,
566
578
( " test_redirect_stdout_using_null " , test_redirect_stdout_using_null) ,
567
579
( " test_redirect_stdin_stdout_using_null " , test_redirect_stdin_stdout_using_null) ,
@@ -570,6 +582,15 @@ class TestProcess : XCTestCase {
570
582
( " test_redirect_all_using_nil " , test_redirect_all_using_nil) ,
571
583
( " test_plutil " , test_plutil) ,
572
584
]
585
+
586
+ #if !os(Windows)
587
+ // Windows doesn't have signals
588
+ tests += [
589
+ ( " test_interrupt " , test_interrupt) ,
590
+ ( " test_suspend_resume " , test_suspend_resume) ,
591
+ ]
592
+ #endif
593
+ return tests
573
594
}
574
595
}
575
596
@@ -726,7 +747,7 @@ internal func runTask(_ arguments: [String], environment: [String: String]? = ni
726
747
727
748
private func parseEnv( _ env: String ) throws -> [ String : String ] {
728
749
var result = [ String: String] ( )
729
- for line in env. components ( separatedBy: " \n " ) where line != " " {
750
+ for line in env. components ( separatedBy: . newlines ) where line != " " {
730
751
guard let range = line. range ( of: " = " ) else {
731
752
throw Error . InvalidEnvironmentVariable ( line)
732
753
}
0 commit comments