cram

package module
v0.0.0-...-7f6a16c Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2016 License: MIT Imports: 11 Imported by: 0

README

Cram: Command-Line Functional Test Framework

Shippable

This is a Go port of the Python-based Cram command-line test framework. Cram makes it easy to test command-line programs by recording commands with their expected output.

Status

This project is still under development and should probably not be used in a production setting.

The project is a learning tool for me to become familiar with the Go language. I would therefore prefer to experiment and implement the basic functionality myself. However, feel free to report bugs for any issues you might find. Thanks! —Martin Geisler

Documentation

There is currently no real documentation, but please take a look at the Cram test suite. The test files serve as a a simple form of documentation as well as a regression test suite.

License

Cram is licensed under the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DropEol

func DropEol(s string) string

DropEol removes a final end-of-line from s. It removes both Unix ("\n") and DOS ("\r\n") end-of-line characters.

func Escape

func Escape(s string) string

Escape quotes non-printable characters in s with a backslash. If anything was changed, " (esc)" is added to the result. A final newline in s (if any) is kept unescaped.

func ExecuteScript

func ExecuteScript(workdir string, env []string, lines []string) ([]byte, error)

Execute a script in the specified working directory.

func MakeBanner

func MakeBanner(u uuid.UUID) string

MakeBanner turns a UUID into a nice banner we can recognize later in the output.

func MakeEnvironment

func MakeEnvironment(path string) ([]string, error)

MakeEnvironment prepares the environment to be used when executing the test in the given path. It currently sets TESTDIR to the dirname of path.

func MakeScript

func MakeScript(cmds []Command, banner string) (lines []string)

MakeScript produces a script ready to be sent to a shell. The banner should be a random string. It will be inserted in the output together with the exit status of each command.

func Patch

func Patch(r io.Reader, w io.Writer, cmds []ExecutedCommand) (err error)

Patch takes an ExecutedTest, a slice ExecutedCommands and returns the patched output where ActualOutput from each ExecutedCommand replaces the ExpectedOutput.

func Unescape

func Unescape(s string) (string, error)

Unescape is the inverse of Escape. It decodes escaped characters such as \t, \x01, etc in s if s ends with escSuffix.

Types

type Command

type Command struct {
	CmdLine          string   // Command line passed to the shell.
	ExpectedOutput   []string // Expected output lines.
	ExpectedExitCode int      // Expected exit code.
	Lineno           int      // Line number of first output line.
}

type Env

type Env map[string]string

type ExecutedCommand

type ExecutedCommand struct {
	*Command                // Command responsible for the output.
	ActualOutput   []string // Actual output read from stdout and stderr.
	ActualExitCode int      // Exit code.
}

func ParseOutput

func ParseOutput(cmds []Command, output []byte, banner string) (
	executed []ExecutedCommand, err error)

ParseOutput finds the actual output and exit codes for a slice of commands. The result is a slice of executed commands. The actual output is normalized, meaning that a missing final EOL in the output is represented as noEolSuffix.

type ExecutedTest

type ExecutedTest struct {
	Test
	ExecutedCmds []ExecutedCommand // All executed commands.
	Script       string            // The script passed to the shell.
	Failures     []ExecutedCommand // Failed commands.
}

ExecutedTest captures the executed commands, the script sent to the shell and the failed commands. The Test struct is embedded as a value instead of pointer to make the zero value for ExecutedTest immediatedly useful.

func Process

func Process(tempdir, path string, idx int) (result ExecutedTest, err error)

Process parses a .t file, executes the test commands and compares the actual output to the expected output. The idx passed is used to make the working directory unique inside tempdir and must be different for each test file.

type InvalidTestError

type InvalidTestError struct {
	Path   string // Path to test file.
	Lineno int    // Line number of failure
	Msg    string // Error message
}

func (*InvalidTestError) Error

func (e *InvalidTestError) Error() string

type Test

type Test struct {
	Path string    // Path to test file.
	Cmds []Command // Commands.
}

func ParseTest

func ParseTest(r io.Reader, path string) (test Test, err error)

Parse splits an input test file into Commands.

Directories

Path Synopsis
cmd
fuzz

Jump to

Keyboard shortcuts

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