Bash · 10599 bytes Raw Blame History
1 #!/usr/bin/env bash
2 # ==============================================================================
3 # Interactive Terminal Tests for fortsh
4 # Tests features that require real terminal interaction
5 # ==============================================================================
6
7 set -euo pipefail
8
9 # Colors
10 RED='\033[0;31m'
11 GREEN='\033[0;32m'
12 YELLOW='\033[1;33m'
13 BLUE='\033[0;34m'
14 CYAN='\033[0;36m'
15 BOLD='\033[1m'
16 RESET='\033[0m'
17
18 FORTSH="${FORTSH:-./bin/fortsh}"
19
20 if [[ ! -x "$FORTSH" ]]; then
21 echo -e "${RED}Error: fortsh binary not found at $FORTSH${RESET}"
22 exit 1
23 fi
24
25 echo -e "${BOLD}${CYAN}"
26 echo "╔══════════════════════════════════════════════════════════════╗"
27 echo "║ Interactive Terminal Tests for fortsh ║"
28 echo "║ (Manual verification required) ║"
29 echo "╚══════════════════════════════════════════════════════════════╝"
30 echo -e "${RESET}\n"
31
32 prompt_user() {
33 local message="$1"
34 echo -e "${YELLOW}${message}${RESET}"
35 read -p "Press Enter to continue..."
36 }
37
38 test_section() {
39 local title="$1"
40 echo -e "\n${BOLD}${CYAN}═══ $title ═══${RESET}\n"
41 }
42
43 # ==============================================================================
44 # Test 1: Bracketed Paste Mode
45 # ==============================================================================
46
47 test_bracketed_paste() {
48 test_section "Test 1: Bracketed Paste Mode"
49
50 cat <<EOF
51 ${BOLD}This test verifies that multi-line paste doesn't execute immediately.${RESET}
52
53 Instructions:
54 1. fortsh will start in interactive mode
55 2. Copy this multi-line code:
56
57 ${GREEN}for i in 1 2 3; do
58 echo "Number: \$i"
59 done${RESET}
60
61 3. Paste it into the fortsh prompt
62 4. Observe that it does NOT execute immediately
63 5. The entire block should appear on the command line
64 6. Press Enter to execute it
65 7. Type 'exit' to finish the test
66
67 EOF
68
69 prompt_user "Ready to test bracketed paste?"
70
71 echo -e "${BOLD}Starting fortsh...${RESET}\n"
72 FORTSH_RC_FILE=/dev/null "$FORTSH"
73
74 echo -e "\n${GREEN}Test complete!${RESET}"
75 read -p "Did the paste work correctly (text appeared without executing)? [y/N] " response
76 if [[ "$response" =~ ^[Yy]$ ]]; then
77 echo -e "${GREEN}✓ Bracketed paste test PASSED${RESET}"
78 else
79 echo -e "${RED}✗ Bracketed paste test FAILED${RESET}"
80 fi
81 }
82
83 # ==============================================================================
84 # Test 2: Window Resize (SIGWINCH)
85 # ==============================================================================
86
87 test_window_resize() {
88 test_section "Test 2: Window Resize (SIGWINCH)"
89
90 cat <<EOF
91 ${BOLD}This test verifies that window resize is handled correctly.${RESET}
92
93 Instructions:
94 1. fortsh will start in interactive mode
95 2. Type: ${GREEN}echo \$COLUMNS \$LINES${RESET}
96 3. Note the values
97 4. Resize your terminal window (drag corner)
98 5. Type: ${GREEN}echo \$COLUMNS \$LINES${RESET} again
99 6. Verify that the values changed to match new size
100 7. Type a long command and verify cursor positioning works
101 8. Type 'exit' to finish
102
103 EOF
104
105 prompt_user "Ready to test window resize?"
106
107 echo -e "${BOLD}Starting fortsh...${RESET}\n"
108 FORTSH_RC_FILE=/dev/null "$FORTSH"
109
110 echo -e "\n${GREEN}Test complete!${RESET}"
111 read -p "Did COLUMNS/LINES update after resize? [y/N] " response
112 if [[ "$response" =~ ^[Yy]$ ]]; then
113 echo -e "${GREEN}✓ Window resize test PASSED${RESET}"
114 else
115 echo -e "${RED}✗ Window resize test FAILED${RESET}"
116 fi
117 }
118
119 # ==============================================================================
120 # Test 3: Colored Prompts & Cursor Positioning
121 # ==============================================================================
122
123 test_colored_prompts() {
124 test_section "Test 3: Colored Prompts & Cursor Positioning"
125
126 cat <<EOF
127 ${BOLD}This test verifies that colored prompts don't break cursor positioning.${RESET}
128
129 Instructions:
130 1. fortsh will start with a colored prompt
131 2. Type a long command that wraps multiple lines
132 3. Verify that cursor stays in correct position
133 4. Use arrow keys to navigate - cursor should track correctly
134 5. Backspace should delete correctly without visual glitches
135 6. Type 'exit' to finish
136
137 EOF
138
139 prompt_user "Ready to test colored prompts?"
140
141 echo -e "${BOLD}Starting fortsh with colored prompt...${RESET}\n"
142 # Set a colored prompt using PS1
143 FORTSH_RC_FILE=/dev/null "$FORTSH" -c 'PS1="\[\e[1;32m\]fortsh\[\e[0m\]> "; exec ../bin/fortsh'
144
145 echo -e "\n${GREEN}Test complete!${RESET}"
146 read -p "Did cursor positioning work correctly with colored prompt? [y/N] " response
147 if [[ "$response" =~ ^[Yy]$ ]]; then
148 echo -e "${GREEN}✓ Colored prompt test PASSED${RESET}"
149 else
150 echo -e "${RED}✗ Colored prompt test FAILED${RESET}"
151 fi
152 }
153
154 # ==============================================================================
155 # Test 4: Job Control & Job Specs
156 # ==============================================================================
157
158 test_job_specs() {
159 test_section "Test 4: Job Control & Job Specs"
160
161 cat <<EOF
162 ${BOLD}This test verifies job control and job spec parsing.${RESET}
163
164 Instructions:
165 1. fortsh will start in interactive mode
166 2. Run: ${GREEN}sleep 100 &${RESET}
167 3. Run: ${GREEN}sleep 200 &${RESET}
168 4. Run: ${GREEN}jobs${RESET} - verify both jobs listed
169 5. Run: ${GREEN}fg %1${RESET} - bring job 1 to foreground
170 6. Press Ctrl-Z to suspend it
171 7. Run: ${GREEN}fg %%${RESET} - bring current job to foreground
172 8. Press Ctrl-Z again
173 9. Run: ${GREEN}fg %-${RESET} - bring previous job to foreground
174 10. Press Ctrl-C to kill it
175 11. Run: ${GREEN}kill %1${RESET} - kill remaining job
176 12. Type 'exit' to finish
177
178 EOF
179
180 prompt_user "Ready to test job specs?"
181
182 echo -e "${BOLD}Starting fortsh...${RESET}\n"
183 FORTSH_RC_FILE=/dev/null "$FORTSH"
184
185 echo -e "\n${GREEN}Test complete!${RESET}"
186 read -p "Did job specs (%1, %%, %-, etc.) work correctly? [y/N] " response
187 if [[ "$response" =~ ^[Yy]$ ]]; then
188 echo -e "${GREEN}✓ Job specs test PASSED${RESET}"
189 else
190 echo -e "${RED}✗ Job specs test FAILED${RESET}"
191 fi
192 }
193
194 # ==============================================================================
195 # Test 5: Terminal Title Updates
196 # ==============================================================================
197
198 test_terminal_title() {
199 test_section "Test 5: Terminal Title Updates"
200
201 cat <<EOF
202 ${BOLD}This test verifies that terminal title updates correctly.${RESET}
203
204 Instructions:
205 1. Look at your terminal window/tab title BEFORE starting fortsh
206 2. Note the current title
207 3. fortsh will start in interactive mode
208 4. Check if terminal title changed to show: user@host:/path
209 5. Run: ${GREEN}cd /tmp${RESET}
210 6. Check if title updated to show new path
211 7. Type 'exit' to finish
212
213 EOF
214
215 prompt_user "Ready to test terminal title?"
216
217 echo -e "${BOLD}Starting fortsh...${RESET}\n"
218 echo -e "${YELLOW}Check your terminal window title NOW${RESET}"
219 sleep 2
220
221 FORTSH_RC_FILE=/dev/null "$FORTSH"
222
223 echo -e "\n${GREEN}Test complete!${RESET}"
224 read -p "Did terminal title update to show user@host:path? [y/N] " response
225 if [[ "$response" =~ ^[Yy]$ ]]; then
226 echo -e "${GREEN}✓ Terminal title test PASSED${RESET}"
227 else
228 echo -e "${RED}✗ Terminal title test FAILED${RESET}"
229 fi
230 }
231
232 # ==============================================================================
233 # Test 6: UTF-8 Wide Characters
234 # ==============================================================================
235
236 test_utf8_wide_chars() {
237 test_section "Test 6: UTF-8 Wide Characters"
238
239 cat <<EOF
240 ${BOLD}This test verifies UTF-8 wide character handling.${RESET}
241
242 Instructions:
243 1. fortsh will start in interactive mode
244 2. Type: ${GREEN}echo "🚀 Rocket"${RESET}
245 3. Verify emoji displays correctly
246 4. Type: ${GREEN}echo "中文字"${RESET}
247 5. Verify Chinese characters display correctly
248 6. Set prompt with emoji: ${GREEN}PS1="🚀 > "${RESET}
249 7. Type a long command - verify cursor positioning is correct
250 8. Arrow keys should work correctly with emoji prompt
251 9. Type 'exit' to finish
252
253 EOF
254
255 prompt_user "Ready to test UTF-8 wide characters?"
256
257 echo -e "${BOLD}Starting fortsh...${RESET}\n"
258 FORTSH_RC_FILE=/dev/null "$FORTSH"
259
260 echo -e "\n${GREEN}Test complete!${RESET}"
261 read -p "Did UTF-8 wide characters display and position correctly? [y/N] " response
262 if [[ "$response" =~ ^[Yy]$ ]]; then
263 echo -e "${GREEN}✓ UTF-8 wide chars test PASSED${RESET}"
264 else
265 echo -e "${RED}✗ UTF-8 wide chars test FAILED${RESET}"
266 fi
267 }
268
269 # ==============================================================================
270 # Main Menu
271 # ==============================================================================
272
273 main_menu() {
274 while true; do
275 echo -e "\n${BOLD}${CYAN}Select a test to run:${RESET}\n"
276 echo " 1) Bracketed Paste Mode"
277 echo " 2) Window Resize (SIGWINCH)"
278 echo " 3) Colored Prompts & Cursor Positioning"
279 echo " 4) Job Control & Job Specs"
280 echo " 5) Terminal Title Updates"
281 echo " 6) UTF-8 Wide Characters"
282 echo " 7) Run ALL tests"
283 echo " 0) Exit"
284 echo ""
285 read -p "Enter choice [0-7]: " choice
286
287 case "$choice" in
288 1) test_bracketed_paste ;;
289 2) test_window_resize ;;
290 3) test_colored_prompts ;;
291 4) test_job_specs ;;
292 5) test_terminal_title ;;
293 6) test_utf8_wide_chars ;;
294 7)
295 test_bracketed_paste
296 test_window_resize
297 test_colored_prompts
298 test_job_specs
299 test_terminal_title
300 test_utf8_wide_chars
301 ;;
302 0)
303 echo -e "\n${GREEN}Goodbye!${RESET}"
304 exit 0
305 ;;
306 *)
307 echo -e "${RED}Invalid choice${RESET}"
308 ;;
309 esac
310 done
311 }
312
313 # ==============================================================================
314 # Run
315 # ==============================================================================
316
317 if [[ "${1:-}" == "--all" ]]; then
318 test_bracketed_paste
319 test_window_resize
320 test_colored_prompts
321 test_job_specs
322 test_terminal_title
323 test_utf8_wide_chars
324 else
325 main_menu
326 fi