aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/gotest.tools/assert/result.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-01-20 15:41:27 +0100
committerMichael Muré <batolettre@gmail.com>2019-03-01 22:40:22 +0100
commit14b240af8fef269d2c1d5dde2fff192b656c50f3 (patch)
tree4f6ea032789d811cd019bbb6c190c99a650084b2 /vendor/gotest.tools/assert/result.go
parentd10c76469d40f13e27739fd363145e89bf74c3e0 (diff)
downloadgit-bug-14b240af8fef269d2c1d5dde2fff192b656c50f3.tar.gz
identity: more cleaning and fixes after a code review
Diffstat (limited to 'vendor/gotest.tools/assert/result.go')
-rw-r--r--vendor/gotest.tools/assert/result.go107
1 files changed, 0 insertions, 107 deletions
diff --git a/vendor/gotest.tools/assert/result.go b/vendor/gotest.tools/assert/result.go
deleted file mode 100644
index 3900264d..00000000
--- a/vendor/gotest.tools/assert/result.go
+++ /dev/null
@@ -1,107 +0,0 @@
-package assert
-
-import (
- "fmt"
- "go/ast"
-
- "gotest.tools/assert/cmp"
- "gotest.tools/internal/format"
- "gotest.tools/internal/source"
-)
-
-func runComparison(
- t TestingT,
- argSelector argSelector,
- f cmp.Comparison,
- msgAndArgs ...interface{},
-) bool {
- if ht, ok := t.(helperT); ok {
- ht.Helper()
- }
- result := f()
- if result.Success() {
- return true
- }
-
- var message string
- switch typed := result.(type) {
- case resultWithComparisonArgs:
- const stackIndex = 3 // Assert/Check, assert, runComparison
- args, err := source.CallExprArgs(stackIndex)
- if err != nil {
- t.Log(err.Error())
- }
- message = typed.FailureMessage(filterPrintableExpr(argSelector(args)))
- case resultBasic:
- message = typed.FailureMessage()
- default:
- message = fmt.Sprintf("comparison returned invalid Result type: %T", result)
- }
-
- t.Log(format.WithCustomMessage(failureMessage+message, msgAndArgs...))
- return false
-}
-
-type resultWithComparisonArgs interface {
- FailureMessage(args []ast.Expr) string
-}
-
-type resultBasic interface {
- FailureMessage() string
-}
-
-// 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 filterPrintableExpr(args []ast.Expr) []ast.Expr {
- result := make([]ast.Expr, len(args))
- for i, arg := range args {
- if isShortPrintableExpr(arg) {
- result[i] = arg
- continue
- }
-
- if starExpr, ok := arg.(*ast.StarExpr); ok {
- result[i] = starExpr.X
- continue
- }
- result[i] = nil
- }
- return result
-}
-
-func isShortPrintableExpr(expr ast.Expr) bool {
- switch expr.(type) {
- case *ast.Ident, *ast.SelectorExpr, *ast.IndexExpr, *ast.SliceExpr:
- return true
- case *ast.BinaryExpr, *ast.UnaryExpr:
- return true
- default:
- // CallExpr, ParenExpr, TypeAssertExpr, KeyValueExpr, StarExpr
- return false
- }
-}
-
-type argSelector func([]ast.Expr) []ast.Expr
-
-func argsAfterT(args []ast.Expr) []ast.Expr {
- if len(args) < 1 {
- return nil
- }
- return args[1:]
-}
-
-func argsFromComparisonCall(args []ast.Expr) []ast.Expr {
- if len(args) < 1 {
- return nil
- }
- if callExpr, ok := args[1].(*ast.CallExpr); ok {
- return callExpr.Args
- }
- return nil
-}