evaltest

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2021 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const ApproximatelyThreshold = 1e-15

ApproximatelyThreshold defines the threshold for matching float64 values when using Approximately.

Variables

View Source
var AnyError = anyError{}

AnyError is an error that can be passed to TestCase.Throws to match any non-nil error.

Functions

func CmdExit

func CmdExit(v eval.ExternalCmdExit) error

CmdExit returns an error that can be passed to TestCase.Throws to match an eval.ExternalCmdExit ignoring the Pid field.

func ErrorWithMessage

func ErrorWithMessage(msg string) error

ErrorWithMessage returns an error that can be passed to TestCase.Throws to match any error with the given message.

func ErrorWithType

func ErrorWithType(v error) error

ErrorWithType returns an error that can be passed to the TestCase.Throws to match any error with the same type as the argument.

func Test

func Test(t *testing.T, tests ...TestCase)

Test runs test cases. For each test case, a new Evaler is created with NewEvaler.

func TestWithSetup

func TestWithSetup(t *testing.T, setup func(*eval.Evaler), tests ...TestCase)

TestWithSetup runs test cases. For each test case, a new Evaler is created with NewEvaler and passed to the setup function.

Types

type Approximately

type Approximately struct{ F float64 }

Approximately can be passed to TestCase.Puts to match a float64 within the threshold defined by ApproximatelyThreshold.

type Result

type Result struct {
	ValueOut  []interface{}
	BytesOut  []byte
	StderrOut []byte

	CompilationError error
	Exception        error
}

type TestCase

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

TestCase is a test case for Test.

func That

func That(lines ...string) TestCase

That returns a new Test with the specified source code. Multiple arguments are joined with newlines. To specify multiple pieces of code that are executed separately, use the Then method to append code pieces.

func (TestCase) DoesNotCompile

func (t TestCase) DoesNotCompile() TestCase

DoesNotCompile returns an altered TestCase that requires the source code to fail compilation.

func (TestCase) DoesNothing

func (t TestCase) DoesNothing() TestCase

DoesNothing returns t unchanged. It is used to mark that a piece of code should simply does nothing. In particular, it shouldn't have any output and does not error.

func (TestCase) Prints

func (t TestCase) Prints(s string) TestCase

Prints returns an altered TestCase that requires the source code to produce the specified output in the byte pipe when evaluated.

func (TestCase) PrintsStderrWith

func (t TestCase) PrintsStderrWith(s string) TestCase

PrintsStderrWith returns an altered TestCase that requires the stderr output to contain the given text.

func (TestCase) Puts

func (t TestCase) Puts(vs ...interface{}) TestCase

Puts returns an altered TestCase that requires the source code to produce the specified values in the value channel when evaluated.

func (TestCase) Then

func (t TestCase) Then(lines ...string) TestCase

Then returns a new Test that executes the given code in addition. Multiple arguments are joined with newlines.

func (TestCase) Throws

func (t TestCase) Throws(reason error, stacks ...string) TestCase

Throws returns an altered TestCase that requires the source code to throw an exception with the given reason. The reason supports special matcher values constructed by functions like ErrorWithMessage.

If at least one stacktrace string is given, the exception must also have a stacktrace matching the given source fragments, frame by frame (innermost frame first). If no stacktrace string is given, the stack trace of the exception is not checked.

Jump to

Keyboard shortcuts

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