MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / TestExecProcessDoesNotLeakViewOutput

Function TestExecProcessDoesNotLeakViewOutput

exec_test.go:194–217  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

192// when releasing the terminal for the subprocess and when shutting down, which
193// keeps the assertion deterministic.
194func 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

Callers

nothing calls this directly

Calls 7

RunMethod · 0.95
NewProgramFunction · 0.85
WithInputFunction · 0.85
WithOutputFunction · 0.85
WithWindowSizeFunction · 0.85
WithFPSFunction · 0.85
StringMethod · 0.45

Tested by

no test coverage detected