package evaltest
import (
)
const ApproximatelyThreshold = 1e-15
type Approximately struct{ F float64 }
func (, , float64) bool {
if math.IsNaN() && math.IsNaN() {
return true
}
if math.IsInf(, 0) && math.IsInf(, 0) &&
math.Signbit() == math.Signbit() {
return true
}
return math.Abs(-) <=
}
type MatchingRegexp struct{ Pattern string }
func (, string) bool {
, := regexp.MatchString(, )
if != nil {
panic()
}
return
}
type errorMatcher interface{ matchError(error) bool }
var AnyError = anyError{}
type anyError struct{}
func (anyError) () string { return "any error" }
func (anyError) ( error) bool { return != nil }
type exc struct {
reason error
stacks []string
}
func ( exc) () string {
if len(.stacks) == 0 {
return fmt.Sprintf("exception with reason %v", .reason)
}
return fmt.Sprintf("exception with reason %v and stacks %v", .reason, .stacks)
}
func ( exc) ( error) bool {
if , := .(eval.Exception); {
return matchErr(.reason, .Reason()) &&
(len(.stacks) == 0 ||
reflect.DeepEqual(.stacks, getStackTexts(.StackTrace())))
}
return false
}
func ( *eval.StackTrace) []string {
:= []string{}
for != nil {
:= .Head
= append(, .Source[.From:.To])
= .Next
}
return
}
func ( error) error { return errWithType{} }
type errWithType struct{ v error }
func ( errWithType) () string { return fmt.Sprintf("error with type %T", .v) }
func ( errWithType) ( error) bool {
return reflect.TypeOf(.v) == reflect.TypeOf()
}
func ( string) error { return errWithMessage{} }
type errWithMessage struct{ msg string }
func ( errWithMessage) () string { return "error with message " + .msg }
func ( errWithMessage) ( error) bool {
return != nil && .msg == .Error()
}
func ( eval.ExternalCmdExit) error { return errCmdExit{} }
type errCmdExit struct{ v eval.ExternalCmdExit }
func ( errCmdExit) () string {
return .v.Error()
}
func ( errCmdExit) ( error) bool {
if == nil {
return false
}
:= .(eval.ExternalCmdExit)
return .v.CmdName == .CmdName && .v.WaitStatus == .WaitStatus
}