Skip to content

Commit f96752c

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 c0252a4 commit f96752c

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

ui-tests/ctrl-c.ahk

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
Send('git -c alias.sleep="{!}/usr/bin/sleep" sleep 15{Enter}')
33+
Sleep 50
34+
Send('^C') ; interrupt sleep
35+
Sleep 150
36+
; Wait for the `^C` tell-tale that is the PowerShell prompt to appear
37+
WaitForRegExInWindowsTerminal('>[ `n`r]*$', 'Timed out waiting for interrupt', 'Sleep was interrupted as desired')
38+
39+
Send('exit{Enter}')
40+
Sleep 50
41+
CleanUpWorkTree()

0 commit comments

Comments
 (0)