Skip to content

Commit

Permalink
Merge pull request #5808 from thaJeztah/bump_gotest_tools
Browse files Browse the repository at this point in the history
vendor: gotest.tools/v3 v3.5.2
  • Loading branch information
thaJeztah authored Feb 10, 2025
2 parents 3560bdd + df8c19d commit bca1f17
Show file tree
Hide file tree
Showing 12 changed files with 105 additions and 45 deletions.
5 changes: 1 addition & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,7 @@ issues:
- text: "package-comments: should have a package comment"
linters:
- revive
# FIXME temporarily suppress these (see https://github.com/gotestyourself/gotest.tools/issues/272)
- text: "SA1019: (assert|cmp|is)\\.ErrorType is deprecated"
linters:
- staticcheck

# Exclude some linters from running on tests files.
- path: _test\.go
linters:
Expand Down
2 changes: 1 addition & 1 deletion vendor.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ require (
golang.org/x/term v0.27.0
golang.org/x/text v0.21.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools/v3 v3.5.1
gotest.tools/v3 v3.5.2
tags.cncf.io/container-device-interface v0.8.0
)

Expand Down
4 changes: 2 additions & 2 deletions vendor.sum
Original file line number Diff line number Diff line change
Expand Up @@ -399,8 +399,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
tags.cncf.io/container-device-interface v0.8.0 h1:8bCFo/g9WODjWx3m6EYl3GfUG31eKJbaggyBDxEldRc=
Expand Down
2 changes: 0 additions & 2 deletions vendor/gotest.tools/v3/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,6 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
// must be called from the goroutine running the test function, not from other
// goroutines created during the test. Use [Check] with [cmp.ErrorType] from other
// goroutines.
//
// Deprecated: Use [ErrorIs]
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
if ht, ok := t.(helperT); ok {
ht.Helper()
Expand Down
5 changes: 2 additions & 3 deletions vendor/gotest.tools/v3/assert/cmp/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type causer interface {
}

func formatErrorMessage(err error) string {
//nolint:errorlint // unwrapping is not appropriate here
//nolint:errorlint,nolintlint // unwrapping is not appropriate here
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
Expand Down Expand Up @@ -286,6 +286,7 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
}

// ErrorType succeeds if err is not nil and is of the expected type.
// New code should use [ErrorIs] instead.
//
// Expected can be one of:
//
Expand All @@ -306,8 +307,6 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
// reflect.Type
//
// Fails if err does not implement the [reflect.Type].
//
// Deprecated: Use [ErrorIs]
func ErrorType(err error, expected interface{}) Comparison {
return func() Result {
switch expectedType := expected.(type) {
Expand Down
4 changes: 2 additions & 2 deletions vendor/gotest.tools/v3/fs/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem {
return problem(fmt.Sprintf("%s: %s", reason, err))
}

func existenceProblem(filename, reason string, args ...interface{}) problem {
return problem(filename + ": " + fmt.Sprintf(reason, args...))
func existenceProblem(filename string, msgAndArgs ...interface{}) problem {
return problem(filename + ": " + format.Message(msgAndArgs...))
}

func eqResource(x, y resource) []problem {
Expand Down
17 changes: 8 additions & 9 deletions vendor/gotest.tools/v3/internal/assert/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,18 @@ func logFailureFromBool(t LogT, msgAndArgs ...interface{}) {
args, err := source.CallExprArgs(stackIndex)
if err != nil {
t.Log(err.Error())
return
}

var msg string
const comparisonArgIndex = 1 // Assert(t, comparison)
if len(args) <= comparisonArgIndex {
t.Log(failureMessage + "but assert failed to find the expression to print")
return
}

msg, err := boolFailureMessage(args[comparisonArgIndex])
if err != nil {
t.Log(err.Error())
msg = "expression is false"
msg = "but assert failed to find the expression to print"
} else {
msg, err = boolFailureMessage(args[comparisonArgIndex])
if err != nil {
t.Log(err.Error())
msg = "expression is false"
}
}

t.Log(format.WithCustomMessage(failureMessage+msg, msgAndArgs...))
Expand Down
30 changes: 17 additions & 13 deletions vendor/gotest.tools/v3/internal/difflib/difflib.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
/*Package difflib is a partial port of Python difflib module.
/*
Package difflib is a partial port of Python difflib module.
Original source: https://github.com/pmezard/go-difflib
This file is trimmed to only the parts used by this repository.
*/
package difflib // import "gotest.tools/v3/internal/difflib"

func min(a, b int) int {
func minInt(a, b int) int {
if a < b {
return a
}
return b
}

func max(a, b int) int {
func maxInt(a, b int) int {
if a > b {
return a
}
Expand Down Expand Up @@ -170,12 +171,15 @@ func (m *SequenceMatcher) isBJunk(s string) bool {
// If IsJunk is not defined:
//
// Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
// alo <= i <= i+k <= ahi
// blo <= j <= j+k <= bhi
//
// alo <= i <= i+k <= ahi
// blo <= j <= j+k <= bhi
//
// and for all (i',j',k') meeting those conditions,
// k >= k'
// i <= i'
// and if i == i', j <= j'
//
// k >= k'
// i <= i'
// and if i == i', j <= j'
//
// In other words, of all maximal matching blocks, return one that
// starts earliest in a, and of all those maximal matching blocks that
Expand Down Expand Up @@ -393,12 +397,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
if codes[0].Tag == 'e' {
c := codes[0]
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
codes[0] = OpCode{c.Tag, max(i1, i2-n), i2, max(j1, j2-n), j2}
codes[0] = OpCode{c.Tag, maxInt(i1, i2-n), i2, maxInt(j1, j2-n), j2}
}
if codes[len(codes)-1].Tag == 'e' {
c := codes[len(codes)-1]
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
codes[len(codes)-1] = OpCode{c.Tag, i1, min(i2, i1+n), j1, min(j2, j1+n)}
codes[len(codes)-1] = OpCode{c.Tag, i1, minInt(i2, i1+n), j1, minInt(j2, j1+n)}
}
nn := n + n
groups := [][]OpCode{}
Expand All @@ -408,11 +412,11 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
// End the current group and start a new one whenever
// there is a large range with no changes.
if c.Tag == 'e' && i2-i1 > nn {
group = append(group, OpCode{c.Tag, i1, min(i2, i1+n),
j1, min(j2, j1+n)})
group = append(group, OpCode{c.Tag, i1, minInt(i2, i1+n),
j1, minInt(j2, j1+n)})
groups = append(groups, group)
group = []OpCode{}
i1, j1 = max(i1, i2-n), max(j1, j2-n)
i1, j1 = maxInt(i1, i2-n), maxInt(j1, j2-n)
}
group = append(group, OpCode{c.Tag, i1, i2, j1, j2})
}
Expand Down
51 changes: 51 additions & 0 deletions vendor/gotest.tools/v3/internal/source/bazel.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package source

import (
"fmt"
"os"
"path/filepath"
)

// These Bazel env vars are documented here:
// https://bazel.build/reference/test-encyclopedia

// Signifies test executable is being driven by `bazel test`.
//
// Due to Bazel's compilation and sandboxing strategy,
// some care is required to handle resolving the original *.go source file.
var inBazelTest = os.Getenv("BAZEL_TEST") == "1"

// The name of the target being tested (ex: //some_package:some_package_test)
var bazelTestTarget = os.Getenv("TEST_TARGET")

// Absolute path to the base of the runfiles tree
var bazelTestSrcdir = os.Getenv("TEST_SRCDIR")

// The local repository's workspace name (ex: __main__)
var bazelTestWorkspace = os.Getenv("TEST_WORKSPACE")

func bazelSourcePath(filename string) (string, error) {
// Use the env vars to resolve the test source files,
// which must be provided as test data in the respective go_test target.
filename = filepath.Join(bazelTestSrcdir, bazelTestWorkspace, filename)

_, err := os.Stat(filename)
if os.IsNotExist(err) {
return "", fmt.Errorf(bazelMissingSourceMsg, filename, bazelTestTarget)
}
return filename, nil
}

var bazelMissingSourceMsg = `
the test source file does not exist: %s
It appears that you are running this test under Bazel (target: %s).
Check that your test source files are added as test data in your go_test targets.
Example:
go_test(
name = "your_package_test",
srcs = ["your_test.go"],
deps = ["@tools_gotest_v3//assert"],
data = glob(["*_test.go"])
)"
`
23 changes: 17 additions & 6 deletions vendor/gotest.tools/v3/internal/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"go/parser"
"go/token"
"os"
"path/filepath"
"runtime"
)

Expand All @@ -35,6 +36,19 @@ func CallExprArgs(stackIndex int) ([]ast.Expr, error) {
}
debug("call stack position: %s:%d", filename, line)

// Normally, `go` will compile programs with absolute paths in
// the debug metadata. However, in the name of reproducibility,
// Bazel uses a compilation strategy that results in relative paths
// (otherwise, since Bazel uses a random tmp dir for compile and sandboxing,
// the resulting binaries would change across compiles/test runs).
if inBazelTest && !filepath.IsAbs(filename) {
var err error
filename, err = bazelSourcePath(filename)
if err != nil {
return nil, err
}
}

fileset := token.NewFileSet()
astFile, err := parser.ParseFile(fileset, filename, nil, parser.AllErrors)
if err != nil {
Expand All @@ -58,7 +72,7 @@ func getNodeAtLine(fileset *token.FileSet, astFile ast.Node, lineNum int) (ast.N
return node, err
}
}
return nil, nil
return nil, errors.New("failed to find expression")
}

func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node {
Expand All @@ -78,19 +92,16 @@ func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node {

func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast.Expr, error) {
node, err := getNodeAtLine(fileset, astFile, line)
switch {
case err != nil:
if err != nil {
return nil, err
case node == nil:
return nil, fmt.Errorf("failed to find an expression")
}

debug("found node: %s", debugFormatNode{node})

visitor := &callExprVisitor{}
ast.Walk(visitor, node)
if visitor.expr == nil {
return nil, errors.New("failed to find call expression")
return nil, errors.New("failed to find an expression")
}
debug("callExpr: %s", debugFormatNode{visitor.expr})
return visitor.expr.Args, nil
Expand Down
5 changes: 3 additions & 2 deletions vendor/gotest.tools/v3/poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/assert"
"gotest.tools/v3/internal/format"
)

// TestingT is the subset of [testing.T] used by [WaitOn]
Expand Down Expand Up @@ -90,7 +91,7 @@ func (r result) Error() error {
// polling. The message text will be used as the failure message if the timeout
// is reached.
func Continue(message string, args ...interface{}) Result {
return result{message: fmt.Sprintf(message, args...)}
return result{message: format.Message(append([]interface{}{message}, args...)...)}
}

// Success returns a [Result] where Done() returns true, which indicates to [WaitOn]
Expand Down Expand Up @@ -151,7 +152,7 @@ func Compare(compare cmp.Comparison) Result {
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
return Success()
}
return Continue(buf.String())
return Continue("%v", buf.String())
}

type logBuffer struct {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ google.golang.org/protobuf/types/known/wrapperspb
# gopkg.in/yaml.v3 v3.0.1
## explicit
gopkg.in/yaml.v3
# gotest.tools/v3 v3.5.1
# gotest.tools/v3 v3.5.2
## explicit; go 1.17
gotest.tools/v3/assert
gotest.tools/v3/assert/cmp
Expand Down

0 comments on commit bca1f17

Please sign in to comment.