markdown · 7952 bytes Raw Blame History

Terminal Integration Test Suite

Comprehensive test suite for fortsh terminal standardization features.

Overview

This test suite validates all 6 phases of terminal standardization implemented in fortsh:

  • Phase 1: Window Size Detection & SIGWINCH
  • Phase 2: Bracketed Paste Mode
  • Phase 3: Prompt Width Calculation
  • Phase 4: Job Specs & Terminal Title
  • Phase 5: Terminal Type Adaptation
  • Phase 6: Polish & Optional Features (UTF-8, True Color)

Test Files

terminal_integration_tests.sh

Automated tests that can run in CI/CD environments.

# Run all automated tests
./tests/terminal_integration_tests.sh

# Set custom fortsh binary
FORTSH=./bin/fortsh ./tests/terminal_integration_tests.sh

What it tests:

  • ✅ Environment variables ($COLUMNS, $LINES)
  • ✅ Terminal type detection (TERM=dumb, TERM=xterm, etc.)
  • ✅ UTF-8 character handling
  • ✅ True color pass-through
  • ✅ Integration across phases

Limitations:

  • Cannot test interactive features (paste, job control, resize)
  • Cannot verify visual output (colors, cursor positioning)
  • Runs in non-interactive mode (-c flag)

terminal_interactive_tests.sh

Manual tests requiring user interaction.

# Run interactive test menu
./tests/terminal_interactive_tests.sh

# Run all tests sequentially
./tests/terminal_interactive_tests.sh --all

What it tests:

  • ✅ Bracketed paste mode (multi-line paste behavior)
  • ✅ Window resize (SIGWINCH) handling
  • ✅ Colored prompts & cursor positioning
  • ✅ Job control & job specs (%%, %-, %1, %?string)
  • ✅ Terminal title updates
  • ✅ UTF-8 wide character cursor positioning

Menu Options:

  1. Bracketed Paste Mode
  2. Window Resize (SIGWINCH)
  3. Colored Prompts & Cursor Positioning
  4. Job Control & Job Specs
  5. Terminal Title Updates
  6. UTF-8 Wide Characters
  7. Run ALL tests
  8. Exit

Quick Start

Run Automated Tests

# Build fortsh first
make clean && make

# Run automated test suite
./tests/terminal_integration_tests.sh

Expected output:

╔══════════════════════════════════════════════════════════════╗
║    Terminal Integration Test Suite for fortsh               ║
╚══════════════════════════════════════════════════════════════╝

fortsh binary: ./bin/fortsh
Test output: /tmp/tmp.XXXXXXXXXX

═══ Phase 1: Window Size Detection & SIGWINCH ═══

[TEST 1] Window size: COLUMNS env var set
  ✓ PASS
[TEST 2] Window size: LINES env var set
  ✓ PASS
...
═══════════════════════════════════════════════════
Test Summary
═══════════════════════════════════════════════════

Total tests run:    21
Passed:             15
Failed:             0
Skipped:            6

✓ ALL TESTS PASSED!

Run Interactive Tests

# Launch interactive test menu
./tests/terminal_interactive_tests.sh

Follow on-screen instructions for each test.

Test Coverage Matrix

Phase Feature Automated Interactive Manual
1 Window size env vars -
1 SIGWINCH handling - -
2 Bracketed paste mode - -
2 Paste marker detection - -
3 ANSI code width calc -
3 Multi-line prompts -
4 Job spec %% (current) - -
4 Job spec %- (previous) - -
4 Job spec %n (number) - -
4 Job spec %?string - -
4 Terminal title OSC - -
5 TERM=dumb detection - -
5 Color disabling - -
6 UTF-8 emoji -
6 UTF-8 CJK -
6 UTF-8 wide width -
6 True color RGB - -

Legend:

  • ✅ = Fully tested
    • = Not applicable / Cannot test automatically

Test Results Interpretation

Automated Tests

PASS: Feature working correctly

  • Green ✓ checkmark
  • Increments pass counter

FAIL: Feature not working

  • Red ✗ mark with error message
  • Increments fail counter
  • Test suite exits with code 1

SKIP: Test cannot run in current environment

  • Yellow ⊘ mark with reason
  • Increments skip counter
  • Examples: interactive features, terminal-specific tests

Interactive Tests

User manually verifies behavior and responds with y/N:

  • y = Test passed (feature works)
  • N = Test failed (feature broken)

CI/CD Integration

GitHub Actions Example

name: Terminal Tests

on: [push, pull_request]

jobs:
  terminal-tests:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Build fortsh
        run: make
      - name: Run terminal integration tests
        run: ./tests/terminal_integration_tests.sh

Expected Results in CI

In CI environments (non-interactive), many tests will SKIP:

  • Bracketed paste (requires terminal)
  • SIGWINCH (requires resize event)
  • Job control (requires interactive mode)
  • Terminal title (requires real terminal)

This is normal and expected. The automated tests focus on:

  • Environment variable correctness
  • Terminal type detection logic
  • UTF-8 handling
  • Output correctness

Troubleshooting

"fortsh binary not found"

# Build fortsh first
make clean && make

# Or specify path
FORTSH=/path/to/fortsh ./tests/terminal_integration_tests.sh

"Test skipped: Requires interactive mode"

This is normal for automated tests. Run interactive tests instead:

./tests/terminal_interactive_tests.sh

Interactive tests don't work

Ensure you're in a real terminal (not CI):

# Check if terminal
if [[ -t 0 ]]; then echo "Terminal"; else echo "Not a terminal"; fi

Colors not showing in output

Check $TERM:

echo $TERM  # Should be xterm-256color or similar

If TERM=dumb, colors are intentionally disabled (this is correct behavior).

Adding New Tests

Automated Test Template

test_start "My new feature"
output=$(run_fortsh 'echo "test"')
if assert_equals "test" "$output"; then
    test_pass
else
    test_fail "Feature broken"
fi

Interactive Test Template

test_my_feature() {
    test_section "Test: My Feature"

    cat <<EOF
${BOLD}This test verifies my feature.${RESET}

Instructions:
1. Do something
2. Verify behavior
3. Type 'exit'
EOF

    prompt_user "Ready to test?"
    FORTSH_RC_FILE=/dev/null "$FORTSH"

    read -p "Did it work? [y/N] " response
    if [[ "$response" =~ ^[Yy]$ ]]; then
        echo -e "${GREEN}✓ Test PASSED${RESET}"
    else
        echo -e "${RED}✗ Test FAILED${RESET}"
    fi
}

Test Development Guidelines

  1. Keep automated tests fast - No sleep, no timeouts
  2. Make interactive tests clear - Explicit instructions
  3. Test one thing at a time - Focused, isolated tests
  4. Document expected behavior - What should happen
  5. Handle both pass and fail - Don't assume success
  • TARGET/01_TERMINAL_STANDARDS.md - Background on terminal standards
  • TARGET/02_CURRENT_STATE_AUDIT.md - Initial capability audit
  • TARGET/03_GAP_ANALYSIS.md - Gap priority matrix
  • TARGET/04_IMPLEMENTATION_ROADMAP.md - Implementation phases

License

Same as fortsh project.

Contributing

When adding new terminal features:

  1. Write automated tests first (if possible)
  2. Add interactive tests for visual/behavioral features
  3. Update this README with new test coverage
  4. Run full test suite before committing
View source
1 # Terminal Integration Test Suite
2
3 Comprehensive test suite for fortsh terminal standardization features.
4
5 ## Overview
6
7 This test suite validates all 6 phases of terminal standardization implemented in fortsh:
8
9 - **Phase 1**: Window Size Detection & SIGWINCH
10 - **Phase 2**: Bracketed Paste Mode
11 - **Phase 3**: Prompt Width Calculation
12 - **Phase 4**: Job Specs & Terminal Title
13 - **Phase 5**: Terminal Type Adaptation
14 - **Phase 6**: Polish & Optional Features (UTF-8, True Color)
15
16 ## Test Files
17
18 ### `terminal_integration_tests.sh`
19 **Automated tests** that can run in CI/CD environments.
20
21 ```bash
22 # Run all automated tests
23 ./tests/terminal_integration_tests.sh
24
25 # Set custom fortsh binary
26 FORTSH=./bin/fortsh ./tests/terminal_integration_tests.sh
27 ```
28
29 **What it tests:**
30 - ✅ Environment variables (`$COLUMNS`, `$LINES`)
31 - ✅ Terminal type detection (`TERM=dumb`, `TERM=xterm`, etc.)
32 - ✅ UTF-8 character handling
33 - ✅ True color pass-through
34 - ✅ Integration across phases
35
36 **Limitations:**
37 - Cannot test interactive features (paste, job control, resize)
38 - Cannot verify visual output (colors, cursor positioning)
39 - Runs in non-interactive mode (`-c` flag)
40
41 ### `terminal_interactive_tests.sh`
42 **Manual tests** requiring user interaction.
43
44 ```bash
45 # Run interactive test menu
46 ./tests/terminal_interactive_tests.sh
47
48 # Run all tests sequentially
49 ./tests/terminal_interactive_tests.sh --all
50 ```
51
52 **What it tests:**
53 - ✅ Bracketed paste mode (multi-line paste behavior)
54 - ✅ Window resize (SIGWINCH) handling
55 - ✅ Colored prompts & cursor positioning
56 - ✅ Job control & job specs (`%%`, `%-`, `%1`, `%?string`)
57 - ✅ Terminal title updates
58 - ✅ UTF-8 wide character cursor positioning
59
60 **Menu Options:**
61 1. Bracketed Paste Mode
62 2. Window Resize (SIGWINCH)
63 3. Colored Prompts & Cursor Positioning
64 4. Job Control & Job Specs
65 5. Terminal Title Updates
66 6. UTF-8 Wide Characters
67 7. Run ALL tests
68 0. Exit
69
70 ## Quick Start
71
72 ### Run Automated Tests
73
74 ```bash
75 # Build fortsh first
76 make clean && make
77
78 # Run automated test suite
79 ./tests/terminal_integration_tests.sh
80 ```
81
82 Expected output:
83 ```
84 ╔══════════════════════════════════════════════════════════════╗
85 ║ Terminal Integration Test Suite for fortsh ║
86 ╚══════════════════════════════════════════════════════════════╝
87
88 fortsh binary: ./bin/fortsh
89 Test output: /tmp/tmp.XXXXXXXXXX
90
91 ═══ Phase 1: Window Size Detection & SIGWINCH ═══
92
93 [TEST 1] Window size: COLUMNS env var set
94 ✓ PASS
95 [TEST 2] Window size: LINES env var set
96 ✓ PASS
97 ...
98 ═══════════════════════════════════════════════════
99 Test Summary
100 ═══════════════════════════════════════════════════
101
102 Total tests run: 21
103 Passed: 15
104 Failed: 0
105 Skipped: 6
106
107 ✓ ALL TESTS PASSED!
108 ```
109
110 ### Run Interactive Tests
111
112 ```bash
113 # Launch interactive test menu
114 ./tests/terminal_interactive_tests.sh
115 ```
116
117 Follow on-screen instructions for each test.
118
119 ## Test Coverage Matrix
120
121 | Phase | Feature | Automated | Interactive | Manual |
122 |-------|---------|-----------|-------------|--------|
123 | 1 | Window size env vars | ✅ | ✅ | - |
124 | 1 | SIGWINCH handling | - | ✅ | - |
125 | 2 | Bracketed paste mode | - | ✅ | - |
126 | 2 | Paste marker detection | - | ✅ | - |
127 | 3 | ANSI code width calc | ✅ | ✅ | - |
128 | 3 | Multi-line prompts | ✅ | ✅ | - |
129 | 4 | Job spec %% (current) | - | ✅ | - |
130 | 4 | Job spec %- (previous) | - | ✅ | - |
131 | 4 | Job spec %n (number) | - | ✅ | - |
132 | 4 | Job spec %?string | - | ✅ | - |
133 | 4 | Terminal title OSC | - | ✅ | - |
134 | 5 | TERM=dumb detection | ✅ | - | - |
135 | 5 | Color disabling | ✅ | - | - |
136 | 6 | UTF-8 emoji | ✅ | ✅ | - |
137 | 6 | UTF-8 CJK | ✅ | ✅ | - |
138 | 6 | UTF-8 wide width | ✅ | ✅ | - |
139 | 6 | True color RGB | ✅ | - | - |
140
141 **Legend:**
142 - ✅ = Fully tested
143 - - = Not applicable / Cannot test automatically
144
145 ## Test Results Interpretation
146
147 ### Automated Tests
148
149 **PASS**: Feature working correctly
150 - Green ✓ checkmark
151 - Increments pass counter
152
153 **FAIL**: Feature not working
154 - Red ✗ mark with error message
155 - Increments fail counter
156 - Test suite exits with code 1
157
158 **SKIP**: Test cannot run in current environment
159 - Yellow ⊘ mark with reason
160 - Increments skip counter
161 - Examples: interactive features, terminal-specific tests
162
163 ### Interactive Tests
164
165 User manually verifies behavior and responds with `y/N`:
166 - `y` = Test passed (feature works)
167 - `N` = Test failed (feature broken)
168
169 ## CI/CD Integration
170
171 ### GitHub Actions Example
172
173 ```yaml
174 name: Terminal Tests
175
176 on: [push, pull_request]
177
178 jobs:
179 terminal-tests:
180 runs-on: ubuntu-latest
181 steps:
182 - uses: actions/checkout@v3
183 - name: Build fortsh
184 run: make
185 - name: Run terminal integration tests
186 run: ./tests/terminal_integration_tests.sh
187 ```
188
189 ### Expected Results in CI
190
191 In CI environments (non-interactive), many tests will **SKIP**:
192 - Bracketed paste (requires terminal)
193 - SIGWINCH (requires resize event)
194 - Job control (requires interactive mode)
195 - Terminal title (requires real terminal)
196
197 This is **normal and expected**. The automated tests focus on:
198 - Environment variable correctness
199 - Terminal type detection logic
200 - UTF-8 handling
201 - Output correctness
202
203 ## Troubleshooting
204
205 ### "fortsh binary not found"
206
207 ```bash
208 # Build fortsh first
209 make clean && make
210
211 # Or specify path
212 FORTSH=/path/to/fortsh ./tests/terminal_integration_tests.sh
213 ```
214
215 ### "Test skipped: Requires interactive mode"
216
217 This is normal for automated tests. Run interactive tests instead:
218
219 ```bash
220 ./tests/terminal_interactive_tests.sh
221 ```
222
223 ### Interactive tests don't work
224
225 Ensure you're in a real terminal (not CI):
226 ```bash
227 # Check if terminal
228 if [[ -t 0 ]]; then echo "Terminal"; else echo "Not a terminal"; fi
229 ```
230
231 ### Colors not showing in output
232
233 Check `$TERM`:
234 ```bash
235 echo $TERM # Should be xterm-256color or similar
236 ```
237
238 If `TERM=dumb`, colors are intentionally disabled (this is correct behavior).
239
240 ## Adding New Tests
241
242 ### Automated Test Template
243
244 ```bash
245 test_start "My new feature"
246 output=$(run_fortsh 'echo "test"')
247 if assert_equals "test" "$output"; then
248 test_pass
249 else
250 test_fail "Feature broken"
251 fi
252 ```
253
254 ### Interactive Test Template
255
256 ```bash
257 test_my_feature() {
258 test_section "Test: My Feature"
259
260 cat <<EOF
261 ${BOLD}This test verifies my feature.${RESET}
262
263 Instructions:
264 1. Do something
265 2. Verify behavior
266 3. Type 'exit'
267 EOF
268
269 prompt_user "Ready to test?"
270 FORTSH_RC_FILE=/dev/null "$FORTSH"
271
272 read -p "Did it work? [y/N] " response
273 if [[ "$response" =~ ^[Yy]$ ]]; then
274 echo -e "${GREEN}✓ Test PASSED${RESET}"
275 else
276 echo -e "${RED}✗ Test FAILED${RESET}"
277 fi
278 }
279 ```
280
281 ## Test Development Guidelines
282
283 1. **Keep automated tests fast** - No sleep, no timeouts
284 2. **Make interactive tests clear** - Explicit instructions
285 3. **Test one thing at a time** - Focused, isolated tests
286 4. **Document expected behavior** - What should happen
287 5. **Handle both pass and fail** - Don't assume success
288
289 ## Related Documentation
290
291 - `TARGET/01_TERMINAL_STANDARDS.md` - Background on terminal standards
292 - `TARGET/02_CURRENT_STATE_AUDIT.md` - Initial capability audit
293 - `TARGET/03_GAP_ANALYSIS.md` - Gap priority matrix
294 - `TARGET/04_IMPLEMENTATION_ROADMAP.md` - Implementation phases
295
296 ## License
297
298 Same as fortsh project.
299
300 ## Contributing
301
302 When adding new terminal features:
303
304 1. Write automated tests first (if possible)
305 2. Add interactive tests for visual/behavioral features
306 3. Update this README with new test coverage
307 4. Run full test suite before committing