@@ -71,12 +71,13 @@ class ProcessTests: XCTestCase {
7171 }
7272
7373 func testFindExecutable( ) throws {
74+ #if !os(Windows)
7475 try testWithTemporaryDirectory { tmpdir in
7576 // This process should always work.
76- XCTAssertTrue ( Process . findExecutable ( " ls " ) != nil )
77+ XCTAssertNotNil ( Process . findExecutable ( " ls " ) )
7778
78- XCTAssertEqual ( Process . findExecutable ( " nonExistantProgram " ) , nil )
79- XCTAssertEqual ( Process . findExecutable ( " " ) , nil )
79+ XCTAssertNil ( Process . findExecutable ( " nonExistantProgram " ) )
80+ XCTAssertNil ( Process . findExecutable ( " " ) )
8081
8182 // Create a local nonexecutable file to test.
8283 let tempExecutable = tmpdir. appending ( component: " nonExecutableProgram " )
@@ -87,11 +88,37 @@ class ProcessTests: XCTestCase {
8788 """ )
8889
8990 try withCustomEnv ( [ " PATH " : tmpdir. pathString] ) {
90- XCTAssertEqual ( Process . findExecutable ( " nonExecutableProgram " ) , nil )
91+ XCTAssertNil ( Process . findExecutable ( " nonExecutableProgram " ) )
9192 }
9293 }
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
93119 }
94120
121+ #if !os(Windows) // Foundation treats all readable files as executable on Windows.
95122 func testNonExecutableLaunch( ) throws {
96123 try testWithTemporaryDirectory { tmpdir in
97124 // Create a local nonexecutable file to test.
@@ -113,6 +140,7 @@ class ProcessTests: XCTestCase {
113140 }
114141 }
115142 }
143+ #endif
116144
117145 #if !os(Windows) // Signals are not supported in Windows
118146 func testSignals( ) throws {
0 commit comments