expect

package
v2.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: Apache-2.0 Imports: 14 Imported by: 1

Documentation

Overview

Package expect is a tool for testing machine specifications.

You construct a Session, which has inputs and expected outputs. Then run the session to see if the expected outputs actually appeared.

Specifying what's expect can be simple, as in some literal output, or fairly fancy, as in code that computes some property.

This package also has support for delays, timeouts, and other time-driven behavior.

See ../../cmd/mexpect for command-line use.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IO

type IO struct {
	// Doc is an opaque documentation string.
	Doc string `json:"doc,omitempty" yaml:"doc,omitempty"`

	// WaitBefore is the time to wait before sending the first message.
	WaitBefore time.Duration `json:"waitBefore,omitempty" yaml:"waitBefore,omitempty"`

	// Waitbefore is the time to wait between sending messages.
	WaitBetween time.Duration `json:"waitBetween,omitempty" yaml:"waitBetween,omitempty"`

	// Inputs are the messages to send.
	Inputs []interface{} `json:"inputs,omitempty" yaml:"inputs,omitempty"`

	// WaitAfter is the time to wait after sending the last
	// message.
	WaitAfter time.Duration `json:"waitAfter,omitempty" yaml:"waitAfter,omitempty"`

	// OutputSet is the set (not a list) of outputs to verify.
	OutputSet []Output `json:"outputSet,omitempty" yaml:"outputSet,omitempty"`

	// Timeout is the optional timeout for this set.
	// Session.DefaultTimeout is the default value.
	Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty"`
}

IO is a package of input messages and required output message specifications.

This struct includes a list of messages to send and a set of expect output messages.

type Output

type Output struct {
	// Doc is an opaque documentation string.
	Doc string `json:"doc,omitempty" yaml:"doc,omitempty"`

	// Pattern must be matched by an emitted message.
	Pattern interface{} `json:"pattern,omitempty" yaml:"pattern,omitempty"`

	// Guard is an optional guard (as in a Machine spec) that is
	// called to execute procedural code to verify the bindings
	// after a match.
	Guard core.Action `json:"-" yaml:"-"`

	// GuardSource is optional source that will be compiled to the
	// Guard.
	GuardSource *core.ActionSource `json:"guard,omitempty" yaml:"guardSource,omitempty"`

	// Bindings, which is the result of a match (and optional
	// guard) is written during processing.  Just for diagnostics.
	Bindingss []match.Bindings `json:"bs,omitempty" yaml:"bs,omitempty"`

	// Inverted means that matching output isn't desired!
	Inverted bool `json:"inverted,omitempty" yaml:"inverted,omitempty"`
}

Output is a specification for a message that's expected.

type Session

type Session struct {
	// Doc is an opaque documentation string.
	Doc string `json:"doc,omitempty" yaml:"doc,omitempty"`

	// IOs is sequence of IOs that this session will run.
	IOs []IO `json:"ios" yaml:"ios"`

	// ParsePatterns will parse IO.OutputSet.Patterns as JSON.
	ParsePatterns bool `json:"parsePatterns,omitempty" yaml:"parsePatterns,omitempty"`

	// Interpreters are used (if necessary) to compile any
	// GuardSources.
	Interpreters core.InterpretersMap `json:"-" yaml:"-"`

	// DefaultTimeout is the default timeout for each IO.
	DefaultTimeout time.Duration `json:"defaultTimeout,omitempty" yaml:"defaultTimeout,omitempty"`

	// ShowStderr controls whether the subprocess's stderr is
	// logged.
	ShowStderr bool `json:"showStderr,omitempty" yaml:"showStderr,omitempty"`

	// ShowStdin controls whether the subprocess's stdin is
	// logged.
	ShowStdin bool `json:"showStdin,omitempty" yaml:"showStdin,omitempty"`

	// ShowStdout controls whether the subprocess's stdout is
	// logged.
	ShowStdout bool `json:"showStdout,omitempty" yaml:"showStdout,omitempty"`

	Verbose bool `json:"verbose,omitempty" yaml:"verbose,omitempty"`
}

Session is mostly a sequence of IOs.

func (*Session) Run

func (s *Session) Run(ctx context.Context, dir string, args ...string) error

Run processes all the IOs in the Session.

The current directory is changed to 'dir' (and then hopefully restored).

The subprocess is given by the args. The first arg is the executable. Example args:

"mcrew", "-v", "-s", "specs", "-d", "", "-I", "-O", "-h", ""

Jump to

Keyboard shortcuts

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