failOnExpectError adds an observer that will fail the test in a standardised way if any expectation on the command output fails, without requiring an explicit assertion. Use WithRelaxedIO to disable this behaviour.
(t *testing.T)
| 203 | // |
| 204 | // Use WithRelaxedIO to disable this behaviour. |
| 205 | func failOnExpectError(t *testing.T) expect.ConsoleOpt { |
| 206 | t.Helper() |
| 207 | return expect.WithExpectObserver( |
| 208 | func(matchers []expect.Matcher, buf string, err error) { |
| 209 | t.Helper() |
| 210 | |
| 211 | if err == nil { |
| 212 | return |
| 213 | } |
| 214 | |
| 215 | if len(matchers) == 0 { |
| 216 | t.Fatalf("Error occurred while matching %q: %s\n", buf, err) |
| 217 | } |
| 218 | |
| 219 | var criteria []string |
| 220 | for _, matcher := range matchers { |
| 221 | criteria = append(criteria, fmt.Sprintf("%q", matcher.Criteria())) |
| 222 | } |
| 223 | t.Fatalf("Failed to find [%s] in %q: %s\n", strings.Join(criteria, ", "), buf, err) |
| 224 | }, |
| 225 | ) |
| 226 | } |
| 227 | |
| 228 | // failOnSendError adds an observer that will fail the test in a standardised way |
| 229 | // if any sending of input fails, without requiring an explicit assertion. |
no test coverage detected