Skip to content

Commit f33e06e

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 0ec7803 commit f33e06e

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

.github/workflows/ui-tests.yml

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

ui-tests/ctrl-c.ahk

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 150
35+
; interrupt sleep; Ideally we'd call `Send('^C')` but that would too quick on GitHub Actions' runners.
36+
Send '{Ctrl down}{c down}'
37+
Sleep 50
38+
Send '{c up}{Ctrl up}'
39+
Sleep 150
40+
; Wait for the `^C` tell-tale that is the PowerShell prompt to appear
41+
WaitForRegExInWindowsTerminal('>[ `n`r]*$', 'Timed out waiting for interrupt', 'Sleep was interrupted as desired')
42+
43+
Send('exit{Enter}')
44+
Sleep 50
45+
CleanUpWorkTree()

0 commit comments

Comments
 (0)