Skip to content

Commit c92fe4f

Browse files
committed
ui-tests: verify that a sleep in Windows Terminal can be interrupted
The Ctrl+C way to interrupt run-away processes is highly important. It was recently broken in multiple ways in the Cygwin runtime (and hence also in the MSYS2 runtime). Let's add some integration tests that will catch regressions. It is admittedly less than ideal to add _integration_ tests; While imitating exactly what the end user does looks appealing at first, excellent tests impress by how quickly they allow regressions not only to be identified but also to be fixed. Even worse: all integration tests, by virtue of working in a broader environment than, say, unit tests, incur the price of sometimes catching unactionable bugs, i.e. bugs in software that is both outside of our control as well as not the target of our testing at all. Nevertheless, seeing as Cygwin did not add any unit tests for those Ctrl+C fixes (which is understandable, given how complex testing for Ctrl+C without UI testing would be), it is better to have integration tests than no tests at all. So here goes: This commit introduces a test that verifies that the MSYS2 `sleep.exe` can be interrupted when run from PowerShell in a Windows Terminal. This was broken in v3.6.0 and fixed in 7674c51 (Cygwin: console: Set ENABLE_PROCESSED_INPUT when disable_master_thread, 2025-07-01). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c291070 commit c92fe4f

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

.github/workflows/ui-tests.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,16 @@ jobs:
9090
& "${env:RUNNER_TEMP}\ahk\AutoHotKey64.exe" /ErrorStdOut /force background-hook.ahk "$PWD\bg-hook" 2>&1 | Out-Default
9191
if (!$?) { $exitCode = 1; echo "::error::Test failed!" } else { echo "::notice::Test log" }
9292
type bg-hook.log
93+
& "${env:RUNNER_TEMP}\ahk\AutoHotKey64.exe" /ErrorStdOut /force ctrl-c.ahk "$PWD\ctrl-c" 2>&1 | Out-Default
94+
if (!$?) { $exitCode = 1; echo "::error::Ctrl+C Test failed!" } else { echo "::notice::Ctrl+C Test log" }
95+
type ctrl-c.log
9396
exit $exitCode
9497
- name: Show logs
9598
if: always()
9699
working-directory: ui-tests
97-
run: type bg-hook.log
100+
run: |
101+
type bg-hook.log
102+
type ctrl-c.log
98103
- name: Take screenshot, if canceled
99104
id: take-screenshot
100105
if: cancelled() || failure()

ui-tests/ctrl-c.ahk

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#Requires AutoHotkey v2.0
2+
#Include ui-test-library.ahk
3+
4+
SetWorkTree('git-test-ctrl-c')
5+
6+
powerShellPath := EnvGet('SystemRoot') . '\System32\WindowsPowerShell\v1.0\powershell.exe'
7+
Run 'wt.exe -d . "' powerShellPath '"', , , &childPid
8+
if A_LastError
9+
ExitWithError 'Error launching PowerShell: ' A_LastError
10+
Info 'Launched PowerShell: ' childPid
11+
; Sadly, `WinWait('ahk_pid ' childPid)` does not work because the Windows Terminal window seems
12+
; to be owned by the `wt.exe` process that launched.
13+
;
14+
; Probably should use the trick mentioned in
15+
; https://www.autohotkey.com/boards/viewtopic.php?p=580081&sid=a40d0ce73efff728ffa6b4573dff07b9#p580081
16+
; where the `before` variable is assigned `WinGetList(winTitle).Length` before the `Run` command,
17+
; and a `Loop` is used to wait until [`WinGetList()`](https://www.autohotkey.com/docs/v2/lib/WinGetList.htm)
18+
; returns a different length, in which case the first array element is the new window.
19+
;
20+
; Also: This is crying out loud to be refactored into a function and then also used in `background-hook.ahk`!
21+
hwnd := WinWait(powerShellPath, , 9)
22+
if not hwnd
23+
ExitWithError 'PowerShell window did not appear'
24+
Info 'Got window'
25+
WinActivate
26+
CloseWindow := true
27+
WinMove 0, 0
28+
Info 'Moved window to top left (so that the bottom is not cut off)'
29+
30+
; sleep test
31+
Sleep 1500
32+
; The `:;` is needed to force Git to call this via the shell, otherwise `/usr/bin/` would not resolve.
33+
Send('git -c alias.sleep="{!}:;/usr/bin/sleep" sleep 15{Enter}')
34+
Sleep 500
35+
; interrupt sleep; Ideally we'd call `Send('^C')` but that would too quick on GitHub Actions' runners.
36+
; The idea for this work-around comes from https://www.reddit.com/r/AutoHotkey/comments/aok10s/comment/eg57e81/.
37+
Send '{Ctrl down}{c down}'
38+
Sleep 50
39+
Send '{c up}{Ctrl up}'
40+
Sleep 150
41+
; Wait for the `^C` tell-tale that is the PowerShell prompt to appear
42+
WaitForRegExInWindowsTerminal('>[ `n`r]*$', 'Timed out waiting for interrupt', 'Sleep was interrupted as desired')
43+
44+
Send('exit{Enter}')
45+
Sleep 50
46+
CleanUpWorkTree()

0 commit comments

Comments
 (0)