Start starts a new process asynchronously and returns a PTYCmd and Process. It kills the process and PTYCmd upon cleanup
(t *testing.T, cmd *pty.Cmd, opts ...pty.StartOption)
| 46 | // Start starts a new process asynchronously and returns a PTYCmd and Process. |
| 47 | // It kills the process and PTYCmd upon cleanup |
| 48 | func Start(t *testing.T, cmd *pty.Cmd, opts ...pty.StartOption) (*PTYCmd, pty.Process) { |
| 49 | t.Helper() |
| 50 | |
| 51 | ptty, ps, err := pty.Start(cmd, opts...) |
| 52 | require.NoError(t, err) |
| 53 | t.Cleanup(func() { |
| 54 | _ = ps.Kill() |
| 55 | _ = ps.Wait() |
| 56 | }) |
| 57 | ex := newExpecter(t, ptty.OutputReader(), cmd.Args[0]) |
| 58 | |
| 59 | r := &PTYCmd{ |
| 60 | outExpecter: ex, |
| 61 | PTYCmd: ptty, |
| 62 | } |
| 63 | t.Cleanup(func() { |
| 64 | _ = r.Close() |
| 65 | }) |
| 66 | return r, ps |
| 67 | } |
| 68 | |
| 69 | func newExpecter(t *testing.T, r io.Reader, name string) outExpecter { |
| 70 | // Use pipe for logging. |