Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ahk-lint-format-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ jobs:
run: choco install autohotkey.portable --version=1.1.36.01 -y
shell: pwsh
- name: Install AutoHotkey v2
run: choco install autohotkey -y
run: |
for ($i = 0; $i -lt 3; $i++) {
choco install autohotkey -y
if ($LASTEXITCODE -eq 0) { break }
Start-Sleep -Seconds 10
}
if ($LASTEXITCODE -ne 0) { exit 1 }
shell: pwsh
- name: Verify Installations
run: |
Expand Down
3 changes: 3 additions & 0 deletions Lib/v2/AHK_Common.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,16 @@ InitScript(requireUIA := true, requireAdmin := false, optimize := true) {
}

FindExe(name, fallbacks := []) {
if (name = "")
return ""
if FileExist(name)
return name
Loop Parse, EnvGet("PATH"), ";"
{
p := Trim(A_LoopField)
if !p
continue
p := RTrim(p, "\/")
cand := p . "\" . name
if FileExist(cand)
return cand
Expand Down
22 changes: 22 additions & 0 deletions tests/FindExe_Test.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ DirCreate(testBaseDir . "\PathDir1")
DirCreate(testBaseDir . "\PathDir2")
DirCreate(testBaseDir . "\FallbackDir")

DirCreate(testBaseDir . "\PathDir3")
DirCreate(testBaseDir . "\PathDir4")
FileAppend("", testBaseDir . "\PathDir3\tool_trailing.exe")
DirCreate(testBaseDir . "\PathDir4\subdir")
FileAppend("", testBaseDir . "\PathDir4\subdir\subtool.exe")


; Create dummy files
FileAppend("", testBaseDir . "\PathDir2\tool.exe")
FileAppend("", testBaseDir . "\FallbackDir\fbtool.exe")
Expand Down Expand Up @@ -59,6 +66,21 @@ try {
EnvSet("PATH", ";;" . mockPath . ";;")
AssertEqual(testBaseDir . "\PathDir2\tool.exe", FindExe("tool.exe"), "Should handle empty entries in PATH")


; Test 6: PATH entry with trailing backslash
EnvSet("PATH", testBaseDir . "\PathDir3\;" . mockPath)
AssertEqual(testBaseDir . "\PathDir3\tool_trailing.exe", FindExe("tool_trailing.exe"), "Should handle PATH entries with trailing backslashes")

; Test 7: Subdirectory path in name
EnvSet("PATH", mockPath . ";" . testBaseDir . "\PathDir4")
AssertEqual(testBaseDir . "\PathDir4\subdir\subtool.exe", FindExe("subdir\subtool.exe"), "Should resolve relative subdirectory paths in name")

; Test 8: Empty string name
AssertEqual("", FindExe(""), "Should return empty string for empty name")

; Test 9: Empty fallback array
AssertEqual("", FindExe("nonexistent.exe", []), "Should handle empty fallbacks array gracefully")

; Final Results
stdout.WriteLine("---")
stdout.WriteLine("Tests Passed: " . testsPassed)
Expand Down
Loading