tests

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanExecute

func CanExecute(v cmdr.Executor)

CanExecute fails the build if the thing passed does not implement the CanExecute interface.

func HasSubcommands

func HasSubcommands(v cmdr.Subcommander)

HasSubcommands fails the build if the thing passed does not implement the HasSubcommands interface.

Types

type Terminal

type Terminal struct {
	*cli.CLI
	Stdout, Stderr, Combined TestOutput
	History                  []string
	T                        *testing.T
}

Terminal is a test harness for the CLI, providing easy introspection into its inputs and outputs.

func NewTerminal

func NewTerminal(t *testing.T, vstr string) *Terminal

NewTerminal creates a new test terminal.

func (*Terminal) PrintFailureSummary

func (t *Terminal) PrintFailureSummary()

PrintFailureSummary prints the entire terminal session transcript if the failed. Otherwise, it does nothing.

func (*Terminal) RunCommand

func (t *Terminal) RunCommand(commandline string)

RunCommand takes a command line, turns it into args, and passes it to a CLI which is pre-populated with a fresh *cli.Sous command, OutWriter and ErrWriter, both mapped to Outputs for interrogation.

Note: This cannot cope with arguments containing spaces, even if they are surrounded by quotes. We should add this feature if we need it.

func (*Terminal) Summary

func (t *Terminal) Summary() string

Summary prints a summary of the session.

type TestOutput

type TestOutput struct {
	Name   string
	Buffer *bytes.Buffer
	T      *testing.T
}

TestOutput allows inspection of output streams from the Terminal.

func (TestOutput) HasLineMatching

func (out TestOutput) HasLineMatching(s string) bool

HasLineMatching returns true if one of the output lines exactly matches s.

func (TestOutput) Lines

func (out TestOutput) Lines() []string

Lines returns a slice of strings representing lines in the output.

func (TestOutput) LinesContaining

func (out TestOutput) LinesContaining(s string) []string

LinesContaining is similar to Lines, but filters lines based on if they have a substring matching s.

func (TestOutput) MostSimilarLineTo

func (out TestOutput) MostSimilarLineTo(s string) (
	winner string, index int, goodMatch bool)

MostSimilarLineTo returns the most similar line in the output to the given string, if any of them have a JaroWinkler score >0.1. It returns the string (or empty), the index of that line, and a bool indicating if the score was greater than 0.1

func (TestOutput) NumLines

func (out TestOutput) NumLines() int

NumLines returns the number of lines in the output.

func (TestOutput) ShouldHaveExactLine

func (out TestOutput) ShouldHaveExactLine(s string)

ShouldHaveExactLine fails the test if the output did not contain the line s.

func (TestOutput) ShouldHaveLineContaining

func (out TestOutput) ShouldHaveLineContaining(s string)

ShouldHaveLineContaining is similar to ShouldHaveExactLine but only requires that the line contain the substring s rather then being equal to s.

func (TestOutput) ShouldHaveNumLines

func (out TestOutput) ShouldHaveNumLines(expected int)

ShouldHaveNumLines fails the test if the output does not have expected lines.

func (TestOutput) String

func (out TestOutput) String() string

Jump to

Keyboard shortcuts

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