Skip to content

Commit

Permalink
Fix a panic when comparing types where the underlying type is string
Browse files Browse the repository at this point in the history
  • Loading branch information
jwilder committed Sep 14, 2018
1 parent f35b8ab commit b93401b
Show file tree
Hide file tree
Showing 19 changed files with 65 additions and 49 deletions.
44 changes: 22 additions & 22 deletions README.md
@@ -1,7 +1,7 @@
Testify - Thou Shalt Write Tests
================================

[![Build Status](https://travis-ci.org/stretchr/testify.svg)](https://travis-ci.org/stretchr/testify) [![Go Report Card](https://goreportcard.com/badge/github.com/stretchr/testify)](https://goreportcard.com/report/github.com/stretchr/testify) [![GoDoc](https://godoc.org/github.com/stretchr/testify?status.svg)](https://godoc.org/github.com/stretchr/testify)
[![Build Status](https://travis-ci.org/jwilder/testify.svg)](https://travis-ci.org/jwilder/testify) [![Go Report Card](https://goreportcard.com/badge/github.com/jwilder/testify)](https://goreportcard.com/report/github.com/jwilder/testify) [![GoDoc](https://godoc.org/github.com/jwilder/testify?status.svg)](https://godoc.org/github.com/jwilder/testify)

Go code (golang) set of packages that provide many tools for testifying that your code will behave as you intend.

Expand All @@ -15,13 +15,13 @@ Get started:

* Install testify with [one line of code](#installation), or [update it with another](#staying-up-to-date)
* For an introduction to writing test code in Go, see http://golang.org/doc/code.html#Testing
* Check out the API Documentation http://godoc.org/github.com/stretchr/testify
* To make your testing life easier, check out our other project, [gorc](http://github.com/stretchr/gorc)
* Check out the API Documentation http://godoc.org/github.com/jwilder/testify
* To make your testing life easier, check out our other project, [gorc](http://github.com/jwilder/gorc)
* A little about [Test-Driven Development (TDD)](http://en.wikipedia.org/wiki/Test-driven_development)



[`assert`](http://godoc.org/github.com/stretchr/testify/assert "API documentation") package
[`assert`](http://godoc.org/github.com/jwilder/testify/assert "API documentation") package
-------------------------------------------------------------------------------------------

The `assert` package provides some helpful methods that allow you to write better test code in Go.
Expand All @@ -37,7 +37,7 @@ package yours

import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/jwilder/testify/assert"
)

func TestSomething(t *testing.T) {
Expand Down Expand Up @@ -73,7 +73,7 @@ package yours

import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/jwilder/testify/assert"
)

func TestSomething(t *testing.T) {
Expand All @@ -98,14 +98,14 @@ func TestSomething(t *testing.T) {
}
```

[`require`](http://godoc.org/github.com/stretchr/testify/require "API documentation") package
[`require`](http://godoc.org/github.com/jwilder/testify/require "API documentation") package
---------------------------------------------------------------------------------------------

The `require` package provides same global functions as the `assert` package, but instead of returning a boolean result they terminate current test.

See [t.FailNow](http://golang.org/pkg/testing/#T.FailNow) for details.

[`mock`](http://godoc.org/github.com/stretchr/testify/mock "API documentation") package
[`mock`](http://godoc.org/github.com/jwilder/testify/mock "API documentation") package
----------------------------------------------------------------------------------------

The `mock` package provides a mechanism for easily writing mock objects that can be used in place of real objects when writing test code.
Expand All @@ -117,7 +117,7 @@ package yours

import (
"testing"
"github.com/stretchr/testify/mock"
"github.com/jwilder/testify/mock"
)

/*
Expand Down Expand Up @@ -190,11 +190,11 @@ func TestSomethingElse(t *testing.T) {
}
```

For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/stretchr/testify/mock).
For more information on how to write mock code, check out the [API documentation for the `mock` package](http://godoc.org/github.com/jwilder/testify/mock).

You can use the [mockery tool](http://github.com/vektra/mockery) to autogenerate the mock code against an interface as well, making using mocks much quicker.

[`suite`](http://godoc.org/github.com/stretchr/testify/suite "API documentation") package
[`suite`](http://godoc.org/github.com/jwilder/testify/suite "API documentation") package
-----------------------------------------------------------------------------------------

The `suite` package provides functionality that you might be used to from more common object oriented languages. With it, you can build a testing suite as a struct, build setup/teardown methods and testing methods on your struct, and run them with 'go test' as per normal.
Expand All @@ -205,8 +205,8 @@ An example suite is shown below:
// Basic imports
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/jwilder/testify/assert"
"github.com/jwilder/testify/suite"
)

// Define the suite, and absorb the built-in basic suite
Expand Down Expand Up @@ -236,17 +236,17 @@ func TestExampleTestSuite(t *testing.T) {
}
```

For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/stretchr/testify/blob/master/suite/suite_test.go)
For a more complete example, using all of the functionality provided by the suite package, look at our [example testing suite](https://github.com/jwilder/testify/blob/master/suite/suite_test.go)

For more information on writing suites, check out the [API documentation for the `suite` package](http://godoc.org/github.com/stretchr/testify/suite).
For more information on writing suites, check out the [API documentation for the `suite` package](http://godoc.org/github.com/jwilder/testify/suite).

`Suite` object has assertion methods:

```go
// Basic imports
import (
"testing"
"github.com/stretchr/testify/suite"
"github.com/jwilder/testify/suite"
)

// Define the suite, and absorb the built-in basic suite
Expand Down Expand Up @@ -282,13 +282,13 @@ Installation

To install Testify, use `go get`:

go get github.com/stretchr/testify
go get github.com/jwilder/testify

This will then make the following packages available to you:

github.com/stretchr/testify/assert
github.com/stretchr/testify/mock
github.com/stretchr/testify/http
github.com/jwilder/testify/assert
github.com/jwilder/testify/mock
github.com/jwilder/testify/http

Import the `testify/assert` package into your code using this template:

Expand All @@ -297,7 +297,7 @@ package yours

import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/jwilder/testify/assert"
)

func TestSomething(t *testing.T) {
Expand All @@ -312,7 +312,7 @@ func TestSomething(t *testing.T) {
Staying up to date
==================

To update Testify to the latest version, use `go get -u github.com/stretchr/testify`.
To update Testify to the latest version, use `go get -u github.com/jwilder/testify`.

------

Expand Down
4 changes: 2 additions & 2 deletions _codegen/main.go
Expand Up @@ -28,7 +28,7 @@ import (
)

var (
pkg = flag.String("assert-path", "github.com/stretchr/testify/assert", "Path to the assert package")
pkg = flag.String("assert-path", "github.com/jwilder/testify/assert", "Path to the assert package")
includeF = flag.Bool("include-format-funcs", false, "include format functions such as Errorf and Equalf")
outputPkg = flag.String("output-package", "", "package for the resulting code")
tmplFile = flag.String("template", "", "What file to load the function template from")
Expand Down Expand Up @@ -298,7 +298,7 @@ func (f *testFunc) CommentWithoutT(receiver string) string {
}

var headerTemplate = `/*
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
* CODE GENERATED AUTOMATICALLY WITH github.com/jwilder/testify/_codegen
* THIS FILE MUST NOT BE EDITED BY HAND
*/
Expand Down
2 changes: 1 addition & 1 deletion assert/assertion_format.go
@@ -1,5 +1,5 @@
/*
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
* CODE GENERATED AUTOMATICALLY WITH github.com/jwilder/testify/_codegen
* THIS FILE MUST NOT BE EDITED BY HAND
*/

Expand Down
2 changes: 1 addition & 1 deletion assert/assertion_forward.go
@@ -1,5 +1,5 @@
/*
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
* CODE GENERATED AUTOMATICALLY WITH github.com/jwilder/testify/_codegen
* THIS FILE MUST NOT BE EDITED BY HAND
*/

Expand Down
2 changes: 1 addition & 1 deletion assert/assertions.go
Expand Up @@ -1345,7 +1345,7 @@ func diff(expected interface{}, actual interface{}) string {
}

var e, a string
if ek != reflect.String {
if et.Name() != "string" {
e = spewConfig.Sdump(expected)
a = spewConfig.Sdump(actual)
} else {
Expand Down
14 changes: 14 additions & 0 deletions assert/assertions_test.go
Expand Up @@ -1791,3 +1791,17 @@ func TestErrorAssertionFunc(t *testing.T) {
})
}
}

type notstring string

// The code in the diff func used to check that the type was a kind of string
// and then do `var.(type)` on the variable containing the expected and actual
// values. This blew up when the type was a _kind_ of string but not actually
// a string.
func TestPanicOnStringLikeType(t *testing.T) {
f := func() {
mockT := new(testing.T)
Equal(mockT, notstring("value"), notstring("value2"))
}
NotPanics(t, f, "Should not panic when comparing string-ish types")
}
4 changes: 2 additions & 2 deletions assert/doc.go
Expand Up @@ -5,7 +5,7 @@
// The following is a complete example using assert in a standard test function:
// import (
// "testing"
// "github.com/stretchr/testify/assert"
// "github.com/jwilder/testify/assert"
// )
//
// func TestSomething(t *testing.T) {
Expand All @@ -21,7 +21,7 @@
//
// import (
// "testing"
// "github.com/stretchr/testify/assert"
// "github.com/jwilder/testify/assert"
// )
//
// func TestSomething(t *testing.T) {
Expand Down
6 changes: 3 additions & 3 deletions doc.go
Expand Up @@ -14,9 +14,9 @@ package testify
// blank imports help docs.
import (
// assert package
_ "github.com/stretchr/testify/assert"
_ "github.com/jwilder/testify/assert"
// http package
_ "github.com/stretchr/testify/http"
_ "github.com/jwilder/testify/http"
// mock package
_ "github.com/stretchr/testify/mock"
_ "github.com/jwilder/testify/mock"
)
3 changes: 2 additions & 1 deletion http/test_round_tripper.go
@@ -1,8 +1,9 @@
package http

import (
"github.com/stretchr/testify/mock"
"net/http"

"github.com/jwilder/testify/mock"
)

// TestRoundTripper DEPRECATED USE net/http/httptest
Expand Down
2 changes: 1 addition & 1 deletion mock/mock.go
Expand Up @@ -11,9 +11,9 @@ import (
"time"

"github.com/davecgh/go-spew/spew"
"github.com/jwilder/testify/assert"
"github.com/pmezard/go-difflib/difflib"
"github.com/stretchr/objx"
"github.com/stretchr/testify/assert"
)

// TestingT is an interface wrapper around *testing.T
Expand Down
4 changes: 2 additions & 2 deletions mock/mock_test.go
Expand Up @@ -9,8 +9,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/jwilder/testify/assert"
"github.com/jwilder/testify/require"
)

/*
Expand Down
3 changes: 2 additions & 1 deletion package_test.go
@@ -1,8 +1,9 @@
package testify

import (
"github.com/stretchr/testify/assert"
"testing"

"github.com/jwilder/testify/assert"
)

func TestImports(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion require/doc.go
Expand Up @@ -6,7 +6,7 @@
// The following is a complete example using require in a standard test function:
// import (
// "testing"
// "github.com/stretchr/testify/require"
// "github.com/jwilder/testify/require"
// )
//
// func TestSomething(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions require/require.go
@@ -1,12 +1,12 @@
/*
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
* CODE GENERATED AUTOMATICALLY WITH github.com/jwilder/testify/_codegen
* THIS FILE MUST NOT BE EDITED BY HAND
*/

package require

import (
assert "github.com/stretchr/testify/assert"
assert "github.com/jwilder/testify/assert"
http "net/http"
url "net/url"
time "time"
Expand Down
4 changes: 2 additions & 2 deletions require/require_forward.go
@@ -1,12 +1,12 @@
/*
* CODE GENERATED AUTOMATICALLY WITH github.com/stretchr/testify/_codegen
* CODE GENERATED AUTOMATICALLY WITH github.com/jwilder/testify/_codegen
* THIS FILE MUST NOT BE EDITED BY HAND
*/

package require

import (
assert "github.com/stretchr/testify/assert"
assert "github.com/jwilder/testify/assert"
http "net/http"
url "net/url"
time "time"
Expand Down
4 changes: 2 additions & 2 deletions suite/doc.go
Expand Up @@ -32,8 +32,8 @@
// // Basic imports
// import (
// "testing"
// "github.com/stretchr/testify/assert"
// "github.com/stretchr/testify/suite"
// "github.com/jwilder/testify/assert"
// "github.com/jwilder/testify/suite"
// )
//
// // Define the suite, and absorb the built-in basic suite
Expand Down
4 changes: 2 additions & 2 deletions suite/suite.go
Expand Up @@ -8,8 +8,8 @@ import (
"regexp"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/jwilder/testify/assert"
"github.com/jwilder/testify/require"
)

var allTestsFilter = func(_, _ string) (bool, error) { return true, nil }
Expand Down
4 changes: 2 additions & 2 deletions suite/suite_test.go
Expand Up @@ -7,8 +7,8 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/jwilder/testify/assert"
"github.com/jwilder/testify/require"
)

// SuiteRequireTwice is intended to test the usage of suite.Require in two
Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/stretchr/objx/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b93401b

Please sign in to comment.