failOnSendError adds an observer that will fail the test in a standardised way if any sending of input fails, without requiring an explicit assertion. Use WithRelaxedIO to disable this behaviour.
(t *testing.T)
| 230 | // |
| 231 | // Use WithRelaxedIO to disable this behaviour. |
| 232 | func failOnSendError(t *testing.T) expect.ConsoleOpt { |
| 233 | t.Helper() |
| 234 | return expect.WithSendObserver( |
| 235 | func(msg string, n int, err error) { |
| 236 | t.Helper() |
| 237 | |
| 238 | if err != nil { |
| 239 | t.Fatalf("Failed to send %q: %s\n", msg, err) |
| 240 | } |
| 241 | if len(msg) != n { |
| 242 | t.Fatalf("Only sent %d of %d bytes for %q\n", n, len(msg), msg) |
| 243 | } |
| 244 | }, |
| 245 | ) |
| 246 | } |
| 247 | |
| 248 | // testCloser is a helper to fail the test if a Closer fails to close. |
| 249 | func testCloser(t *testing.T, closer io.Closer) { |
no test coverage detected