Help us shape the future of Go! Take the 2026 Go Developer Survey

ptytest

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: MPL-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PTY

type PTY struct {
	pty.PTY
	// contains filtered or unexported fields
}

PTY wraps a pty.PTY with expect-style output matching for tests.

func New

func New(t *testing.T, opts ...pty.Option) *PTY

func (*PTY) Close

func (p *PTY) Close() error

Close closes the PTY and its expecter.

func (*PTY) ExpectMatch deprecated

func (e *PTY) ExpectMatch(str string) string

ExpectMatch uses a background context with a medium timeout.

Deprecated: use ExpectMatchContext instead.

func (*PTY) ExpectMatchContext

func (e *PTY) ExpectMatchContext(ctx context.Context, str string) string

ExpectMatchContext reads output until str is found or ctx expires.

func (*PTY) ExpectNoMatchBefore

func (e *PTY) ExpectNoMatchBefore(ctx context.Context, match, before string) string

ExpectNoMatchBefore validates that `match` does not occur before `before`.

func (*PTY) ExpectRegexMatch

func (e *PTY) ExpectRegexMatch(str string) string

ExpectRegexMatch uses a background context with a medium timeout.

func (*PTY) ExpectRegexMatchContext

func (e *PTY) ExpectRegexMatchContext(ctx context.Context, str string) string

ExpectRegexMatchContext reads output until pattern matches or ctx expires.

func (*PTY) Named

func (p *PTY) Named(name string) *PTY

Named sets the PTY name in the logs. Defaults to "cmd".

func (*PTY) Peek

func (e *PTY) Peek(ctx context.Context, n int) []byte

Peek returns the next n bytes without advancing the reader.

func (*PTY) ReadAll

func (e *PTY) ReadAll() []byte

ReadAll returns all buffered output.

func (*PTY) ReadLine

func (e *PTY) ReadLine(ctx context.Context) string

ReadLine reads output until a newline is encountered.

func (*PTY) ReadRune

func (e *PTY) ReadRune(ctx context.Context) rune

ReadRune reads a single rune from the output.

func (*PTY) Write

func (p *PTY) Write(r rune)

Write writes a single rune to the PTY input.

func (*PTY) WriteLine

func (p *PTY) WriteLine(str string)

WriteLine writes a string followed by a carriage return to the PTY input.

type PTYCmd

type PTYCmd struct {
	pty.PTYCmd
	// contains filtered or unexported fields
}

PTYCmd wraps a pty.PTYCmd with expect-style output matching for tests.

func Start

func Start(t *testing.T, cmd *pty.Cmd, opts ...pty.StartOption) (*PTYCmd, pty.Process)

Start starts a new process asynchronously and returns a PTYCmd and Process. It kills the process and PTYCmd upon cleanup.

func (*PTYCmd) Close

func (p *PTYCmd) Close() error

Close closes the PTYCmd and its expecter.

func (*PTYCmd) ExpectMatch deprecated

func (e *PTYCmd) ExpectMatch(str string) string

ExpectMatch uses a background context with a medium timeout.

Deprecated: use ExpectMatchContext instead.

func (*PTYCmd) ExpectMatchContext

func (e *PTYCmd) ExpectMatchContext(ctx context.Context, str string) string

ExpectMatchContext reads output until str is found or ctx expires.

func (*PTYCmd) ExpectNoMatchBefore

func (e *PTYCmd) ExpectNoMatchBefore(ctx context.Context, match, before string) string

ExpectNoMatchBefore validates that `match` does not occur before `before`.

func (*PTYCmd) ExpectRegexMatch

func (e *PTYCmd) ExpectRegexMatch(str string) string

ExpectRegexMatch uses a background context with a medium timeout.

func (*PTYCmd) ExpectRegexMatchContext

func (e *PTYCmd) ExpectRegexMatchContext(ctx context.Context, str string) string

ExpectRegexMatchContext reads output until pattern matches or ctx expires.

func (*PTYCmd) Peek

func (e *PTYCmd) Peek(ctx context.Context, n int) []byte

Peek returns the next n bytes without advancing the reader.

func (*PTYCmd) ReadAll

func (e *PTYCmd) ReadAll() []byte

ReadAll returns all buffered output.

func (*PTYCmd) ReadLine

func (e *PTYCmd) ReadLine(ctx context.Context) string

ReadLine reads output until a newline is encountered.

func (*PTYCmd) ReadRune

func (e *PTYCmd) ReadRune(ctx context.Context) rune

ReadRune reads a single rune from the output.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL