termiotest

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package termiotest provides *termio.Streams test helpers with buffer- backed streams and convenience accessors for the underlying buffers.

Quick start

s, in, out, errOut := termiotest.New()
fmt.Fprintln(s.Out, "hello")
fmt.Println(out.String()) // prints "hello\n"

Both New and NewTTY return the three *bytes.Buffer values corresponding to In, Out, and ErrOut so assertions are one line:

assert.Equal(t, "hello\n", out.String())

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New() (s *termio.Streams, in, out, errOut *bytes.Buffer)

New returns a *termio.Streams backed by three *bytes.Buffer values. All three streams report as non-TTY. The returned buffers are the live underlying storage; writes to s.Out appear in out, etc.

Example

ExampleNew returns buffer-backed streams and the underlying buffers for assertion. Writes to s.Out appear in the returned out buffer.

package main

import (
	"fmt"

	"gopherly.dev/termio/termiotest"
)

func main() {
	s, _, out, _ := termiotest.New()

	fmt.Fprintln(s.Out, "hello") //nolint:errcheck
	fmt.Print(out.String())
}
Output:
hello

func NewTTY

func NewTTY() (s *termio.Streams, in, out, errOut *bytes.Buffer)

NewTTY is like New but overrides all three TTY flags to true, making termio.Streams.IsInteractive return true. Use when the code path under test branches on TTY detection.

Example

ExampleNewTTY is like New but marks all three streams as TTYs so IsInteractive returns true.

package main

import (
	"fmt"

	"gopherly.dev/termio/termiotest"
)

func main() {
	s, in, out, errOut := termiotest.NewTTY()
	_ = in
	_ = out
	_ = errOut

	fmt.Println(s.IsInteractive())
}
Output:
true

Types

This section is empty.

Jump to

Keyboard shortcuts

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