Skip to content

Commit

Permalink
Minor behavioral fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevapple committed Dec 23, 2020
1 parent 556d422 commit e4cda47
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 4 additions & 1 deletion Sources/TSCBasic/Process.swift
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,10 @@ public final class Process: ObjectIdentifierProtocol {
searchPaths.append(AbsolutePath(String(decodingCString: buffer, as: UTF16.self)))

// The 16-bit Windows system directory
searchPaths.append(AbsolutePath("\(ProcessEnv.vars["systemdrive"] ?? "C:")\\System"))
if let systemDrive = ProcessEnv.vars["systemdrive"],
let systemPath = try? AbsolutePath(validating: "\(systemDrive))\\System") {
searchPaths.append(systemPath)
}

// The Windows directory
GetWindowsDirectoryW(&buffer, .init(MAX_PATH + 1))
Expand Down
2 changes: 1 addition & 1 deletion Sources/TSCBasic/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public func lookupExecutablePath(
guard var value = value, !value.isEmpty else {
return nil
}
let isPath = value.contains("\\")
let isPath = value.contains("\\") || value.contains("/")
if !isPath && !value.contains(".") {
value.append(executableFileSuffix)
}
Expand Down
20 changes: 9 additions & 11 deletions Tests/TSCBasicTests/ProcessTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,31 +103,29 @@ class ProcessTests: XCTestCase {
XCTAssertNil(Process.findExecutable("nonExistantProgram"))
XCTAssertNil(Process.findExecutable(""))

// Create a bat file to test.
let tempExecutable = tmpdir.appending(component: "program.bat")
try localFileSystem.writeFileContents(tempExecutable, bytes: """
@echo off
exit
""")
// Copy an executable file to test.
let tempExecutable = tmpdir.appending(component: "executableProgram.exe")
try localFileSystem.copy(from: Process.findExecutable("cmd")!, to: tempExecutable)

// Create a non-executable file to test.
let tempNonExecutable = tmpdir.appending(component: "program.bc")
let tempNonExecutable = tmpdir.appending(component: "program.bat")
try localFileSystem.writeFileContents(tempNonExecutable, bytes: """
@echo off
exit
""")

try withCustomEnv(["PATH": tmpdir.pathString]) {
XCTAssertNotNil(Process.findExecutable("program.bat"))
XCTAssertNil(Process.findExecutable("program.bc"))
XCTAssertNotNil(Process.findExecutable("executableProgram.exe"))
XCTAssertNotNil(Process.findExecutable("executableProgram"))
// Currently, Foundation treats all readable files as executable on Windows.
// XCTAssertNil(Process.findExecutable("program.bat"))
}
}
#endif
}

#if !os(Windows) // Foundation treats all readable files as executable on Windows.
#if !os(Windows) // Foundation treats all readable files as executable on Windows
func testNonExecutableLaunch() throws {
try testWithTemporaryDirectory { tmpdir in
// Create a local nonexecutable file to test.
Expand Down

0 comments on commit e4cda47

Please sign in to comment.