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)
| 934 | // |
| 935 | // Use WithRelaxedIO to disable this behaviour. |
| 936 | func failOnSendError(t *testing.T) expect.ConsoleOpt { |
| 937 | t.Helper() |
| 938 | return expect.WithSendObserver( |
| 939 | func(msg string, n int, err error) { |
| 940 | t.Helper() |
| 941 | |
| 942 | if err != nil { |
| 943 | t.Fatalf("Failed to send %q: %s\n", msg, err) |
| 944 | } |
| 945 | if len(msg) != n { |
| 946 | t.Fatalf("Only sent %d of %d bytes for %q\n", n, len(msg), msg) |
| 947 | } |
| 948 | }, |
| 949 | ) |
| 950 | } |
| 951 | |
| 952 | // testCloser is a helper to fail the test if a Closer fails to close. |
| 953 | func testCloser(t *testing.T, closer io.Closer) { |
no test coverage detected