TestExecProcessDoesNotLeakViewOutput is a regression test for #431: when ExecProcess runs a subprocess, the renderer must not flush the last View() to stdout. The program renders EXEC_MARKER until the subprocess finishes and QUIT_MARKER afterwards, so EXEC_MARKER may only ever reach stdout through t
(t *testing.T)
| 192 | // when releasing the terminal for the subprocess and when shutting down, which |
| 193 | // keeps the assertion deterministic. |
| 194 | func TestExecProcessDoesNotLeakViewOutput(t *testing.T) { |
| 195 | t.Parallel() |
| 196 | var buf bytes.Buffer |
| 197 | var in bytes.Buffer |
| 198 | |
| 199 | m := &execLeakModel{} |
| 200 | p := NewProgram(m, |
| 201 | WithInput(&in), |
| 202 | WithOutput(&buf), |
| 203 | WithWindowSize(80, 24), |
| 204 | WithFPS(1), |
| 205 | ) |
| 206 | if _, err := p.Run(); err != nil { |
| 207 | t.Fatalf("unexpected error: %v", err) |
| 208 | } |
| 209 | |
| 210 | out := buf.String() |
| 211 | if strings.Contains(out, "EXEC_MARKER") { |
| 212 | t.Errorf("View output leaked to stdout before the subprocess ran; the renderer must not flush the last View() when handing the terminal to a subprocess (see #431)") |
| 213 | } |
| 214 | if !strings.Contains(out, "QUIT_MARKER") { |
| 215 | t.Errorf("expected the final View() (QUIT_MARKER) to be rendered on shutdown, got output: %q", out) |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | // TestExecProcessAltscreenNoLeak verifies the #431 fix also holds in alt screen |
| 220 | // mode and that the program leaves the terminal in a clean state. The fix |
nothing calls this directly
no test coverage detected