testexec

package module
v0.0.0-...-87984e6 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: MIT Imports: 13 Imported by: 0

README

testexec

Go Report Card Go Reference

Run subprocess tests for Go.

How to use

Setup code:

func TestMain(m *testing.M) {
	testexec.Main(m)
}

Add subprocess program:

var flagProgram = testexec.NewProgram(func(t *testexec.T, in int, out *int) {
	var f = flag.Int("data", 1, "")
	flag.Parse()
	*out = in + *f
})

Add test:

func TestFlag(t *testing.T) {
	var i int
	testexec.Run(t, flagProgram, 12, &i, "--data=123")
	assert.Equal(t, 135, i)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Main

func Main(m *testing.M)

func Run

func Run[In, Out any](t testing.TB, prg ProgramHandle[In, Out], req In, resp Out, args ...string)

Types

type Cmd

type Cmd struct {
	*exec.Cmd
	// contains filtered or unexported fields
}

func Command

func Command[In, Out any](t testing.TB, prg ProgramHandle[In, Out], req In, resp Out, args ...string) *Cmd

func CommandContext

func CommandContext[In, Out any](t testing.TB, prg ProgramHandle[In, Out], ctx context.Context, req In, resp Out, args ...string) *Cmd

func (*Cmd) Run

func (c *Cmd) Run() error

func (*Cmd) Wait

func (c *Cmd) Wait() error

type Nil

type Nil chan struct {
	// contains filtered or unexported fields
}

type ProgramHandle

type ProgramHandle[In any, Out any] string

func NewProgram

func NewProgram[In any, Out any](f func(*T, In, Out), opts ...ProgramOption) ProgramHandle[In, Out]

type ProgramOption

type ProgramOption func(*options)

func WithName

func WithName(name string) ProgramOption

type T

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

func (*T) Errorf

func (t *T) Errorf(format string, args ...interface{})

Jump to

Keyboard shortcuts

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