From 0f950f83323011e9af4201705642e49b488c35a6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Feb 2025 14:20:51 +0000 Subject: [PATCH] Bump gotest.tools/v3 from 3.5.1 to 3.5.2 Bumps [gotest.tools/v3](https://github.com/gotestyourself/gotest.tools) from 3.5.1 to 3.5.2. - [Release notes](https://github.com/gotestyourself/gotest.tools/releases) - [Commits](https://github.com/gotestyourself/gotest.tools/compare/v3.5.1...v3.5.2) --- updated-dependencies: - dependency-name: gotest.tools/v3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- go.mod | 2 +- go.sum | 4 +- vendor/gotest.tools/v3/assert/assert.go | 2 - vendor/gotest.tools/v3/assert/cmp/compare.go | 5 +- vendor/gotest.tools/v3/fs/report.go | 4 +- .../gotest.tools/v3/internal/assert/assert.go | 17 +++---- .../v3/internal/difflib/difflib.go | 30 ++++++----- .../gotest.tools/v3/internal/source/bazel.go | 51 +++++++++++++++++++ .../gotest.tools/v3/internal/source/source.go | 23 ++++++--- vendor/modules.txt | 2 +- 10 files changed, 101 insertions(+), 39 deletions(-) create mode 100644 vendor/gotest.tools/v3/internal/source/bazel.go diff --git a/go.mod b/go.mod index 999dcf128b..a178334322 100644 --- a/go.mod +++ b/go.mod @@ -34,7 +34,7 @@ require ( go.uber.org/zap v1.27.0 golang.org/x/term v0.29.0 gotest.tools v2.2.0+incompatible - gotest.tools/v3 v3.5.1 + gotest.tools/v3 v3.5.2 k8s.io/api v0.31.5 k8s.io/apimachinery v0.31.5 k8s.io/cli-runtime v0.29.13 diff --git a/go.sum b/go.sum index 43bfffbe31..a5c9db0186 100644 --- a/go.sum +++ b/go.sum @@ -2080,8 +2080,8 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= gotest.tools/v3 v3.0.3/go.mod h1:Z7Lb0S5l+klDB31fvDQX8ss/FlKDxtlFlw3Oa8Ymbl8= -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= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/vendor/gotest.tools/v3/assert/assert.go b/vendor/gotest.tools/v3/assert/assert.go index c418bd07b5..ae62cefec1 100644 --- a/vendor/gotest.tools/v3/assert/assert.go +++ b/vendor/gotest.tools/v3/assert/assert.go @@ -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() diff --git a/vendor/gotest.tools/v3/assert/cmp/compare.go b/vendor/gotest.tools/v3/assert/cmp/compare.go index 118844f35d..a7507e6591 100644 --- a/vendor/gotest.tools/v3/assert/cmp/compare.go +++ b/vendor/gotest.tools/v3/assert/cmp/compare.go @@ -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) } @@ -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: // @@ -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) { diff --git a/vendor/gotest.tools/v3/fs/report.go b/vendor/gotest.tools/v3/fs/report.go index 952aa26ad3..773df21c1a 100644 --- a/vendor/gotest.tools/v3/fs/report.go +++ b/vendor/gotest.tools/v3/fs/report.go @@ -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 { diff --git a/vendor/gotest.tools/v3/internal/assert/assert.go b/vendor/gotest.tools/v3/internal/assert/assert.go index 2dd80255ab..1e8727682c 100644 --- a/vendor/gotest.tools/v3/internal/assert/assert.go +++ b/vendor/gotest.tools/v3/internal/assert/assert.go @@ -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...)) diff --git a/vendor/gotest.tools/v3/internal/difflib/difflib.go b/vendor/gotest.tools/v3/internal/difflib/difflib.go index 9bf506b6be..bedacca3e5 100644 --- a/vendor/gotest.tools/v3/internal/difflib/difflib.go +++ b/vendor/gotest.tools/v3/internal/difflib/difflib.go @@ -1,4 +1,5 @@ -/*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 @@ -6,14 +7,14 @@ 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 } @@ -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 @@ -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{} @@ -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}) } diff --git a/vendor/gotest.tools/v3/internal/source/bazel.go b/vendor/gotest.tools/v3/internal/source/bazel.go new file mode 100644 index 0000000000..1f5197ddfc --- /dev/null +++ b/vendor/gotest.tools/v3/internal/source/bazel.go @@ -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"]) + )" +` diff --git a/vendor/gotest.tools/v3/internal/source/source.go b/vendor/gotest.tools/v3/internal/source/source.go index a4fc24ee63..9ac4bfa7d1 100644 --- a/vendor/gotest.tools/v3/internal/source/source.go +++ b/vendor/gotest.tools/v3/internal/source/source.go @@ -10,6 +10,7 @@ import ( "go/parser" "go/token" "os" + "path/filepath" "runtime" ) @@ -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 { @@ -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 { @@ -78,11 +92,8 @@ 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}) @@ -90,7 +101,7 @@ func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast. 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 diff --git a/vendor/modules.txt b/vendor/modules.txt index 00748d36ea..edb17439a7 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -2292,7 +2292,7 @@ gotest.tools/assert/cmp gotest.tools/internal/difflib gotest.tools/internal/format gotest.tools/internal/source -# 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