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 ¶
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 ¶
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.