@@ -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,9 +125,40 @@ 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+ // Copy an executable file to test.
144+ let tempExecutable = tmpdir. appending ( component: " executableProgram.exe " )
145+ try localFileSystem. copy ( from: Process . findExecutable ( " cmd " ) !, to: tempExecutable)
146+
147+ // Create a non-executable file to test.
148+ let tempNonExecutable = tmpdir. appending ( component: " program.bat " )
149+ try localFileSystem. writeFileContents ( tempNonExecutable, bytes: """
150+ @echo off
151+ exit
152+
153+ """ )
154+
155+ try withCustomEnv ( [ " Path " : tmpdir. pathString] ) {
156+ XCTAssertNotNil ( Process . findExecutable ( " executableProgram.exe " ) )
157+ XCTAssertNotNil ( Process . findExecutable ( " executableProgram " ) )
158+ XCTAssertNil ( Process . findExecutable ( " program.bat " ) )
159+ }
160+ }
161+ #endif
130162 }
131163
132164 func testNonExecutableLaunch( ) throws {
0 commit comments