@@ -108,12 +108,13 @@ class ProcessTests: XCTestCase {
108
108
}
109
109
110
110
func testFindExecutable( ) throws {
111
+ #if !os(Windows)
111
112
try testWithTemporaryDirectory { tmpdir in
112
113
// This process should always work.
113
- XCTAssertTrue ( Process . findExecutable ( " ls " ) != nil )
114
+ XCTAssertNotNil ( Process . findExecutable ( " ls " ) )
114
115
115
- XCTAssertEqual ( Process . findExecutable ( " nonExistantProgram " ) , nil )
116
- XCTAssertEqual ( Process . findExecutable ( " " ) , nil )
116
+ XCTAssertNil ( Process . findExecutable ( " nonExistantProgram " ) )
117
+ XCTAssertNil ( Process . findExecutable ( " " ) )
117
118
118
119
// Create a local nonexecutable file to test.
119
120
let tempExecutable = tmpdir. appending ( component: " nonExecutableProgram " )
@@ -124,11 +125,37 @@ class ProcessTests: XCTestCase {
124
125
""" )
125
126
126
127
try withCustomEnv ( [ " PATH " : tmpdir. pathString] ) {
127
- XCTAssertEqual ( Process . findExecutable ( " nonExecutableProgram " ) , nil )
128
+ XCTAssertNil ( Process . findExecutable ( " nonExecutableProgram " ) )
128
129
}
129
130
}
131
+ #else
132
+ try testWithTemporaryDirectory { tmpdir in
133
+ // Test System32 without .exe suffix.
134
+ XCTAssertNotNil ( Process . findExecutable ( " cmd " ) )
135
+
136
+ // Test Windows with .exe suffix.
137
+ XCTAssertNotNil ( Process . findExecutable ( " explorer.exe " ) )
138
+
139
+ // Test non-existant programs.
140
+ XCTAssertNil ( Process . findExecutable ( " nonExistantProgram " ) )
141
+ XCTAssertNil ( Process . findExecutable ( " " ) )
142
+
143
+ // Create a bat file to test.
144
+ let tempExecutable = tmpdir. appending ( component: " program.bat " )
145
+ try localFileSystem. writeFileContents ( tempExecutable, bytes: """
146
+ @echo off
147
+ exit
148
+
149
+ """ )
150
+
151
+ try withCustomEnv ( [ " PATH " : tmpdir. pathString] ) {
152
+ XCTAssertNotNil ( Process . findExecutable ( " program.bat " ) )
153
+ }
154
+ }
155
+ #endif
130
156
}
131
157
158
+ #if !os(Windows) // Foundation treats all readable files as executable on Windows.
132
159
func testNonExecutableLaunch( ) throws {
133
160
try testWithTemporaryDirectory { tmpdir in
134
161
// Create a local nonexecutable file to test.
@@ -150,6 +177,7 @@ class ProcessTests: XCTestCase {
150
177
}
151
178
}
152
179
}
180
+ #endif
153
181
154
182
#if !os(Windows) // Signals are not supported in Windows
155
183
func testSignals( ) throws {
0 commit comments