package assertimport ()// RunComparison and return Comparison.Success. If the comparison fails a messages// will be printed using t.Log.func (LogT,argSelector,cmp.Comparison, ...interface{},) bool {if , := .(helperT); { .Helper() } := ()if .Success() {returntrue }ifsource.Update {if , := .(updateExpected); {const = 3// Assert/Check, assert, RunComparison := .UpdatedExpected()switch {case == nil:returntruecaseerrors.Is(, source.ErrNotFound):// do nothing, fallthrough to regular failure messagedefault: .Log("failed to update source", )returnfalse } } }varstringswitch typed := .(type) {caseresultWithComparisonArgs:const = 3// Assert/Check, assert, RunComparison , := source.CallExprArgs()if != nil { .Log(.Error()) } = .FailureMessage(filterPrintableExpr(()))caseresultBasic: = .FailureMessage()default: = fmt.Sprintf("comparison returned invalid Result type: %T", ) } .Log(format.WithCustomMessage(failureMessage+, ...))returnfalse}typeresultWithComparisonArgsinterface {FailureMessage(args []ast.Expr) string}typeresultBasicinterface {FailureMessage() string}typeupdateExpectedinterface {UpdatedExpected(stackIndex int) error}// filterPrintableExpr filters the ast.Expr slice to only include Expr that are// easy to read when printed and contain relevant information to an assertion.//// Ident and SelectorExpr are included because they print nicely and the variable// names may provide additional context to their values.// BasicLit and CompositeLit are excluded because their source is equivalent to// their value, which is already available.// Other types are ignored for now, but could be added if they are relevant.func ( []ast.Expr) []ast.Expr { := make([]ast.Expr, len())for , := range {ifisShortPrintableExpr() { [] = continue }if , := .(*ast.StarExpr); { [] = .Xcontinue } }return}func ( ast.Expr) bool {switch .(type) {case *ast.Ident, *ast.SelectorExpr, *ast.IndexExpr, *ast.SliceExpr:returntruecase *ast.BinaryExpr, *ast.UnaryExpr:returntruedefault:// CallExpr, ParenExpr, TypeAssertExpr, KeyValueExpr, StarExprreturnfalse }}typeargSelectorfunc([]ast.Expr) []ast.Expr// ArgsAfterT selects args starting at position 1. Used when the caller has a// testing.T as the first argument, and the args to select should follow it.func ( []ast.Expr) []ast.Expr {iflen() < 1 {returnnil }return [1:]}// ArgsFromComparisonCall selects args from the CallExpression at position 1.// Used when the caller has a testing.T as the first argument, and the args to// select are passed to the cmp.Comparison at position 1.func ( []ast.Expr) []ast.Expr {iflen() <= 1 {returnnil }if , := [1].(*ast.CallExpr); {return .Args }returnnil}// ArgsAtZeroIndex selects args from the CallExpression at position 1.// Used when the caller accepts a single cmp.Comparison argument.func ( []ast.Expr) []ast.Expr {iflen() == 0 {returnnil }if , := [0].(*ast.CallExpr); {return .Args }returnnil}
The pages are generated with Goldsv0.4.9. (GOOS=linux GOARCH=amd64)