capture

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2022 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package capture assists in testing code writing output to stdout or stderr. Those will be temporarily exchanged so that the written output will be caught and can be retrieved.

cout := capture.Stdout(func() {
    fmt.Printf("Hello, World!")
})
cerr := capture.Stderr(func() { ... })

assert.Equal(cout.String(), "Hello, World!")

cout, cerr = capture.Both(func() { ... })

The captured content data also can be retrieved as bytes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Both

func Both(f func()) (Captured, Captured)

Both captures Stdout and Stderr.

Types

type Captured

type Captured struct {
	// contains filtered or unexported fields
}

Captured provides access to the captured output in multiple ways.

func Stderr

func Stderr(f func()) Captured

Stderr captures Stderr.

func Stdout

func Stdout(f func()) Captured

Stdout captures Stdout.

func (Captured) Bytes

func (c Captured) Bytes() []byte

Bytes returns the captured content as bytes.

func (Captured) Len

func (c Captured) Len() int

Len returns the number of captured bytes.

func (Captured) String

func (c Captured) String() string

String implements fmt.Stringer.

Jump to

Keyboard shortcuts

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