fakestdio

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FakeStdOutErr

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

modified from: https://eli.thegreenplace.net/2020/faking-stdin-and-stdout-in-go/

FakeStdio can be used to fake stdin and capture stdout. Between creating a new FakeStdio and calling ReadAndRestore on it, code reading os.Stdin will get the contents of stdinText passed to New. Output to os.Stdout will be captured and returned from ReadAndRestore. FakeStdio is not reusable; don't attempt to use it after calling ReadAndRestore, but it should be safe to create a new FakeStdio.

func New

func New() (*FakeStdOutErr, error)

func (*FakeStdOutErr) ReadAndRestore

func (sf *FakeStdOutErr) ReadAndRestore() ([]byte, []byte, error)

ReadAndRestore collects all captured stdout and returns it; it also restores os.Stdin and os.Stdout to their original values.

Jump to

Keyboard shortcuts

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