1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

bump gotest.tools v3.0.1 for compatibility with Go 1.14

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

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-02-07 14:39:24 +01:00
parent c6400be468
commit 9f0b3f5609
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
385 changed files with 1054 additions and 868 deletions

View file

@ -1,8 +0,0 @@
module gotest.tools
require (
github.com/google/go-cmp v0.2.0
github.com/pkg/errors v0.8.0
github.com/spf13/pflag v1.0.3
golang.org/x/tools v0.0.0-20180810170437-e96c4e24768d
)

View file

@ -2,26 +2,41 @@
A collection of packages to augment `testing` and support common patterns.
[![GoDoc](https://godoc.org/gotest.tools?status.svg)](https://godoc.org/gotest.tools)
[![GoDoc](https://godoc.org/gotest.tools?status.svg)](http://gotest.tools)
[![CircleCI](https://circleci.com/gh/gotestyourself/gotest.tools/tree/master.svg?style=shield)](https://circleci.com/gh/gotestyourself/gotest.tools/tree/master)
[![Go Reportcard](https://goreportcard.com/badge/gotest.tools)](https://goreportcard.com/report/gotest.tools)
## Usage
With Go modules enabled (go1.11+)
```
$ go get gotest.tools/v3
```
```
import "gotest.tools/v3/assert"
```
To use `gotest.tools` with an older version of Go that does not understand Go
module paths pin to version `v2.3.0`.
## Packages
* [assert](http://godoc.org/gotest.tools/assert) -
* [assert](http://gotest.tools/assert) -
compare values and fail the test when a comparison fails
* [env](http://godoc.org/gotest.tools/env) -
* [env](http://gotest.tools/env) -
test code which uses environment variables
* [fs](http://godoc.org/gotest.tools/fs) -
* [fs](http://gotest.tools/fs) -
create temporary files and compare a filesystem tree to an expected value
* [golden](http://godoc.org/gotest.tools/golden) -
* [golden](http://gotest.tools/golden) -
compare large multi-line strings against values frozen in golden files
* [icmd](http://godoc.org/gotest.tools/icmd) -
* [icmd](http://gotest.tools/icmd) -
execute binaries and test the output
* [poll](http://godoc.org/gotest.tools/poll) -
* [poll](http://gotest.tools/poll) -
test asynchronous code by polling until a desired state is reached
* [skip](http://godoc.org/gotest.tools/skip) -
* [skip](http://gotest.tools/skip) -
skip a test and print the source code of the condition used to skip the test
## Related

View file

@ -49,30 +49,31 @@ The example below shows assert used with some common types.
Comparisons
Package https://godoc.org/gotest.tools/assert/cmp provides
Package http://gotest.tools/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
gty-migrate-from-testify is a binary which can update source code which uses
testify assertions to use the assertions provided by this package.
gty-migrate-from-testify is a command which translates Go source code from
testify assertions to the assertions provided by this package.
See http://bit.do/cmd-gty-migrate-from-testify.
See http://gotest.tools/assert/cmd/gty-migrate-from-testify.
*/
package assert // import "gotest.tools/assert"
package assert // import "gotest.tools/v3/assert"
import (
"fmt"
"go/ast"
"go/token"
"reflect"
gocmp "github.com/google/go-cmp/cmp"
"gotest.tools/assert/cmp"
"gotest.tools/internal/format"
"gotest.tools/internal/source"
"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/format"
"gotest.tools/v3/internal/source"
)
// BoolOrComparison can be a bool, or cmp.Comparison. See Assert() for usage.
@ -118,6 +119,10 @@ func assert(
return true
case error:
// Handle nil structs which implement error as a nil error
if reflect.ValueOf(check).IsNil() {
return true
}
msg := "error is not nil: "
t.Log(format.WithCustomMessage(failureMessage+msg+check.Error(), msgAndArgs...))
@ -202,17 +207,20 @@ func boolFailureMessage(expr ast.Expr) (string, error) {
return "expression is false: " + formatted, nil
}
// Assert performs a comparison. If the comparison fails the test is marked as
// Assert performs a comparison. If the comparison fails, the test is marked as
// failed, a failure message is logged, and execution is stopped immediately.
//
// The comparison argument may be one of three types: bool, cmp.Comparison or
// error.
// When called with a bool the failure message will contain the literal source
// code of the expression.
// When called with a cmp.Comparison the comparison is responsible for producing
// a helpful failure message.
// When called with an error a nil value is considered success. A non-nil error
// is a failure, and Error() is used as the failure message.
// The comparison argument may be one of three types:
// bool
// True is success. False is a failure.
// The failure message will contain the literal source code of the expression.
// cmp.Comparison
// Uses cmp.Result.Success() to check for success of failure.
// The comparison is responsible for producing a helpful failure message.
// http://gotest.tools/assert/cmp provides many common comparisons.
// error
// A nil value is considered success.
// A non-nil error is a failure, err.Error() is used as the failure message.
func Assert(t TestingT, comparison BoolOrComparison, msgAndArgs ...interface{}) {
if ht, ok := t.(helperT); ok {
ht.Helper()
@ -260,10 +268,10 @@ func Equal(t TestingT, x, y interface{}, msgAndArgs ...interface{}) {
assert(t, t.FailNow, argsAfterT, cmp.Equal(x, y), msgAndArgs...)
}
// DeepEqual uses google/go-cmp (http://bit.do/go-cmp) to assert two values are
// equal and fails the test if they are not equal.
// DeepEqual uses google/go-cmp (https://godoc.org/github.com/google/go-cmp/cmp)
// to assert two values are equal and fails the test if they are not equal.
//
// Package https://godoc.org/gotest.tools/assert/opt provides some additional
// Package http://gotest.tools/assert/opt provides some additional
// commonly used Options.
//
// This is equivalent to Assert(t, cmp.DeepEqual(x, y)).
@ -295,14 +303,19 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
}
// ErrorType fails the test if err is nil, or err is not the expected type.
// Equivalent to Assert(t, cmp.ErrorType(err, expected)).
//
// Expected can be one of:
// a func(error) bool which returns true if the error is the expected type,
// an instance of (or a pointer to) a struct of the expected type,
// a pointer to an interface the error is expected to implement,
// a reflect.Type of the expected struct or interface.
//
// Equivalent to Assert(t, cmp.ErrorType(err, expected)).
// 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(t TestingT, err error, expected interface{}, msgAndArgs ...interface{}) {
if ht, ok := t.(helperT); ok {
ht.Helper()

View file

@ -1,5 +1,5 @@
/*Package cmp provides Comparisons for Assert and Check*/
package cmp // import "gotest.tools/assert/cmp"
package cmp // import "gotest.tools/v3/assert/cmp"
import (
"fmt"
@ -8,7 +8,7 @@ import (
"strings"
"github.com/google/go-cmp/cmp"
"gotest.tools/internal/format"
"gotest.tools/v3/internal/format"
)
// Comparison is a function which compares values and returns ResultSuccess if
@ -16,11 +16,12 @@ import (
// Result will contain a message about why it failed.
type Comparison func() Result
// DeepEqual compares two values using google/go-cmp (http://bit.do/go-cmp)
// DeepEqual compares two values using google/go-cmp
// (https://godoc.org/github.com/google/go-cmp/cmp)
// and succeeds if the values are equal.
//
// The comparison can be customized using comparison Options.
// Package https://godoc.org/gotest.tools/assert/opt provides some additional
// Package http://gotest.tools/assert/opt provides some additional
// commonly used Options.
func DeepEqual(x, y interface{}, opts ...cmp.Option) Comparison {
return func() (result Result) {
@ -103,10 +104,10 @@ func Equal(x, y interface{}) Comparison {
return multiLineDiffResult(diff)
}
return ResultFailureTemplate(`
{{- .Data.x}} (
{{- printf "%v" .Data.x}} (
{{- with callArg 0 }}{{ formatNode . }} {{end -}}
{{- printf "%T" .Data.x -}}
) != {{ .Data.y}} (
) != {{ printf "%v" .Data.y}} (
{{- with callArg 1 }}{{ formatNode . }} {{end -}}
{{- printf "%T" .Data.y -}}
)`,
@ -241,10 +242,12 @@ func ErrorContains(err error, substring string) Comparison {
}
}
type causer interface {
Cause() error
}
func formatErrorMessage(err error) string {
if _, ok := err.(interface {
Cause() error
}); ok {
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
// This error was not wrapped with github.com/pkg/errors
@ -283,10 +286,16 @@ 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:
// a func(error) bool which returns true if the error is the expected type,
// an instance of (or a pointer to) a struct of the expected type,
// a pointer to an interface the error is expected to implement,
// a reflect.Type of the expected struct or interface.
// 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 {
switch expectedType := expected.(type) {

View file

@ -6,7 +6,7 @@ import (
"go/ast"
"text/template"
"gotest.tools/internal/source"
"gotest.tools/v3/internal/source"
)
// A Result of a Comparison.

View file

@ -4,9 +4,9 @@ import (
"fmt"
"go/ast"
"gotest.tools/assert/cmp"
"gotest.tools/internal/format"
"gotest.tools/internal/source"
"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/format"
"gotest.tools/v3/internal/source"
)
func runComparison(

View file

@ -1,14 +1,14 @@
/*Package env provides functions to test code that read environment variables
or the current working directory.
*/
package env // import "gotest.tools/env"
package env // import "gotest.tools/v3/env"
import (
"os"
"strings"
"gotest.tools/assert"
"gotest.tools/x/subtest"
"gotest.tools/v3/assert"
"gotest.tools/v3/internal/cleanup"
)
type helperT interface {
@ -18,30 +18,34 @@ type helperT interface {
// Patch changes the value of an environment variable, and returns a
// function which will reset the the value of that variable back to the
// previous state.
//
// When used with Go 1.14+ the unpatch function will be called automatically
// when the test ends, unless the TEST_NOCLEANUP env var is set to true.
func Patch(t assert.TestingT, key, value string) func() {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
oldValue, ok := os.LookupEnv(key)
oldValue, envVarExists := os.LookupEnv(key)
assert.NilError(t, os.Setenv(key, value))
cleanup := func() {
clean := func() {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
if !ok {
if !envVarExists {
assert.NilError(t, os.Unsetenv(key))
return
}
assert.NilError(t, os.Setenv(key, oldValue))
}
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(cleanup)
}
return cleanup
cleanup.Cleanup(t, clean)
return clean
}
// PatchAll sets the environment to env, and returns a function which will
// reset the environment back to the previous state.
//
// When used with Go 1.14+ the unpatch function will be called automatically
// when the test ends, unless the TEST_NOCLEANUP env var is set to true.
func PatchAll(t assert.TestingT, env map[string]string) func() {
if ht, ok := t.(helperT); ok {
ht.Helper()
@ -52,7 +56,7 @@ func PatchAll(t assert.TestingT, env map[string]string) func() {
for key, value := range env {
assert.NilError(t, os.Setenv(key, value), "setenv %s=%s", key, value)
}
cleanup := func() {
clean := func() {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
@ -61,10 +65,8 @@ func PatchAll(t assert.TestingT, env map[string]string) func() {
assert.NilError(t, os.Setenv(key, oldVal), "setenv %s=%s", key, oldVal)
}
}
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(cleanup)
}
return cleanup
cleanup.Cleanup(t, clean)
return clean
}
// ToMap takes a list of strings in the format returned by os.Environ() and
@ -94,6 +96,10 @@ func getParts(raw string) (string, string) {
// ChangeWorkingDir to the directory, and return a function which restores the
// previous working directory.
//
// When used with Go 1.14+ the previous working directory will be restored
// automatically when the test ends, unless the TEST_NOCLEANUP env var is set to
// true.
func ChangeWorkingDir(t assert.TestingT, dir string) func() {
if ht, ok := t.(helperT); ok {
ht.Helper()
@ -101,14 +107,12 @@ func ChangeWorkingDir(t assert.TestingT, dir string) func() {
cwd, err := os.Getwd()
assert.NilError(t, err)
assert.NilError(t, os.Chdir(dir))
cleanup := func() {
clean := func() {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
assert.NilError(t, os.Chdir(cwd))
}
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(cleanup)
}
return cleanup
cleanup.Cleanup(t, clean)
return clean
}

View file

@ -1,7 +1,7 @@
/*Package fs provides tools for creating temporary files, and testing the
contents and structure of a directory.
*/
package fs // import "gotest.tools/fs"
package fs // import "gotest.tools/v3/fs"
import (
"io/ioutil"
@ -10,8 +10,8 @@ import (
"runtime"
"strings"
"gotest.tools/assert"
"gotest.tools/x/subtest"
"gotest.tools/v3/assert"
"gotest.tools/v3/internal/cleanup"
)
// Path objects return their filesystem path. Path may be implemented by a
@ -38,18 +38,21 @@ type helperT interface {
// NewFile creates a new file in a temporary directory using prefix as part of
// the filename. The PathOps are applied to the before returning the File.
//
// When used with Go 1.14+ the file will be automatically removed when the test
// ends, unless the TEST_NOCLEANUP env var is set to true.
func NewFile(t assert.TestingT, prefix string, ops ...PathOp) *File {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
tempfile, err := ioutil.TempFile("", cleanPrefix(prefix)+"-")
assert.NilError(t, err)
file := &File{path: tempfile.Name()}
cleanup.Cleanup(t, file.Remove)
assert.NilError(t, tempfile.Close())
assert.NilError(t, applyPathOps(file, ops))
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(file.Remove)
}
return file
}
@ -79,6 +82,9 @@ type Dir struct {
// NewDir returns a new temporary directory using prefix as part of the directory
// name. The PathOps are applied before returning the Dir.
//
// When used with Go 1.14+ the directory will be automatically removed when the test
// ends, unless the TEST_NOCLEANUP env var is set to true.
func NewDir(t assert.TestingT, prefix string, ops ...PathOp) *Dir {
if ht, ok := t.(helperT); ok {
ht.Helper()
@ -86,10 +92,9 @@ func NewDir(t assert.TestingT, prefix string, ops ...PathOp) *Dir {
path, err := ioutil.TempDir("", cleanPrefix(prefix)+"-")
assert.NilError(t, err)
dir := &Dir{path: path}
cleanup.Cleanup(t, dir.Remove)
assert.NilError(t, applyPathOps(dir, ops))
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(dir.Remove)
}
return dir
}

View file

@ -7,7 +7,7 @@ import (
"path/filepath"
"github.com/pkg/errors"
"gotest.tools/assert"
"gotest.tools/v3/assert"
)
// Manifest stores the expected structure and properties of files and directories

View file

@ -10,7 +10,7 @@ import (
"time"
"github.com/pkg/errors"
"gotest.tools/assert"
"gotest.tools/v3/assert"
)
const defaultFileMode = 0644
@ -61,6 +61,23 @@ func WithBytes(raw []byte) PathOp {
}
}
// WithReaderContent copies the reader contents to the file at Path
func WithReaderContent(r io.Reader) PathOp {
return func(path Path) error {
if m, ok := path.(manifestFile); ok {
m.SetContent(ioutil.NopCloser(r))
return nil
}
f, err := os.OpenFile(path.Path(), os.O_WRONLY, defaultFileMode)
if err != nil {
return err
}
defer f.Close()
_, err = io.Copy(f, r)
return err
}
}
// AsUser changes ownership of the file system object at Path
func AsUser(uid, gid int) PathOp {
return func(path Path) error {

View file

@ -6,7 +6,7 @@ import (
"io/ioutil"
"os"
"gotest.tools/assert"
"gotest.tools/v3/assert"
)
// resourcePath is an adaptor for resources so they can be used as a Path
@ -150,7 +150,7 @@ const anyFile = "*"
// to contain unspecified files.
func MatchExtraFiles(path Path) error {
if m, ok := path.(*directoryPath); ok {
m.AddFile(anyFile)
return m.AddFile(anyFile)
}
return nil
}
@ -180,7 +180,7 @@ func MatchFileContent(f func([]byte) CompareResult) PathOp {
func MatchFilesWithGlob(glob string, ops ...PathOp) PathOp {
return func(path Path) error {
if m, ok := path.(*directoryPath); ok {
m.AddGlobFiles(glob, ops...)
return m.AddGlobFiles(glob, ops...)
}
return nil
}

View file

@ -10,8 +10,8 @@ import (
"sort"
"strings"
"gotest.tools/assert/cmp"
"gotest.tools/internal/format"
"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/internal/format"
)
// Equal compares a directory to the expected structured described by a manifest
@ -159,7 +159,7 @@ func eqSymlink(x, y *symlink) []problem {
func eqDirectory(path string, x, y *directory) []failure {
p := eqResource(x.resource, y.resource)
var f []failure
var f []failure // nolint: prealloc
matchedFiles := make(map[string]bool)
for _, name := range sortedKeys(x.items) {
@ -209,7 +209,7 @@ func maybeAppendFailure(failures []failure, path string, problems []problem) []f
}
func sortedKeys(items map[string]dirEntry) []string {
var keys []string
keys := make([]string, 0, len(items))
for key := range items {
keys = append(keys, key)
}

10
vendor/gotest.tools/v3/go.mod vendored Normal file
View file

@ -0,0 +1,10 @@
module gotest.tools/v3
require (
github.com/google/go-cmp v0.3.0
github.com/pkg/errors v0.8.1
github.com/spf13/pflag v1.0.3
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4
)
go 1.11

View file

@ -1,18 +1,19 @@
/*Package icmd executes binaries and provides convenient assertions for testing the results.
*/
package icmd // import "gotest.tools/icmd"
package icmd // import "gotest.tools/v3/icmd"
import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"strings"
"sync"
"time"
"gotest.tools/assert"
"gotest.tools/assert/cmp"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
)
type helperT interface {
@ -191,12 +192,13 @@ func (r *Result) setExitError(err error) {
// Cmd contains the arguments and options for a process to run as part of a test
// suite.
type Cmd struct {
Command []string
Timeout time.Duration
Stdin io.Reader
Stdout io.Writer
Dir string
Env []string
Command []string
Timeout time.Duration
Stdin io.Reader
Stdout io.Writer
Dir string
Env []string
ExtraFiles []*os.File
}
// Command create a simple Cmd with the specified command and arguments
@ -252,6 +254,8 @@ func buildCmd(cmd Cmd) *Result {
execCmd.Stdout = outBuffer
}
execCmd.Stderr = errBuffer
execCmd.ExtraFiles = cmd.ExtraFiles
return &Result{
Cmd: execCmd,
outBuffer: outBuffer,

View file

@ -2,6 +2,7 @@ package icmd
import (
"io"
"os"
"time"
)
@ -36,3 +37,10 @@ func WithStdin(r io.Reader) CmdOp {
c.Stdin = r
}
}
// WithExtraFile adds a file descriptor to the command
func WithExtraFile(f *os.File) CmdOp {
return func(c *Cmd) {
c.ExtraFiles = append(c.ExtraFiles, f)
}
}

View file

@ -0,0 +1,45 @@
/*Package cleanup handles migration to and support for the Go 1.14+
testing.TB.Cleanup() function.
*/
package cleanup
import (
"os"
"strings"
"gotest.tools/v3/x/subtest"
)
type cleanupT interface {
Cleanup(f func())
}
type logT interface {
Log(...interface{})
}
type helperT interface {
Helper()
}
var noCleanup = strings.ToLower(os.Getenv("TEST_NOCLEANUP")) == "true"
// Cleanup registers f as a cleanup function on t if any mechanisms are available.
//
// Skips registering f if TEST_NOCLEANUP is set to true.
func Cleanup(t logT, f func()) {
if ht, ok := t.(helperT); ok {
ht.Helper()
}
if noCleanup {
t.Log("skipping cleanup because TEST_NOCLEANUP was enabled.")
return
}
if ct, ok := t.(cleanupT); ok {
ct.Cleanup(f)
return
}
if tc, ok := t.(subtest.TestContext); ok {
tc.AddCleanup(f)
}
}

View file

@ -4,7 +4,7 @@ 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/internal/difflib"
package difflib // import "gotest.tools/v3/internal/difflib"
func min(a, b int) int {
if a < b {

View file

@ -6,7 +6,7 @@ import (
"strings"
"unicode"
"gotest.tools/internal/difflib"
"gotest.tools/v3/internal/difflib"
)
const (

View file

@ -1,4 +1,4 @@
package format // import "gotest.tools/internal/format"
package format // import "gotest.tools/v3/internal/format"
import "fmt"

View file

@ -1,4 +1,4 @@
package source // import "gotest.tools/internal/source"
package source // import "gotest.tools/v3/internal/source"
import (
"bytes"
@ -92,7 +92,9 @@ func nodePosition(fileset *token.FileSet, node ast.Node) token.Position {
return fileset.Position(node.Pos())
}
var goVersionBefore19 = func() bool {
// GoVersionLessThan returns true if runtime.Version() is semantically less than
// version 1.minor.
func GoVersionLessThan(minor int64) bool {
version := runtime.Version()
// not a release version
if !strings.HasPrefix(version, "go") {
@ -103,9 +105,11 @@ var goVersionBefore19 = func() bool {
if len(parts) < 2 {
return false
}
minor, err := strconv.ParseInt(parts[1], 10, 32)
return err == nil && parts[0] == "1" && minor < 9
}()
actual, err := strconv.ParseInt(parts[1], 10, 32)
return err == nil && parts[0] == "1" && actual < minor
}
var goVersionBefore19 = GoVersionLessThan(9)
func getCallExprArgs(node ast.Node) ([]ast.Expr, error) {
visitor := &callExprVisitor{}

View file

@ -1,6 +1,6 @@
/*Package poll provides tools for testing asynchronous code.
*/
package poll // import "gotest.tools/poll"
package poll // import "gotest.tools/v3/poll"
import (
"fmt"

View file

@ -1,7 +1,7 @@
/*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/skip"
package skip // import "gotest.tools/v3/skip"
import (
"fmt"
@ -10,8 +10,8 @@ import (
"runtime"
"strings"
"gotest.tools/internal/format"
"gotest.tools/internal/source"
"gotest.tools/v3/internal/format"
"gotest.tools/v3/internal/source"
)
type skipT interface {

View file

@ -3,7 +3,7 @@ provides a testing.TB, and context.Context.
This package was inspired by github.com/frankban/quicktest.
*/
package subtest // import "gotest.tools/x/subtest"
package subtest // import "gotest.tools/v3/x/subtest"
import (
"context"
@ -27,9 +27,9 @@ func (tc *testcase) Ctx() context.Context {
return tc.ctx
}
// Cleanup runs all cleanup functions. Functions are run in the opposite order
// cleanup runs all cleanup functions. Functions are run in the opposite order
// in which they were added. Cleanup is called automatically before Run exits.
func (tc *testcase) Cleanup() {
func (tc *testcase) cleanup() {
for _, f := range tc.cleanupFuncs {
// Defer all cleanup functions so they all run even if one calls
// t.FailNow() or panics. Deferring them also runs them in reverse order.
@ -59,7 +59,7 @@ type parallel interface {
func Run(t *testing.T, name string, subtest func(t TestContext)) bool {
return t.Run(name, func(t *testing.T) {
tc := &testcase{TB: t}
defer tc.Cleanup()
defer tc.cleanup()
subtest(tc)
})
}
@ -68,6 +68,9 @@ func Run(t *testing.T, name string, subtest func(t TestContext)) bool {
type TestContext interface {
testing.TB
// AddCleanup function which will be run when before Run returns.
//
// Deprecated: Go 1.14+ now includes a testing.TB.Cleanup(func()) which
// should be used instead. AddCleanup will be removed in a future release.
AddCleanup(f func())
// Ctx returns a context for the test case. Multiple calls from the same subtest
// will return the same context. The context is cancelled when Run