RunAndProcessStderrInt runs the given command, and streams its stderr line-by-line to stderrCallback until it returns false. The remaining lines from stderr, if any, are asynchronously sent line-by-line to stderrAsyncCallback.
(tb testing.TB, stderrCallback func(line string) bool, stderrAsyncCallback func(line string), args ...string)
| 201 | // from stderr, if any, are asynchronously sent line-by-line to |
| 202 | // stderrAsyncCallback. |
| 203 | func (e *CLITest) RunAndProcessStderrInt(tb testing.TB, stderrCallback func(line string) bool, stderrAsyncCallback func(line string), args ...string) (wait func() error, interrupt func(os.Signal)) { |
| 204 | tb.Helper() |
| 205 | |
| 206 | stdout, stderr, wait, interrupt := e.Runner.Start(tb, e.RunContext, e.cmdArgs(args), e.Environment) |
| 207 | |
| 208 | prefix, logOutput := e.getLogOutputPrefix() |
| 209 | |
| 210 | go func() { |
| 211 | scanner := bufio.NewScanner(stdout) |
| 212 | for scanner.Scan() { |
| 213 | if logOutput { |
| 214 | tb.Logf("[%vstdout] %v", prefix, scanner.Text()) |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if logOutput { |
| 219 | tb.Logf("[%vstdout] EOF", prefix) |
| 220 | } |
| 221 | }() |
| 222 | |
| 223 | scanner := bufio.NewScanner(stderr) |
| 224 | for scanner.Scan() { |
| 225 | if !stderrCallback(scanner.Text()) { |
| 226 | break |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | // complete stderr scanning in the background without processing lines. |
| 231 | go func() { |
| 232 | for scanner.Scan() { |
| 233 | if stderrAsyncCallback != nil { |
| 234 | stderrAsyncCallback(scanner.Text()) |
| 235 | } |
| 236 | |
| 237 | if logOutput { |
| 238 | tb.Logf("[%vstderr] %v", prefix, scanner.Text()) |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | if logOutput { |
| 243 | tb.Logf("[%vstderr] EOF", prefix) |
| 244 | } |
| 245 | }() |
| 246 | |
| 247 | return wait, interrupt |
| 248 | } |
| 249 | |
| 250 | // RunAndExpectSuccessWithErrOut runs the given command, expects it to succeed and returns its stdout and stderr lines. |
| 251 | func (e *CLITest) RunAndExpectSuccessWithErrOut(tb testing.TB, args ...string) (stdout, stderr []string) { |