vendor: gotest.tools/v3 v3.4.0

- removes github.com/spf13/pflag dependency
- removes use of deprecated io/ioutil package
- drops support for go1.16

full diff: https://github.com/gotestyourself/gotest.tools/compare/v3.3.0...v3.4.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-11-05 23:25:29 +01:00
parent 46ba87dcf1
commit c855e4ba3b
No known key found for this signature in database
GPG Key ID: 76698F39D527CE8C
20 changed files with 142 additions and 114 deletions

View File

@ -41,7 +41,7 @@ require (
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
golang.org/x/text v0.3.7
gopkg.in/yaml.v2 v2.4.0
gotest.tools/v3 v3.3.0
gotest.tools/v3 v3.4.0
)
require (

View File

@ -751,8 +751,8 @@ gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C
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.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
gotest.tools/v3 v3.3.0 h1:MfDY1b1/0xN1CyMlQDac0ziEy9zJQd9CXBRRDHw2jJo=
gotest.tools/v3 v3.3.0/go.mod h1:Mcr9QNxkg0uMvy/YElmo4SpXgJKWgQvYrT7Kw5RzJ1A=
gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o=
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
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=

View File

@ -1,7 +1,8 @@
/*Package assert provides assertions for comparing expected values to actual
/*
Package assert provides assertions for comparing expected values to actual
values in tests. When an assertion fails a helpful error message is printed.
Example usage
# Example usage
All the assertions in this package use testing.T.Helper to mark themselves as
test helpers. This allows the testing package to print the filename and line
@ -64,7 +65,7 @@ message is omitted from these examples for brevity.
assert.Assert(t, ref != nil) // use Assert for NotNil
// assertion failed: ref is nil
Assert and Check
# Assert and Check
Assert and Check are very similar, they both accept a Comparison, and fail
the test when the comparison fails. The one difference is that Assert uses
@ -76,20 +77,18 @@ Like testing.T.FailNow, Assert must be called from the goroutine running the tes
not from other goroutines created during the test. Check is safe to use from any
goroutine.
Comparisons
# Comparisons
Package http://pkg.go.dev/gotest.tools/v3/assert/cmp provides
many common comparisons. Additional comparisons can be written to compare
values in other ways. See the example Assert (CustomComparison).
Automated migration from testify
# Automated migration from testify
gty-migrate-from-testify is a command which translates Go source code from
testify assertions to the assertions provided by this package.
See http://pkg.go.dev/gotest.tools/v3/assert/cmd/gty-migrate-from-testify.
*/
package assert // import "gotest.tools/v3/assert"
@ -132,7 +131,6 @@ type helperT interface {
// A nil value is considered success, and a non-nil error is a failure.
// The return value of error.Error is used as the failure message.
//
//
// Extra details can be added to the failure message using msgAndArgs. msgAndArgs
// may be either a single string, or a format string and args that will be
// passed to fmt.Sprintf.

View File

@ -68,6 +68,7 @@ type RegexOrPattern interface{}
// Regexp succeeds if value v matches regular expression re.
//
// Example:
//
// assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str))
// r := regexp.MustCompile("^[0-9a-f]{32}$")
// assert.Assert(t, cmp.Regexp(r, str))
@ -288,15 +289,23 @@ func isNil(obj interface{}, msgFunc func(reflect.Value) string) Comparison {
// ErrorType succeeds if err is not nil and is of the expected type.
//
// Expected can be one of:
//
// func(error) bool
//
// Function should return true if the error is the expected type.
//
// type struct{}, type &struct{}
//
// A struct or a pointer to a struct.
// Fails if the error is not of the same type as expected.
//
// type &interface{}
//
// A pointer to an interface type.
// Fails if err does not implement the interface.
//
// reflect.Type
//
// Fails if err does not implement the reflect.Type
func ErrorType(err error, expected interface{}) Comparison {
return func() Result {

View File

@ -1,4 +1,5 @@
/*Package env provides functions to test code that read environment variables
/*
Package env provides functions to test code that read environment variables
or the current working directory.
*/
package env // import "gotest.tools/v3/env"

View File

@ -1,10 +1,10 @@
/*Package fs provides tools for creating temporary files, and testing the
/*
Package fs provides tools for creating temporary files, and testing the
contents and structure of a directory.
*/
package fs // import "gotest.tools/v3/fs"
import (
"io/ioutil"
"os"
"path/filepath"
"runtime"
@ -45,7 +45,7 @@ func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
tempfile, err := ioutil.TempFile("", cleanPrefix(prefix)+"-")
tempfile, err := os.CreateTemp("", cleanPrefix(prefix)+"-")
assert.NilError(t, err)
file := &File{path: tempfile.Name()}
@ -71,8 +71,7 @@ func (f *File) Path() string {
// Remove the file
func (f *File) Remove() {
// nolint: errcheck
os.Remove(f.path)
_ = os.Remove(f.path)
}
// Dir is a temporary directory
@ -89,7 +88,7 @@ func NewDir(t assert.TestingT, prefix string, ops ...PathOp) *Dir {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
path, err := ioutil.TempDir("", cleanPrefix(prefix)+"-")
path, err := os.MkdirTemp("", cleanPrefix(prefix)+"-")
assert.NilError(t, err)
dir := &Dir{path: path}
cleanup.Cleanup(t, dir.Remove)
@ -105,8 +104,7 @@ func (d *Dir) Path() string {
// Remove the directory
func (d *Dir) Remove() {
// nolint: errcheck
os.RemoveAll(d.path)
_ = os.RemoveAll(d.path)
}
// Join returns a new path with this directory as the base of the path

View File

@ -3,7 +3,6 @@ package fs
import (
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
@ -84,7 +83,7 @@ func manifestFromDir(path string) (Manifest, error) {
func newDirectory(path string, info os.FileInfo) (*directory, error) {
items := make(map[string]dirEntry)
children, err := ioutil.ReadDir(path)
children, err := os.ReadDir(path)
if err != nil {
return nil, err
}
@ -103,7 +102,11 @@ func newDirectory(path string, info os.FileInfo) (*directory, error) {
}, nil
}
func getTypedResource(path string, info os.FileInfo) (dirEntry, error) {
func getTypedResource(path string, entry os.DirEntry) (dirEntry, error) {
info, err := entry.Info()
if err != nil {
return nil, err
}
switch {
case info.IsDir():
return newDirectory(path, info)

View File

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
@ -43,10 +42,10 @@ type manifestDirectory interface {
func WithContent(content string) PathOp {
return func(path Path) error {
if m, ok := path.(manifestFile); ok {
m.SetContent(ioutil.NopCloser(strings.NewReader(content)))
m.SetContent(io.NopCloser(strings.NewReader(content)))
return nil
}
return ioutil.WriteFile(path.Path(), []byte(content), defaultFileMode)
return os.WriteFile(path.Path(), []byte(content), defaultFileMode)
}
}
@ -54,10 +53,10 @@ func WithContent(content string) PathOp {
func WithBytes(raw []byte) PathOp {
return func(path Path) error {
if m, ok := path.(manifestFile); ok {
m.SetContent(ioutil.NopCloser(bytes.NewReader(raw)))
m.SetContent(io.NopCloser(bytes.NewReader(raw)))
return nil
}
return ioutil.WriteFile(path.Path(), raw, defaultFileMode)
return os.WriteFile(path.Path(), raw, defaultFileMode)
}
}
@ -65,7 +64,7 @@ func WithBytes(raw []byte) PathOp {
func WithReaderContent(r io.Reader) PathOp {
return func(path Path) error {
if m, ok := path.(manifestFile); ok {
m.SetContent(ioutil.NopCloser(r))
m.SetContent(io.NopCloser(r))
return nil
}
f, err := os.OpenFile(path.Path(), os.O_WRONLY, defaultFileMode)
@ -107,7 +106,7 @@ func WithFile(filename, content string, ops ...PathOp) PathOp {
}
func createFile(fullpath string, content string) error {
return ioutil.WriteFile(fullpath, []byte(content), defaultFileMode)
return os.WriteFile(fullpath, []byte(content), defaultFileMode)
}
// WithFiles creates all the files in the directory at path with their content
@ -191,34 +190,38 @@ func WithMode(mode os.FileMode) PathOp {
}
func copyDirectory(source, dest string) error {
entries, err := ioutil.ReadDir(source)
entries, err := os.ReadDir(source)
if err != nil {
return err
}
for _, entry := range entries {
sourcePath := filepath.Join(source, entry.Name())
destPath := filepath.Join(dest, entry.Name())
switch {
case entry.IsDir():
if err := os.Mkdir(destPath, 0755); err != nil {
err = copyEntry(entry, destPath, sourcePath)
if err != nil {
return err
}
if err := copyDirectory(sourcePath, destPath); err != nil {
return err
}
case entry.Mode()&os.ModeSymlink != 0:
if err := copySymLink(sourcePath, destPath); err != nil {
return err
}
default:
if err := copyFile(sourcePath, destPath); err != nil {
return err
}
}
}
return nil
}
func copyEntry(entry os.DirEntry, destPath string, sourcePath string) error {
if entry.IsDir() {
if err := os.Mkdir(destPath, 0755); err != nil {
return err
}
return copyDirectory(sourcePath, destPath)
}
info, err := entry.Info()
if err != nil {
return err
}
if info.Mode()&os.ModeSymlink != 0 {
return copySymLink(sourcePath, destPath)
}
return copyFile(sourcePath, destPath)
}
func copySymLink(source, dest string) error {
link, err := os.Readlink(source)
if err != nil {
@ -228,11 +231,11 @@ func copySymLink(source, dest string) error {
}
func copyFile(source, dest string) error {
content, err := ioutil.ReadFile(source)
content, err := os.ReadFile(source)
if err != nil {
return err
}
return ioutil.WriteFile(dest, content, 0644)
return os.WriteFile(dest, content, 0644)
}
// WithSymlink creates a symlink in the directory which links to target.

View File

@ -3,7 +3,6 @@ package fs
import (
"bytes"
"io"
"io/ioutil"
"os"
"gotest.tools/v3/assert"
@ -124,7 +123,7 @@ func normalizeID(id int) uint32 {
return uint32(id)
}
var anyFileContent = ioutil.NopCloser(bytes.NewReader(nil))
var anyFileContent = io.NopCloser(bytes.NewReader(nil))
// MatchAnyFileContent is a PathOp that updates a Manifest so that the file
// at path may contain any content.

View File

@ -3,7 +3,7 @@ package fs
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"os"
"path/filepath"
"runtime"
@ -86,9 +86,9 @@ func eqFile(x, y *file) []problem {
return p
}
xContent, xErr := ioutil.ReadAll(x.content)
xContent, xErr := io.ReadAll(x.content)
defer x.content.Close()
yContent, yErr := ioutil.ReadAll(y.content)
yContent, yErr := io.ReadAll(y.content)
defer y.content.Close()
if xErr != nil {

View File

@ -1,4 +1,5 @@
/*Package golden provides tools for comparing large mutli-line strings.
/*
Package golden provides tools for comparing large mutli-line strings.
Golden files are files in the ./testdata/ subdirectory of the package under test.
Golden files can be automatically updated to match new values by running
@ -11,7 +12,6 @@ import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
@ -62,7 +62,7 @@ func Get(t assert.TestingT, filename string) []byte {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
expected, err := ioutil.ReadFile(Path(filename))
expected, err := os.ReadFile(Path(filename))
assert.NilError(t, err)
return expected
}
@ -167,7 +167,7 @@ func compare(actual []byte, filename string) (cmp.Result, []byte) {
if err := update(filename, actual); err != nil {
return cmp.ResultFromError(err), nil
}
expected, err := ioutil.ReadFile(Path(filename))
expected, err := os.ReadFile(Path(filename))
if err != nil {
return cmp.ResultFromError(err), nil
}
@ -186,5 +186,5 @@ func update(filename string, actual []byte) error {
return err
}
}
return ioutil.WriteFile(Path(filename), actual, 0644)
return os.WriteFile(Path(filename), actual, 0644)
}

View File

@ -7,11 +7,11 @@ import (
"fmt"
"io"
"os"
"os/exec"
"strings"
"sync"
"time"
exec "golang.org/x/sys/execabs"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
)

View File

@ -2,8 +2,7 @@ package icmd
import (
"errors"
exec "golang.org/x/sys/execabs"
"os/exec"
)
func processExitCode(err error) int {

View File

@ -1,3 +1,4 @@
// Package assert provides internal utilties for assertions.
package assert
import (

View File

@ -1,4 +1,5 @@
/*Package cleanup handles migration to and support for the Go 1.14+
/*
Package cleanup handles migration to and support for the Go 1.14+
testing.TB.Cleanup() function.
*/
package cleanup

View File

@ -1,3 +1,4 @@
// Package format provides utilities for formatting diffs and messages.
package format
import (

View File

@ -1,3 +1,4 @@
// Package source provides utilities for handling source-code.
package source // import "gotest.tools/v3/internal/source"
import (

View File

@ -54,8 +54,8 @@ func UpdateExpectedValue(stackIndex int, x, y interface{}) error {
return ErrNotFound
}
argIndex, varName := getVarNameForExpectedValueArg(expr)
if argIndex < 0 || varName == "" {
argIndex, ident := getIdentForExpectedValueArg(expr)
if argIndex < 0 || ident == nil {
debug("no arguments started with the word 'expected': %v",
debugFormatNode{Node: &ast.CallExpr{Args: expr}})
return ErrNotFound
@ -71,7 +71,7 @@ func UpdateExpectedValue(stackIndex int, x, y interface{}) error {
debug("value must be type string, got %T", value)
return ErrNotFound
}
return UpdateVariable(filename, fileset, astFile, varName, strValue)
return UpdateVariable(filename, fileset, astFile, ident, strValue)
}
// UpdateVariable writes to filename the contents of astFile with the value of
@ -80,10 +80,10 @@ func UpdateVariable(
filename string,
fileset *token.FileSet,
astFile *ast.File,
varName string,
ident *ast.Ident,
value string,
) error {
obj := astFile.Scope.Objects[varName]
obj := ident.Obj
if obj == nil {
return ErrNotFound
}
@ -92,21 +92,34 @@ func UpdateVariable(
return ErrNotFound
}
spec, ok := obj.Decl.(*ast.ValueSpec)
if !ok {
debug("can only update *ast.ValueSpec, found %T", obj.Decl)
return ErrNotFound
}
if len(spec.Names) != 1 {
switch decl := obj.Decl.(type) {
case *ast.ValueSpec:
if len(decl.Names) != 1 {
debug("more than one name in ast.ValueSpec")
return ErrNotFound
}
spec.Values[0] = &ast.BasicLit{
decl.Values[0] = &ast.BasicLit{
Kind: token.STRING,
Value: "`" + value + "`",
}
case *ast.AssignStmt:
if len(decl.Lhs) != 1 {
debug("more than one name in ast.AssignStmt")
return ErrNotFound
}
decl.Rhs[0] = &ast.BasicLit{
Kind: token.STRING,
Value: "`" + value + "`",
}
default:
debug("can only update *ast.ValueSpec, found %T", obj.Decl)
return ErrNotFound
}
var buf bytes.Buffer
if err := format.Node(&buf, fileset, astFile); err != nil {
return fmt.Errorf("failed to format file after update: %w", err)
@ -125,14 +138,14 @@ func UpdateVariable(
return nil
}
func getVarNameForExpectedValueArg(expr []ast.Expr) (int, string) {
func getIdentForExpectedValueArg(expr []ast.Expr) (int, *ast.Ident) {
for i := 1; i < 3; i++ {
switch e := expr[i].(type) {
case *ast.Ident:
if strings.HasPrefix(strings.ToLower(e.Name), "expected") {
return i, e.Name
return i, e
}
}
}
return -1, ""
return -1, nil
}

View File

@ -1,4 +1,5 @@
/*Package skip provides functions for skipping a test and printing the source code
/*
Package skip provides functions for skipping a test and printing the source code
of the condition used to skip the test.
*/
package skip // import "gotest.tools/v3/skip"

2
vendor/modules.txt vendored
View File

@ -377,7 +377,7 @@ google.golang.org/protobuf/types/known/timestamppb
# gopkg.in/yaml.v2 v2.4.0
## explicit; go 1.15
gopkg.in/yaml.v2
# gotest.tools/v3 v3.3.0
# gotest.tools/v3 v3.4.0
## explicit; go 1.13
gotest.tools/v3/assert
gotest.tools/v3/assert/cmp