@@ -108,12 +108,13 @@ class ProcessTests: XCTestCase {
108108 }
109109
110110 func testFindExecutable( ) throws {
111+ #if !os(Windows)
111112 try testWithTemporaryDirectory { tmpdir in
112113 // This process should always work.
113- XCTAssertTrue ( Process . findExecutable ( " ls " ) != nil )
114+ XCTAssertNotNil ( Process . findExecutable ( " ls " ) )
114115
115- XCTAssertEqual ( Process . findExecutable ( " nonExistantProgram " ) , nil )
116- XCTAssertEqual ( Process . findExecutable ( " " ) , nil )
116+ XCTAssertNil ( Process . findExecutable ( " nonExistantProgram " ) )
117+ XCTAssertNil ( Process . findExecutable ( " " ) )
117118
118119 // Create a local nonexecutable file to test.
119120 let tempExecutable = tmpdir. appending ( component: " nonExecutableProgram " )
@@ -124,11 +125,37 @@ class ProcessTests: XCTestCase {
124125 """ )
125126
126127 try withCustomEnv ( [ " PATH " : tmpdir. pathString] ) {
127- XCTAssertEqual ( Process . findExecutable ( " nonExecutableProgram " ) , nil )
128+ XCTAssertNil ( Process . findExecutable ( " nonExecutableProgram " ) )
128129 }
129130 }
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
130156 }
131157
158+ #if !os(Windows) // Foundation treats all readable files as executable on Windows.
132159 func testNonExecutableLaunch( ) throws {
133160 try testWithTemporaryDirectory { tmpdir in
134161 // Create a local nonexecutable file to test.
@@ -150,6 +177,7 @@ class ProcessTests: XCTestCase {
150177 }
151178 }
152179 }
180+ #endif
153181
154182 #if !os(Windows) // Signals are not supported in Windows
155183 func testSignals( ) throws {
0 commit comments