@@ -71,12 +71,13 @@ class ProcessTests: XCTestCase {
71
71
}
72
72
73
73
func testFindExecutable( ) throws {
74
+ #if !os(Windows)
74
75
try testWithTemporaryDirectory { tmpdir in
75
76
// This process should always work.
76
- XCTAssertTrue ( Process . findExecutable ( " ls " ) != nil )
77
+ XCTAssertNotNil ( Process . findExecutable ( " ls " ) )
77
78
78
- XCTAssertEqual ( Process . findExecutable ( " nonExistantProgram " ) , nil )
79
- XCTAssertEqual ( Process . findExecutable ( " " ) , nil )
79
+ XCTAssertNil ( Process . findExecutable ( " nonExistantProgram " ) )
80
+ XCTAssertNil ( Process . findExecutable ( " " ) )
80
81
81
82
// Create a local nonexecutable file to test.
82
83
let tempExecutable = tmpdir. appending ( component: " nonExecutableProgram " )
@@ -87,11 +88,37 @@ class ProcessTests: XCTestCase {
87
88
""" )
88
89
89
90
try withCustomEnv ( [ " PATH " : tmpdir. pathString] ) {
90
- XCTAssertEqual ( Process . findExecutable ( " nonExecutableProgram " ) , nil )
91
+ XCTAssertNil ( Process . findExecutable ( " nonExecutableProgram " ) )
91
92
}
92
93
}
94
+ #else
95
+ try testWithTemporaryDirectory { tmpdir in
96
+ // Test System32 without .exe suffix.
97
+ XCTAssertNotNil ( Process . findExecutable ( " cmd " ) )
98
+
99
+ // Test Windows with .exe suffix.
100
+ XCTAssertNotNil ( Process . findExecutable ( " explorer.exe " ) )
101
+
102
+ // Test non-existant programs.
103
+ XCTAssertNil ( Process . findExecutable ( " nonExistantProgram " ) )
104
+ XCTAssertNil ( Process . findExecutable ( " " ) )
105
+
106
+ // Create a bat file to test.
107
+ let tempExecutable = tmpdir. appending ( component: " program.bat " )
108
+ try localFileSystem. writeFileContents ( tempExecutable, bytes: """
109
+ @echo off
110
+ exit
111
+
112
+ """ )
113
+
114
+ try withCustomEnv ( [ " PATH " : tmpdir. pathString] ) {
115
+ XCTAssertNotNil ( Process . findExecutable ( " program.bat " ) )
116
+ }
117
+ }
118
+ #endif
93
119
}
94
120
121
+ #if !os(Windows) // Foundation treats all readable files as executable on Windows.
95
122
func testNonExecutableLaunch( ) throws {
96
123
try testWithTemporaryDirectory { tmpdir in
97
124
// Create a local nonexecutable file to test.
@@ -113,6 +140,7 @@ class ProcessTests: XCTestCase {
113
140
}
114
141
}
115
142
}
143
+ #endif
116
144
117
145
#if !os(Windows) // Signals are not supported in Windows
118
146
func testSignals( ) throws {
0 commit comments