newStream returns a *streams.Out whose IsTerminal() matches tty. When tty is true it is backed by a pseudo-terminal slave; otherwise by an os.Pipe writer.
(t *testing.T, tty bool)
| 49 | // newStream returns a *streams.Out whose IsTerminal() matches tty. When tty is |
| 50 | // true it is backed by a pseudo-terminal slave; otherwise by an os.Pipe writer. |
| 51 | func newStream(t *testing.T, tty bool) *streams.Out { |
| 52 | t.Helper() |
| 53 | if tty { |
| 54 | ptmx, slave, err := pty.Open() |
| 55 | assert.NilError(t, err) |
| 56 | t.Cleanup(func() { |
| 57 | _ = ptmx.Close() |
| 58 | _ = slave.Close() |
| 59 | }) |
| 60 | return streams.NewOut(slave) |
| 61 | } |
| 62 | r, w, err := os.Pipe() |
| 63 | assert.NilError(t, err) |
| 64 | t.Cleanup(func() { |
| 65 | _ = r.Close() |
| 66 | _ = w.Close() |
| 67 | }) |
| 68 | return streams.NewOut(w) |
| 69 | } |
| 70 | |
| 71 | func newMockCli(t *testing.T, out, errStream *streams.Out) *mocks.MockCli { |
| 72 | t.Helper() |
no test coverage detected