Skip to content

Commit bca1f17

Browse files
authored
Merge pull request #5808 from thaJeztah/bump_gotest_tools
vendor: gotest.tools/v3 v3.5.2
2 parents 3560bdd + df8c19d commit bca1f17

File tree

12 files changed

+105
-45
lines changed

12 files changed

+105
-45
lines changed

.golangci.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ issues:
161161
- text: "package-comments: should have a package comment"
162162
linters:
163163
- revive
164-
# FIXME temporarily suppress these (see https://github.com/gotestyourself/gotest.tools/issues/272)
165-
- text: "SA1019: (assert|cmp|is)\\.ErrorType is deprecated"
166-
linters:
167-
- staticcheck
164+
168165
# Exclude some linters from running on tests files.
169166
- path: _test\.go
170167
linters:

vendor.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ require (
5353
golang.org/x/term v0.27.0
5454
golang.org/x/text v0.21.0
5555
gopkg.in/yaml.v3 v3.0.1
56-
gotest.tools/v3 v3.5.1
56+
gotest.tools/v3 v3.5.2
5757
tags.cncf.io/container-device-interface v0.8.0
5858
)
5959

vendor.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
399399
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
400400
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
401401
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
402-
gotest.tools/v3 v3.5.1 h1:EENdUnS3pdur5nybKYIh2Vfgc8IUNBjxDPSjtiJcOzU=
403-
gotest.tools/v3 v3.5.1/go.mod h1:isy3WKz7GK6uNw/sbHzfKBLvlvXwUyV06n6brMxxopU=
402+
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
403+
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
404404
k8s.io/klog/v2 v2.90.1 h1:m4bYOKall2MmOiRaR1J+We67Do7vm9KiQVlT96lnHUw=
405405
k8s.io/klog/v2 v2.90.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
406406
tags.cncf.io/container-device-interface v0.8.0 h1:8bCFo/g9WODjWx3m6EYl3GfUG31eKJbaggyBDxEldRc=

vendor/gotest.tools/v3/assert/assert.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
284284
// must be called from the goroutine running the test function, not from other
285285
// goroutines created during the test. Use [Check] with [cmp.ErrorType] from other
286286
// goroutines.
287-
//
288-
// Deprecated: Use [ErrorIs]
289287
func ErrorType(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
290288
if ht, ok := t.(helperT); ok {
291289
ht.Helper()

vendor/gotest.tools/v3/assert/cmp/compare.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ type causer interface {
248248
}
249249

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

288288
// ErrorType succeeds if err is not nil and is of the expected type.
289+
// New code should use [ErrorIs] instead.
289290
//
290291
// Expected can be one of:
291292
//
@@ -306,8 +307,6 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
306307
// reflect.Type
307308
//
308309
// Fails if err does not implement the [reflect.Type].
309-
//
310-
// Deprecated: Use [ErrorIs]
311310
func ErrorType(err error, expected interface{}) Comparison {
312311
return func() Result {
313312
switch expectedType := expected.(type) {

vendor/gotest.tools/v3/fs/report.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem {
5050
return problem(fmt.Sprintf("%s: %s", reason, err))
5151
}
5252

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

5757
func eqResource(x, y resource) []problem {

vendor/gotest.tools/v3/internal/assert/assert.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,19 +87,18 @@ func logFailureFromBool(t LogT, msgAndArgs ...interface{}) {
8787
args, err := source.CallExprArgs(stackIndex)
8888
if err != nil {
8989
t.Log(err.Error())
90-
return
9190
}
9291

92+
var msg string
9393
const comparisonArgIndex = 1 // Assert(t, comparison)
9494
if len(args) <= comparisonArgIndex {
95-
t.Log(failureMessage + "but assert failed to find the expression to print")
96-
return
97-
}
98-
99-
msg, err := boolFailureMessage(args[comparisonArgIndex])
100-
if err != nil {
101-
t.Log(err.Error())
102-
msg = "expression is false"
95+
msg = "but assert failed to find the expression to print"
96+
} else {
97+
msg, err = boolFailureMessage(args[comparisonArgIndex])
98+
if err != nil {
99+
t.Log(err.Error())
100+
msg = "expression is false"
101+
}
103102
}
104103

105104
t.Log(format.WithCustomMessage(failureMessage+msg, msgAndArgs...))

vendor/gotest.tools/v3/internal/difflib/difflib.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
/*Package difflib is a partial port of Python difflib module.
1+
/*
2+
Package difflib is a partial port of Python difflib module.
23
34
Original source: https://github.com/pmezard/go-difflib
45
56
This file is trimmed to only the parts used by this repository.
67
*/
78
package difflib // import "gotest.tools/v3/internal/difflib"
89

9-
func min(a, b int) int {
10+
func minInt(a, b int) int {
1011
if a < b {
1112
return a
1213
}
1314
return b
1415
}
1516

16-
func max(a, b int) int {
17+
func maxInt(a, b int) int {
1718
if a > b {
1819
return a
1920
}
@@ -170,12 +171,15 @@ func (m *SequenceMatcher) isBJunk(s string) bool {
170171
// If IsJunk is not defined:
171172
//
172173
// Return (i,j,k) such that a[i:i+k] is equal to b[j:j+k], where
173-
// alo <= i <= i+k <= ahi
174-
// blo <= j <= j+k <= bhi
174+
//
175+
// alo <= i <= i+k <= ahi
176+
// blo <= j <= j+k <= bhi
177+
//
175178
// and for all (i',j',k') meeting those conditions,
176-
// k >= k'
177-
// i <= i'
178-
// and if i == i', j <= j'
179+
//
180+
// k >= k'
181+
// i <= i'
182+
// and if i == i', j <= j'
179183
//
180184
// In other words, of all maximal matching blocks, return one that
181185
// starts earliest in a, and of all those maximal matching blocks that
@@ -393,12 +397,12 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
393397
if codes[0].Tag == 'e' {
394398
c := codes[0]
395399
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
396-
codes[0] = OpCode{c.Tag, max(i1, i2-n), i2, max(j1, j2-n), j2}
400+
codes[0] = OpCode{c.Tag, maxInt(i1, i2-n), i2, maxInt(j1, j2-n), j2}
397401
}
398402
if codes[len(codes)-1].Tag == 'e' {
399403
c := codes[len(codes)-1]
400404
i1, i2, j1, j2 := c.I1, c.I2, c.J1, c.J2
401-
codes[len(codes)-1] = OpCode{c.Tag, i1, min(i2, i1+n), j1, min(j2, j1+n)}
405+
codes[len(codes)-1] = OpCode{c.Tag, i1, minInt(i2, i1+n), j1, minInt(j2, j1+n)}
402406
}
403407
nn := n + n
404408
groups := [][]OpCode{}
@@ -408,11 +412,11 @@ func (m *SequenceMatcher) GetGroupedOpCodes(n int) [][]OpCode {
408412
// End the current group and start a new one whenever
409413
// there is a large range with no changes.
410414
if c.Tag == 'e' && i2-i1 > nn {
411-
group = append(group, OpCode{c.Tag, i1, min(i2, i1+n),
412-
j1, min(j2, j1+n)})
415+
group = append(group, OpCode{c.Tag, i1, minInt(i2, i1+n),
416+
j1, minInt(j2, j1+n)})
413417
groups = append(groups, group)
414418
group = []OpCode{}
415-
i1, j1 = max(i1, i2-n), max(j1, j2-n)
419+
i1, j1 = maxInt(i1, i2-n), maxInt(j1, j2-n)
416420
}
417421
group = append(group, OpCode{c.Tag, i1, i2, j1, j2})
418422
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package source
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
)
8+
9+
// These Bazel env vars are documented here:
10+
// https://bazel.build/reference/test-encyclopedia
11+
12+
// Signifies test executable is being driven by `bazel test`.
13+
//
14+
// Due to Bazel's compilation and sandboxing strategy,
15+
// some care is required to handle resolving the original *.go source file.
16+
var inBazelTest = os.Getenv("BAZEL_TEST") == "1"
17+
18+
// The name of the target being tested (ex: //some_package:some_package_test)
19+
var bazelTestTarget = os.Getenv("TEST_TARGET")
20+
21+
// Absolute path to the base of the runfiles tree
22+
var bazelTestSrcdir = os.Getenv("TEST_SRCDIR")
23+
24+
// The local repository's workspace name (ex: __main__)
25+
var bazelTestWorkspace = os.Getenv("TEST_WORKSPACE")
26+
27+
func bazelSourcePath(filename string) (string, error) {
28+
// Use the env vars to resolve the test source files,
29+
// which must be provided as test data in the respective go_test target.
30+
filename = filepath.Join(bazelTestSrcdir, bazelTestWorkspace, filename)
31+
32+
_, err := os.Stat(filename)
33+
if os.IsNotExist(err) {
34+
return "", fmt.Errorf(bazelMissingSourceMsg, filename, bazelTestTarget)
35+
}
36+
return filename, nil
37+
}
38+
39+
var bazelMissingSourceMsg = `
40+
the test source file does not exist: %s
41+
It appears that you are running this test under Bazel (target: %s).
42+
Check that your test source files are added as test data in your go_test targets.
43+
44+
Example:
45+
go_test(
46+
name = "your_package_test",
47+
srcs = ["your_test.go"],
48+
deps = ["@tools_gotest_v3//assert"],
49+
data = glob(["*_test.go"])
50+
)"
51+
`

vendor/gotest.tools/v3/internal/source/source.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"go/parser"
1111
"go/token"
1212
"os"
13+
"path/filepath"
1314
"runtime"
1415
)
1516

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

39+
// Normally, `go` will compile programs with absolute paths in
40+
// the debug metadata. However, in the name of reproducibility,
41+
// Bazel uses a compilation strategy that results in relative paths
42+
// (otherwise, since Bazel uses a random tmp dir for compile and sandboxing,
43+
// the resulting binaries would change across compiles/test runs).
44+
if inBazelTest && !filepath.IsAbs(filename) {
45+
var err error
46+
filename, err = bazelSourcePath(filename)
47+
if err != nil {
48+
return nil, err
49+
}
50+
}
51+
3852
fileset := token.NewFileSet()
3953
astFile, err := parser.ParseFile(fileset, filename, nil, parser.AllErrors)
4054
if err != nil {
@@ -58,7 +72,7 @@ func getNodeAtLine(fileset *token.FileSet, astFile ast.Node, lineNum int) (ast.N
5872
return node, err
5973
}
6074
}
61-
return nil, nil
75+
return nil, errors.New("failed to find expression")
6276
}
6377

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

7993
func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast.Expr, error) {
8094
node, err := getNodeAtLine(fileset, astFile, line)
81-
switch {
82-
case err != nil:
95+
if err != nil {
8396
return nil, err
84-
case node == nil:
85-
return nil, fmt.Errorf("failed to find an expression")
8697
}
8798

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

90101
visitor := &callExprVisitor{}
91102
ast.Walk(visitor, node)
92103
if visitor.expr == nil {
93-
return nil, errors.New("failed to find call expression")
104+
return nil, errors.New("failed to find an expression")
94105
}
95106
debug("callExpr: %s", debugFormatNode{visitor.expr})
96107
return visitor.expr.Args, nil

vendor/gotest.tools/v3/poll/poll.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"gotest.tools/v3/assert/cmp"
1111
"gotest.tools/v3/internal/assert"
12+
"gotest.tools/v3/internal/format"
1213
)
1314

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

9697
// Success returns a [Result] where Done() returns true, which indicates to [WaitOn]
@@ -151,7 +152,7 @@ func Compare(compare cmp.Comparison) Result {
151152
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
152153
return Success()
153154
}
154-
return Continue(buf.String())
155+
return Continue("%v", buf.String())
155156
}
156157

157158
type logBuffer struct {

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ google.golang.org/protobuf/types/known/wrapperspb
529529
# gopkg.in/yaml.v3 v3.0.1
530530
## explicit
531531
gopkg.in/yaml.v3
532-
# gotest.tools/v3 v3.5.1
532+
# gotest.tools/v3 v3.5.2
533533
## explicit; go 1.17
534534
gotest.tools/v3/assert
535535
gotest.tools/v3/assert/cmp

0 commit comments

Comments
 (0)