-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_screen_captures.sh
executable file
·159 lines (115 loc) · 2.82 KB
/
test_screen_captures.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
DEFAULT='\033[00m'
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
function SetupTestEnv
{
mkdir -p a/m/x a/m/y
for i in $(seq 1 120)
do
touch a/m/x/$i.txt
done
echo "broot is a file manager." > a/m/x/112.txt
}
BROOT_TMUX_SESSION="broot_test_$$"
BROOT_BINARY=broot
CAPTURE_DIR="/tmp/$$.BROOT.CAPTURES"
echo -e "$YELLOW Captures in $CAPTURE_DIR"
mkdir -p $CAPTURE_DIR
FAILURE=false
function capture_compare
{
echo -e "$YELLOW Test case $1 $DEFAULT"
CAPTURE_FILE="$CAPTURE_DIR/$1"
tmux capture-pane -p -e -t $BROOT_TMUX_SESSION > $CAPTURE_FILE
if ! diff --side-by-side --suppress-common-lines $CAPTURE_FILE master/$1
then
echo -e $RED "❌ $1"
FAILURE=true
else
echo -e $GREEN "✅ $1"
fi
echo -e "$DEFAULT"
}
function normalize_file_name()
{
INPUT="$1"
OUTPUT=${INPUT/$PWD/}
echo $OUTPUT
}
function clipboard_compare_file_name()
{
EXPECTED_CLIPBOARD_TEXT=$1
NORMALIZED=$(normalize_file_name $(xsel -b))
if [ "$NORMALIZED" = "$EXPECTED_CLIPBOARD_TEXT" ]
then
echo -e $GREEN "✅ Clipboard as expected: $1"
else
echo -e $RED "❌ Clipboard, got: $(xsel -b) expected (after normalization): $1"
FAILURE=true
fi
echo -e "$DEFAULT"
}
function SendKeysToTmuxSession
{
tmux send-keys -t $BROOT_TMUX_SESSION $@
sleep 0.5
}
function TestCopy
{
SendKeysToTmuxSession :copy_path ENTER
clipboard_compare_file_name "/a/m/x/34.txt"
SendKeysToTmuxSession DOWN DOWN ENTER
clipboard_compare_file_name "/a/m/x/36.txt"
SendKeysToTmuxSession ESCAPE
SendKeysToTmuxSession UP UP M-c
clipboard_compare_file_name "/a/m/x/98.txt"
}
tmux -u new-session -d -x 50 -y 50 -s $BROOT_TMUX_SESSION
trap "tmux kill-session -t $BROOT_TMUX_SESSION; exit" SIGINT SIGTERM
echo "Setting up test environment"
SetupTestEnv
echo "Starting tests"
# Initial View
SendKeysToTmuxSession 'unset' SPACE 'RPROMPT' ENTER
SendKeysToTmuxSession export SPACE PS1=$ ENTER
SendKeysToTmuxSession clear ENTER
SendKeysToTmuxSession $BROOT_BINARY ENTER
capture_compare initial
# Folder Pane, open
SendKeysToTmuxSession DOWN
SendKeysToTmuxSession DOWN
SendKeysToTmuxSession C-Right
capture_compare folder_pane_open
# Folder Pane, closed
SendKeysToTmuxSession Escape
capture_compare folder_pane_closed
# Fuzzy file search
SendKeysToTmuxSession 112
capture_compare file_fuzzy
# File contents
SendKeysToTmuxSession C-Right
capture_compare file_contents
SendKeysToTmuxSession Escape
SendKeysToTmuxSession Escape
# Page down
SendKeysToTmuxSession x
SendKeysToTmuxSession ENTER
SendKeysToTmuxSession PageDown
SendKeysToTmuxSession PageDown
capture_compare page_down
# Page up
SendKeysToTmuxSession PageUp
capture_compare page_up
# Copy
TestCopy
# Print path
SendKeysToTmuxSession :print_path ENTER
capture_compare print_path
sleep 2
tmux kill-session -t $BROOT_TMUX_SESSION
if $FAILURE
then
echo -e "$RED There were failures, see $CAPTURE_DIR"
fi
rm -rf a