Skip to content
Merged
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
16 changes: 14 additions & 2 deletions .github/workflows/ahk-lint-format-compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,22 @@ jobs:
- uses: actions/checkout@v6

- name: Install AutoHotkey v1.1 (Portable)
run: choco install autohotkey.portable --version=1.1.36.01 -y
run: |
for ($i=0; $i -lt 3; $i++) {
choco install autohotkey.portable --version=1.1.36.01 -y
if ($LASTEXITCODE -eq 0) { break }
Start-Sleep -Seconds 10
}
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
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 $LASTEXITCODE }
shell: pwsh
- name: Verify Installations
run: |
Expand Down
14 changes: 11 additions & 3 deletions Lib/v2/AHK_Common.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,20 @@ FindExe(name, fallbacks := []) {
return ""
}

MustGetExe(name, fallbacks := []) {
MustGetExe(name, fallbacks := [], mockMsgBox := "", mockExitApp := "") {
exe := FindExe(name, fallbacks)
if exe = ""
{
MsgBox("Required executable not found: " . name . "`nChecked PATH and fallbacks.")
ExitApp(1)
msg := "Required executable not found: " . name . "`nChecked PATH and fallbacks."
if mockMsgBox !== ""
mockMsgBox(msg)
else
MsgBox(msg)

if mockExitApp !== ""
mockExitApp(1)
else
ExitApp(1)
}
return exe
}
20 changes: 20 additions & 0 deletions tests/FindExe_Test.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,26 @@ try {
EnvSet("PATH", ";;" . mockPath . ";;")
AssertEqual(testBaseDir . "\PathDir2\tool.exe", FindExe("tool.exe"), "Should handle empty entries in PATH")

; MustGetExe Tests

; Test 6: MustGetExe success path
AssertEqual(directPath, MustGetExe(directPath), "MustGetExe should return path if found")

; Test 7: MustGetExe failure path
mockState := Map("msgBoxCalled", false, "exitAppCalled", false, "exitCode", "")

mockMsgBox := (msg) => (mockState["msgBoxCalled"] := true)
mockExitApp := (code) => (mockState["exitAppCalled"] := true, mockState["exitCode"] := code)

; Attempt to find a non-existent file with no fallbacks
try {
MustGetExe("definitely_nonexistent.exe", [], mockMsgBox, mockExitApp)
}

AssertEqual(1, mockState["msgBoxCalled"], "MustGetExe should call MsgBox on failure")
AssertEqual(1, mockState["exitAppCalled"], "MustGetExe should call ExitApp on failure")
AssertEqual(1, mockState["exitCode"], "MustGetExe should exit with code 1 on failure")

; Final Results
Comment on lines +70 to 82
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This block contains two syntax errors for AutoHotkey v2:

  1. Function definitions inside control flow: mockMsgBox and mockExitApp are defined using the function name() { ... } syntax inside a try block. In AHK v2, function definitions cannot be placed inside control flow statements.
  2. Invalid try block: The try block at line 80 lacks a corresponding catch or finally block, which is a requirement in AHK v2. Furthermore, since MustGetExe does not throw exceptions, the try block is unnecessary.

To fix this while keeping the logic within the test's execution flow, you can use anonymous functions (fat arrows) assigned to variables, which are allowed inside try blocks.

    mockMsgBox := (msg) => (mockState["msgBoxCalled"] := true)
    mockExitApp := (code) => (mockState["exitAppCalled"] := true, mockState["exitCode"] := code)

    ; Attempt to find a non-existent file with no fallbacks
    MustGetExe("definitely_nonexistent.exe", [], mockMsgBox, mockExitApp)

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