README

go-testcli

Go Reference

Go package containing helpers for testing CLIs.

Usage

Define your main function so that it matches the signature of testcli.MainFunc. In tests, call your main function using testcli.Main which will capture stdout, stderr, and the exit code. Use the other helper functions to create a working directory that suites the use cases that need testing.

For an example of this used in the wild, see the tests of gas.

Expand ▾ Collapse ▴

Documentation

Overview

    Define your main function so that it matches the signature of testcli.MainFunc. In tests, call your main function using testcli.Main which will capture stdout, stderr, and the exit code. Use the other helper functions to create a working directory that suites the use cases that need testing.

    For an example of this used in the wild, see the tests of gas: https://4d63.com/gas

    Index

    Constants

    This section is empty.

    Variables

    This section is empty.

    Functions

    This section is empty.

    Types

    type Helper

    type Helper struct {
    	TB testing.TB
    }

    func New

    func New(tb testing.TB) Helper

    func (Helper) Chdir

    func (h Helper) Chdir(dir string)

    func (Helper) Exec

    func (h Helper) Exec(command string) (exitCode int, stdout, stderr string)

    func (Helper) Main

    func (h Helper) Main(args []string, stdin io.Reader, main MainFunc) (exitCode int, stdout, stderr string)

    func (Helper) Mkdir

    func (h Helper) Mkdir(path string)

    func (Helper) MkdirTemp

    func (h Helper) MkdirTemp() string

    func (Helper) WriteFile

    func (h Helper) WriteFile(filename string, data []byte)

    type MainFunc

    type MainFunc func(args []string, stdin io.Reader, stdout, stderr io.Writer) int

    Source Files