testutils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package testutils provides utility functions and types for testing terminal interactions and handling standard output in Go tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreatePTY added in v0.2.0

func CreatePTY(t *testing.T) (master *os.File, slave *os.File)

CreatePTY creates a pseudo-terminal pair for testing terminal interactions. The returned master and slave *os.File can be used to simulate terminal input and output in tests. The master end can be used to write input as if typed by a user, while the slave end can be used to read output from the terminal. Both files are automatically closed after the test completes.

Lovely stolen from https://github.com/engmtcdrm/go-pardon testutils package.

func CreatePTYWithSize added in v0.2.0

func CreatePTYWithSize(t *testing.T, columns, rows int) (master *os.File, slave *os.File)

CreatePTYWithSize creates a pseudo-terminal pair with the specified size for testing terminal interactions. The returned master and slave *os.File can be used to simulate terminal input and output in tests that require specific terminal dimensions. Both files are automatically closed after the test completes.

Lovely stolen from https://github.com/engmtcdrm/go-pardon testutils package.

func ReadPTYOutput added in v0.2.0

func ReadPTYOutput(t *testing.T, ptyFile io.Reader, bufferSize int) string

ReadPTYOutput reads all available output from the provided reader until EOF is reached.

func SetStdout

func SetStdout(t *testing.T) *os.File

SetStdout is a helper function that stores the originl os.Stdout, replaces it with a temporary file, and restores the original os.Stdout after the test finishes. It returns the temporary file.

Types

type EmptyReader

type EmptyReader struct{}

EmptyReader is a mock reader that simulates an empty input.

func (*EmptyReader) Read

func (e *EmptyReader) Read(_ []byte) (n int, err error)

Read implements the io.Reader interface for the EmptyReader type, always returning 0 bytes read and an EOF error.

type ErrorReader

type ErrorReader struct{}

ErrorReader is a mock reader that simulates an error when reading.

func (*ErrorReader) Read

func (e *ErrorReader) Read(_ []byte) (n int, err error)

Read implements the io.Reader interface for the ErrorReader type, always returning 0 bytes read and an unexpected EOF error.

Jump to

Keyboard shortcuts

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