Documentation
¶
Overview ¶
Package assertion is the implementation detail of package assert. One can use API to create a customized assert function with this package
Index ¶
- func Assert(t *testing.T, expr interface{}, trigger *Trigger)
- func AssertEqual(t *testing.T, v1, v2 interface{}, trigger *Trigger)
- func AssertNilError(t *testing.T, result []interface{}, trigger *Trigger)
- func AssertNonNilError(t *testing.T, result []interface{}, trigger *Trigger)
- func AssertNotEqual(t *testing.T, v1, v2 interface{}, trigger *Trigger)
- func IsIncluded(parent, child string) bool
- func IsVar(expr ast.Expr) bool
- type FalseKind
- type Func
- type Info
- type Parser
- type Trigger
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Assert ¶
Assert tests expr and call `t.Fatalf` to terminate test case if expr is false-equivalent value.
func AssertEqual ¶
AssertEqual uses `reflect.DeepEqual` to test v1 and v2 equality.
func AssertNilError ¶
AssertNilError expects a function return a nil error. Otherwise, it will terminate the test case using `t.Fatalf`.
func AssertNonNilError ¶
AssertNonNilError expects a function return a non-nil error. Otherwise, it will terminate the test case using `t.Fatalf`.
func AssertNotEqual ¶
AssertNotEqual uses `reflect.DeepEqual` to test v1 and v2 equality.
func IsIncluded ¶ added in v1.1.0
IsIncluded checks whether child var is a children of parent var. Regarding the child var `a.b.c`, it's the children of `a`, `a.b` and `a.b.c`.
Types ¶
type FalseKind ¶
type FalseKind int
FalseKind is the kind of a false-equivalent value.
Valid kinds for all false-equivalent values.
func ParseFalseKind ¶
func ParseFalseKind(expr interface{}) FalseKind
ParseFalseKind checks expr value and return false when expr is `false`, 0, `nil` and empty string. Otherwise, return true.
type Func ¶ added in v1.1.0
type Func struct { FileSet *token.FileSet Func *ast.FuncDecl Caller *ast.CallExpr Args []ast.Expr Filename string Line int }
Func represents AST information of an assertion function.
type Info ¶ added in v1.1.0
type Info struct { Source string // Source code of the caller. Args []string // Selected arguments. // The last assignments related to Args. // The len(Assignments) is guaranteed to be the same as len(Args). Assignments [][]string // RelatedVars is the list of variables which are referenced in argument expression // or in the assignment statements containing arguments. // For instance, consider following code. // // for i, c := range cases { // a := 1 // Assert(t, a+1 == c.Value) // } // // After parsing `Assert`, RelatedVars contains `a`, `c.Value` and `i`. // Note that, `i` is listed in related vars because of the value of `i` is assigned in // `i, c := range cases` in which `c` is also assigned. RelatedVars []string }
Info represents code analysis information of an assertion function.
type Parser ¶ added in v1.1.4
type Parser struct {
// contains filtered or unexported fields
}
Parser represents a source file parser.
func (*Parser) AddExcluded ¶ added in v1.1.4
AddExcluded adds an expr to excluded expr list so that this expr will not be inspected when finding related assignments.
func (*Parser) ParseArgs ¶ added in v1.1.4
ParseArgs parses caller's source code, finds out the right call expression by name and returns the argument source AST.
Skip is the stack frame calling an assert function. If skip is 0, the stack frame for ParseArgs is selected. In most cases, caller should set skip to 1 to skip ParseArgs itself.