Skip to content

Commit da687f1

Browse files
committed
ui-tests: Move reusable functions into a library
These functions will be used in an upcoming test script to verify that Ctrl+C does what it is supposed to do. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 0bcd1c8 commit da687f1

File tree

2 files changed

+63
-60
lines changed

2 files changed

+63
-60
lines changed

ui-tests/background-hook.ahk

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#Requires AutoHotkey v2.0
2+
#Include ui-test-library.ahk
23

34
; This script is an integration test for the following scenario:
45
; A Git hook spawns a background process that outputs some text
@@ -10,50 +11,8 @@
1011
; This was fixed in the Cygwin/MSYS2 runtime, but then regressed again.
1112
; This test is meant to verify that the issue is fixed and remains so.
1213

13-
SetWorkTree() {
14-
global workTree
15-
; First, set the worktree path; This path will be reused
16-
; for the `.log` file).
17-
if A_Args.Length > 0
18-
workTree := A_Args[1]
19-
else
20-
{
21-
; Create a unique worktree path in the TEMP directory.
22-
workTree := EnvGet('TEMP') . '\git-test-background-hook'
23-
if FileExist(workTree)
24-
{
25-
counter := 0
26-
while FileExist(workTree '-' counter)
27-
counter++
28-
workTree := workTree '-' counter
29-
}
30-
}
31-
}
3214
SetWorkTree()
3315

34-
Info(text) {
35-
FileAppend text '`n', workTree '.log'
36-
}
37-
38-
closeWindow := false
39-
childPid := 0
40-
ExitWithError(error) {
41-
Info 'Error: ' error
42-
if closeWindow
43-
WinClose "A"
44-
else if childPid != 0
45-
ProcessClose childPid
46-
ExitApp 1
47-
}
48-
49-
RunWaitOne(command) {
50-
shell := ComObject("WScript.Shell")
51-
; Execute a single command via cmd.exe
52-
exec := shell.Exec(A_ComSpec " /C " command)
53-
; Read and return the command's output
54-
return exec.StdOut.ReadAll()
55-
}
56-
5716
SetWorkingDir(EnvGet('TEMP'))
5817
Info 'uname: ' RunWaitOne('uname -a')
5918
Info RunWaitOne('git version --build-options')
@@ -85,24 +44,6 @@ CloseWindow := true
8544
WinMove 0, 0
8645
Info 'Moved window to top left (so that the bottom is not cut off)'
8746

88-
CaptureTextFromWindowsTerminal() {
89-
ControlGetPos &cx, &cy, &cw, &ch, 'Windows.UI.Composition.DesktopWindowContentBridge1', "A"
90-
titleBarHeight := 54
91-
scrollBarWidth := 28
92-
pad := 8
93-
94-
SavedClipboard := ClipboardAll
95-
A_Clipboard := ''
96-
SendMode('Event')
97-
MouseMove cx + pad, cy + titleBarHeight + pad
98-
MouseClickDrag 'Left', , , cx + cw - scrollBarWidth, cy + ch - pad, , ''
99-
MouseClick 'Right'
100-
ClipWait()
101-
Result := A_Clipboard
102-
Clipboard := SavedClipboard
103-
return Result
104-
}
105-
10647
Info('Setting committer identity')
10748
Send('git config user.name Test{Enter}git config user.email [email protected]{Enter}')
10849

ui-tests/ui-test-library.ahk

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
; Reusable library functions for the UI tests.
2+
3+
SetWorkTree() {
4+
global workTree
5+
; First, set the worktree path; This path will be reused
6+
; for the `.log` file).
7+
if A_Args.Length > 0
8+
workTree := A_Args[1]
9+
else
10+
{
11+
; Create a unique worktree path in the TEMP directory.
12+
workTree := EnvGet('TEMP') . '\git-test-background-hook'
13+
if FileExist(workTree)
14+
{
15+
counter := 0
16+
while FileExist(workTree '-' counter)
17+
counter++
18+
workTree := workTree '-' counter
19+
}
20+
}
21+
}
22+
23+
Info(text) {
24+
FileAppend text '`n', workTree '.log'
25+
}
26+
27+
closeWindow := false
28+
childPid := 0
29+
ExitWithError(error) {
30+
Info 'Error: ' error
31+
if closeWindow
32+
WinClose "A"
33+
else if childPid != 0
34+
ProcessClose childPid
35+
ExitApp 1
36+
}
37+
38+
RunWaitOne(command) {
39+
shell := ComObject("WScript.Shell")
40+
; Execute a single command via cmd.exe
41+
exec := shell.Exec(A_ComSpec " /C " command)
42+
; Read and return the command's output
43+
return exec.StdOut.ReadAll()
44+
}
45+
46+
CaptureTextFromWindowsTerminal() {
47+
ControlGetPos &cx, &cy, &cw, &ch, 'Windows.UI.Composition.DesktopWindowContentBridge1', "A"
48+
titleBarHeight := 54
49+
scrollBarWidth := 28
50+
pad := 8
51+
52+
SavedClipboard := ClipboardAll
53+
A_Clipboard := ''
54+
SendMode('Event')
55+
MouseMove cx + pad, cy + titleBarHeight + pad
56+
MouseClickDrag 'Left', , , cx + cw - scrollBarWidth, cy + ch - pad, , ''
57+
MouseClick 'Right'
58+
ClipWait()
59+
Result := A_Clipboard
60+
Clipboard := SavedClipboard
61+
return Result
62+
}

0 commit comments

Comments
 (0)