MCPcopy
hub / github.com/cheat/cheat / TestPromptError

Function TestPromptError

internal/installer/prompt_test.go:138–159  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

136}
137
138func TestPromptError(t *testing.T) {
139 // Save original stdin
140 oldStdin := os.Stdin
141 defer func() {
142 os.Stdin = oldStdin
143 }()
144
145 // Create a pipe and close it immediately to simulate read error
146 r, w, _ := os.Pipe()
147 os.Stdin = r
148 r.Close()
149 w.Close()
150
151 // This should cause a read error
152 _, err := Prompt("Test?", false)
153 if err == nil {
154 t.Error("expected error when reading from closed stdin, got nil")
155 }
156 if !strings.Contains(err.Error(), "failed to prompt") {
157 t.Errorf("expected 'failed to prompt' error, got: %v", err)
158 }
159}

Callers

nothing calls this directly

Calls 1

PromptFunction · 0.85

Tested by

no test coverage detected