| 136 | } |
| 137 | |
| 138 | func 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 | } |