diff --git a/.github/workflows/ahk-lint-format-compile.yml b/.github/workflows/ahk-lint-format-compile.yml index d6b76ab..35ebadf 100644 --- a/.github/workflows/ahk-lint-format-compile.yml +++ b/.github/workflows/ahk-lint-format-compile.yml @@ -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: | diff --git a/Lib/v2/AHK_Common.ahk b/Lib/v2/AHK_Common.ahk index 78055fa..d22efc0 100644 --- a/Lib/v2/AHK_Common.ahk +++ b/Lib/v2/AHK_Common.ahk @@ -48,6 +48,8 @@ InitScript(requireUIA := true, requireAdmin := false, optimize := true) { } FindExe(name, fallbacks := []) { + if (name = "") + return "" if FileExist(name) return name Loop Parse, EnvGet("PATH"), ";" @@ -55,6 +57,7 @@ FindExe(name, fallbacks := []) { p := Trim(A_LoopField) if !p continue + p := RTrim(p, "\/") cand := p . "\" . name if FileExist(cand) return cand diff --git a/tests/FindExe_Test.ahk b/tests/FindExe_Test.ahk index 0d02a0d..7aa4e48 100644 --- a/tests/FindExe_Test.ahk +++ b/tests/FindExe_Test.ahk @@ -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") @@ -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)