MCPcopy Index your code
hub / github.com/cli/cli / failOnExpectError

Function failOnExpectError

pkg/iostreams/iostreams_progress_indicator_test.go:205–226  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

203//
204// Use WithRelaxedIO to disable this behaviour.
205func 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.

Callers 1

newTestVirtualTerminalFunction · 0.70

Calls 2

JoinMethod · 0.80
HelperMethod · 0.65

Tested by

no test coverage detected