Skip to content

Commit

Permalink
Run new go1.19 gofmt on source
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Aug 6, 2022
1 parent a382c45 commit e66bd80
Show file tree
Hide file tree
Showing 13 changed files with 66 additions and 54 deletions.
58 changes: 28 additions & 30 deletions assert/assert.go
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -119,19 +118,18 @@ type helperT interface {
//
// 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 or failure.
// The comparison is responsible for producing a helpful failure message.
// http://pkg.go.dev/gotest.tools/v3/assert/cmp provides many common comparisons.
// bool
// True is success. False is a failure. The failure message will contain
// the literal source code of the expression.
//
// error
// 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.
// cmp.Comparison
// Uses cmp.Result.Success() to check for success or failure.
// The comparison is responsible for producing a helpful failure message.
// http://pkg.go.dev/gotest.tools/v3/assert/cmp provides many common comparisons.
//
// error
// 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
Expand Down Expand Up @@ -187,8 +185,8 @@ func NilError(t TestingT, err error, msgAndArgs ...interface{}) {
// x and y as part of the failure message to identify the actual and expected
// values.
//
// assert.Equal(t, actual, expected)
// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32)
// assert.Equal(t, actual, expected)
// // main_test.go:41: assertion failed: 1 (actual int) != 21 (expected int32)
//
// If either x or y are a multi-line string the failure message will include a
// unified diff of the two values. If the values only differ by whitespace
Expand Down Expand Up @@ -269,19 +267,19 @@ func ErrorContains(t TestingT, err error, substring string, msgAndArgs ...interf
//
// Expected can be one of:
//
// func(error) bool
// The function should return true if the error is the expected type.
// func(error) bool
// The function should return true if the error is the expected type.
//
// struct{} or *struct{}
// A struct or a pointer to a struct. The assertion fails if the error is
// not of the same type.
// struct{} or *struct{}
// A struct or a pointer to a struct. The assertion fails if the error is
// not of the same type.
//
// *interface{}
// A pointer to an interface type. The assertion fails if err does not
// implement the interface.
// *interface{}
// A pointer to an interface type. The assertion fails if err does not
// implement the interface.
//
// reflect.Type
// The assertion fails if err does not implement the reflect.Type.
// reflect.Type
// The assertion fails if err does not implement the reflect.Type.
//
// ErrorType uses t.FailNow to fail the test. Like t.FailNow, ErrorType
// must be called from the goroutine running the test function, not from other
Expand Down
2 changes: 1 addition & 1 deletion assert/cmd/gty-migrate-from-testify/call.go
Expand Up @@ -22,7 +22,7 @@ type call struct {

func (c call) String() string {
buf := new(bytes.Buffer)
// nolint: errcheck
//nolint: errcheck
format.Node(buf, token.NewFileSet(), c.expr)
return buf.String()
}
Expand Down
3 changes: 0 additions & 3 deletions assert/cmd/gty-migrate-from-testify/doc.go
@@ -1,5 +1,4 @@
/*
Command gty-migrate-from-testify migrates packages from
testify/assert and testify/require to gotest.tools/v3/assert.
Expand All @@ -11,12 +10,10 @@ Usage:
See --help for full usage.
To run on all packages (including external test packages) use:
go list \
-f '{{.ImportPath}} {{if .XTestGoFiles}}{{"\n"}}{{.ImportPath}}_test{{end}}' \
./... | xargs gty-migrate-from-testify
*/
package main
2 changes: 1 addition & 1 deletion assert/cmd/gty-migrate-from-testify/migrate.go
Expand Up @@ -141,7 +141,7 @@ func convertTestifySingleArgCall(tcall call) ast.Node {
}
}

// nolint: maintidx
//nolint: maintidx
func convertTestifyAssertion(tcall call, migration migration) ast.Node {
imports := migration.importNames

Expand Down
25 changes: 17 additions & 8 deletions assert/cmp/compare.go
Expand Up @@ -68,9 +68,10 @@ 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))
//
// assert.Assert(t, cmp.Regexp("^[0-9a-f]{32}$", str))
// r := regexp.MustCompile("^[0-9a-f]{32}$")
// assert.Assert(t, cmp.Regexp(r, str))
func Regexp(re RegexOrPattern, v string) Comparison {
match := func(re *regexp.Regexp) Result {
return toResult(
Expand Down Expand Up @@ -248,7 +249,7 @@ type causer interface {
}

func formatErrorMessage(err error) string {
// nolint: errorlint // unwrapping is not appropriate here
//nolint: errorlint // unwrapping is not appropriate here
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
Expand Down Expand Up @@ -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
//
// func(error) bool
//
// Function should return true if the error is the expected type.
// type struct{}, type &struct{}
//
// 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{}
//
// type &interface{}
//
// A pointer to an interface type.
// Fails if err does not implement the interface.
// reflect.Type
//
// reflect.Type
//
// Fails if err does not implement the reflect.Type
func ErrorType(err error, expected interface{}) Comparison {
return func() Result {
Expand Down
3 changes: 2 additions & 1 deletion env/env.go
@@ -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"
Expand Down
7 changes: 4 additions & 3 deletions fs/file.go
@@ -1,4 +1,5 @@
/*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"
Expand Down Expand Up @@ -71,7 +72,7 @@ func (f *File) Path() string {

// Remove the file
func (f *File) Remove() {
// nolint: errcheck
//nolint: errcheck
os.Remove(f.path)
}

Expand Down Expand Up @@ -105,7 +106,7 @@ func (d *Dir) Path() string {

// Remove the directory
func (d *Dir) Remove() {
// nolint: errcheck
//nolint: errcheck
os.RemoveAll(d.path)
}

Expand Down
3 changes: 2 additions & 1 deletion golden/golden.go
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/cleanup/cleanup.go
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion pkg.go
@@ -1,4 +1,5 @@
/*Package gotesttools is a collection of packages to augment `testing` and
/*
Package gotesttools is a collection of packages to augment `testing` and
support common patterns.
*/
package gotesttools // import "gotest.tools/v3"
3 changes: 2 additions & 1 deletion skip/skip.go
@@ -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"
Expand Down
3 changes: 2 additions & 1 deletion x/doc.go
@@ -1,4 +1,5 @@
/*Package x is a namespace for experimental packages. Packages under x have looser
/*
Package x is a namespace for experimental packages. Packages under x have looser
compatibility requirements. Packages in this namespace may contain backwards
incompatible changes within the same major version.
*/
Expand Down
5 changes: 3 additions & 2 deletions x/subtest/context.go
@@ -1,9 +1,10 @@
/*Package subtest provides a TestContext to subtests which handles cleanup, and
/*
Package subtest provides a TestContext to subtests which handles cleanup, and
provides a testing.TB, and context.Context.
This package was inspired by github.com/frankban/quicktest.
DEPRECATED
# DEPRECATED
With the addition of T.Cleanup() in go1.14 this package provides very
little value. A context.Context can be managed by tests that need it with
Expand Down

0 comments on commit e66bd80

Please sign in to comment.