forked from toolshed/abra
build: go 1.24
We were running behind and there were quite some deprecations to update. This was mostly in the upstream copy/pasta package but seems quite minimal.
This commit is contained in:
2
vendor/gotest.tools/v3/assert/assert.go
vendored
2
vendor/gotest.tools/v3/assert/assert.go
vendored
@ -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()
|
||||
|
5
vendor/gotest.tools/v3/assert/cmp/compare.go
vendored
5
vendor/gotest.tools/v3/assert/cmp/compare.go
vendored
@ -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) {
|
||||
|
4
vendor/gotest.tools/v3/fs/report.go
vendored
4
vendor/gotest.tools/v3/fs/report.go
vendored
@ -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 {
|
||||
|
17
vendor/gotest.tools/v3/internal/assert/assert.go
vendored
17
vendor/gotest.tools/v3/internal/assert/assert.go
vendored
@ -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...))
|
||||
|
@ -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})
|
||||
}
|
||||
|
51
vendor/gotest.tools/v3/internal/source/bazel.go
vendored
Normal file
51
vendor/gotest.tools/v3/internal/source/bazel.go
vendored
Normal file
@ -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
vendor/gotest.tools/v3/internal/source/source.go
vendored
23
vendor/gotest.tools/v3/internal/source/source.go
vendored
@ -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
|
||||
|
Reference in New Issue
Block a user