Documentation ¶
Overview ¶
Package evaltest provides a framework for testing Elvish script.
The entry point for the framework is the Test function, which accepts a *testing.T and any number of test cases.
Test cases are constructed using the That function, followed by method calls that add additional information to it.
Example:
Test(t, That("put x").Puts("x"), That("echo x").Prints("x\n"))
If some setup is needed, use the TestWithSetup function instead.
Index ¶
- Constants
- func CmdExit(v eval.ExternalCmdExit) error
- func ErrorWithMessage(msg string) error
- func ErrorWithType(v error) error
- func OneOfErrors(errs ...error) error
- func Test(t *testing.T, tests ...Case)
- func TestWithSetup(t *testing.T, setup func(*eval.Evaler), tests ...Case)
- type Approximately
- type Case
- func (c Case) DoesNotCompile() Case
- func (c Case) DoesNothing() Case
- func (c Case) Passes(f func(t *testing.T)) Case
- func (c Case) Prints(s string) Case
- func (c Case) PrintsStderrWith(s string) Case
- func (c Case) Puts(vs ...interface{}) Case
- func (c Case) Then(lines ...string) Case
- func (c Case) Throws(reason error, stacks ...string) Case
- func (c Case) WithSetup(f func(*eval.Evaler)) Case
- type MatchingRegexp
Constants ¶
const ApproximatelyThreshold = 1e-15
ApproximatelyThreshold defines the threshold for matching float64 values when using Approximately.
Variables ¶
This section is empty.
Functions ¶
func CmdExit ¶
func CmdExit(v eval.ExternalCmdExit) error
CmdExit returns an error that can be passed to Case.Throws to match an eval.ExternalCmdExit ignoring the Pid field.
func ErrorWithMessage ¶
ErrorWithMessage returns an error that can be passed to Case.Throws to match any error with the given message.
func ErrorWithType ¶
ErrorWithType returns an error that can be passed to the Case.Throws to match any error with the same type as the argument.
func OneOfErrors ¶
Types ¶
type Approximately ¶
type Approximately struct{ F float64 }
Approximately can be passed to Case.Puts to match a float64 within the threshold defined by ApproximatelyThreshold.
type Case ¶
type Case struct {
// contains filtered or unexported fields
}
Case is a test case that can be used in Test.
func That ¶
That returns a new Case 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.
When combined with subsequent method calls, a test case reads like English. For example, a test for the fact that "put x" puts "x" reads:
That("put x").Puts("x")
func (Case) DoesNotCompile ¶
DoesNotCompile returns an altered Case that requires the source code to fail compilation.
func (Case) DoesNothing ¶
DoesNothing returns t unchanged. It is useful to mark tests that don't have any side effects, for example:
That("nop").DoesNothing()
func (Case) Prints ¶
Prints returns an altered Case that requires the source code to produce the specified output in the byte pipe when evaluated.
func (Case) PrintsStderrWith ¶
PrintsStderrWith returns an altered Case that requires the stderr output to contain the given text.
func (Case) Puts ¶
Puts returns an altered Case that requires the source code to produce the specified values in the value channel when evaluated.
func (Case) Then ¶
Then returns a new Case that executes the given code in addition. Multiple arguments are joined with newlines.
func (Case) Throws ¶
Throws returns an altered Case 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.
type MatchingRegexp ¶
type MatchingRegexp struct{ Pattern string }
MatchingRegexp can be passed to Case.Puts to match a any string that matches a regexp pattern. If the pattern is not a valid regexp, the test will panic.