@@ -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,9 +125,40 @@ 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
+ // 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
130
162
}
131
163
132
164
func testNonExecutableLaunch( ) throws {
0 commit comments