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)
| 907 | // |
| 908 | // Use WithRelaxedIO to disable this behaviour. |
| 909 | func failOnExpectError(t *testing.T) expect.ConsoleOpt { |
| 910 | t.Helper() |
| 911 | return expect.WithExpectObserver( |
| 912 | func(matchers []expect.Matcher, buf string, err error) { |
| 913 | t.Helper() |
| 914 | |
| 915 | if err == nil { |
| 916 | return |
| 917 | } |
| 918 | |
| 919 | if len(matchers) == 0 { |
| 920 | t.Fatalf("Error occurred while matching %q: %s\n", buf, err) |
| 921 | } |
| 922 | |
| 923 | var criteria []string |
| 924 | for _, matcher := range matchers { |
| 925 | criteria = append(criteria, fmt.Sprintf("%q", matcher.Criteria())) |
| 926 | } |
| 927 | t.Fatalf("Failed to find [%s] in %q: %s\n", strings.Join(criteria, ", "), buf, err) |
| 928 | }, |
| 929 | ) |
| 930 | } |
| 931 | |
| 932 | // failOnSendError adds an observer that will fail the test in a standardised way |
| 933 | // if any sending of input fails, without requiring an explicit assertion. |
no test coverage detected