Skip to content

Commit 442014d

Browse files
committed
ui-tests: move code to wait for text in the Windows Terminal into a function
This code is way too useful _not_ to make it reusable. While at it, improve on the timeout logic to be quite a bit more precise. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 9bbd0b6 commit 442014d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

ui-tests/background-hook.ahk

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ Send('git config user.name Test{Enter}git config user.email [email protected]{Enter}')
3838
Info('Committing')
3939
Send('git commit --allow-empty -m zOMG{Enter}')
4040
; Wait for the hook to finish printing
41-
While not RegExMatch(CaptureTextFromWindowsTerminal(), '`n49$')
42-
{
43-
Sleep 100
44-
if A_Index > 1000
45-
ExitWithError 'Timed out waiting for commit to finish'
46-
MouseClick 'WheelDown', , , 20
47-
}
48-
Info('Hook finished')
41+
WaitForRegExInWindowsTerminal('`n49$', 'Timed out waiting for commit to finish', 'Hook finished', 100000)
4942

5043
; Verify that CursorUp shows the previous command
5144
Send('{Up}')

ui-tests/ui-test-library.ahk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,17 @@ CaptureTextFromWindowsTerminal() {
8989
Result := A_Clipboard
9090
Clipboard := SavedClipboard
9191
return Result
92+
}
93+
94+
WaitForRegExInWindowsTerminal(regex, errorMessage, successMessage, timeout := 5000) {
95+
timeout := timeout + A_TickCount
96+
; Wait for the regex to match in the terminal output
97+
while not RegExMatch(CaptureTextFromWindowsTerminal(), regex)
98+
{
99+
Sleep 100
100+
if A_TickCount > timeout
101+
ExitWithError errorMessage
102+
MouseClick 'WheelDown', , , 20
103+
}
104+
Info(successMessage)
92105
}

0 commit comments

Comments
 (0)