mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
fix(godep): fixed godep dependency
This commit is contained in:
parent
fb7a6c0764
commit
46ea3ed971
25
Godeps/Godeps.json
generated
25
Godeps/Godeps.json
generated
@ -315,26 +315,21 @@
|
||||
"ImportPath": "github.com/rainycape/unidecode",
|
||||
"Rev": "836ef0a715aedf08a12d595ed73ec8ed5b288cac"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/assertions",
|
||||
"Comment": "1.6.0-6-g40711f7",
|
||||
"Rev": "40711f7748186bbf9c99977cd89f21ce1a229447"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/assertions/internal/go-render/render",
|
||||
"Comment": "1.6.0-6-g40711f7",
|
||||
"Rev": "40711f7748186bbf9c99977cd89f21ce1a229447"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/assertions/internal/oglematchers",
|
||||
"Comment": "1.6.0-6-g40711f7",
|
||||
"Rev": "40711f7748186bbf9c99977cd89f21ce1a229447"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/goconvey/convey",
|
||||
"Comment": "1.5.0-356-gfbc0a1c",
|
||||
"Rev": "fbc0a1c888f9f96263f9a559d1769905245f1123"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/goconvey/convey/assertions",
|
||||
"Comment": "1.5.0-356-gfbc0a1c",
|
||||
"Rev": "fbc0a1c888f9f96263f9a559d1769905245f1123"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/goconvey/convey/assertions/oglematchers",
|
||||
"Comment": "1.5.0-356-gfbc0a1c",
|
||||
"Rev": "fbc0a1c888f9f96263f9a559d1769905245f1123"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/smartystreets/goconvey/convey/gotest",
|
||||
"Comment": "1.5.0-356-gfbc0a1c",
|
||||
|
3
Godeps/_workspace/src/github.com/smartystreets/assertions/.gitignore
generated
vendored
3
Godeps/_workspace/src/github.com/smartystreets/assertions/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
/.idea
|
14
Godeps/_workspace/src/github.com/smartystreets/assertions/.travis.yml
generated
vendored
14
Godeps/_workspace/src/github.com/smartystreets/assertions/.travis.yml
generated
vendored
@ -1,14 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.2
|
||||
- 1.3
|
||||
- 1.4
|
||||
- 1.5
|
||||
|
||||
install:
|
||||
- go get -t ./...
|
||||
|
||||
script: go test -v
|
||||
|
||||
sudo: false
|
12
Godeps/_workspace/src/github.com/smartystreets/assertions/CONTRIBUTING.md
generated
vendored
12
Godeps/_workspace/src/github.com/smartystreets/assertions/CONTRIBUTING.md
generated
vendored
@ -1,12 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
In general, the code posted to the [SmartyStreets github organization](https://github.com/smartystreets) is created to solve specific problems at SmartyStreets that are ancillary to our core products in the address verification industry and may or may not be useful to other organizations or developers. Our reason for posting said code isn't necessarily to solicit feedback or contributions from the community but more as a showcase of some of the approaches to solving problems we have adopted.
|
||||
|
||||
Having stated that, we do consider issues raised by other githubbers as well as contributions submitted via pull requests. When submitting such a pull request, please follow these guidelines:
|
||||
|
||||
- _Look before you leap:_ If the changes you plan to make are significant, it's in everyone's best interest for you to discuss them with a SmartyStreets team member prior to opening a pull request.
|
||||
- _License and ownership:_ If modifying the `LICENSE.md` file, limit your changes to fixing typographical mistakes. Do NOT modify the actual terms in the license or the copyright by **SmartyStreets, LLC**. Code submitted to SmartyStreets projects becomes property of SmartyStreets and must be compatible with the associated license.
|
||||
- _Testing:_ If the code you are submitting resides in packages/modules covered by automated tests, be sure to add passing tests that cover your changes and assert expected behavior and state. Submit the additional test cases as part of your change set.
|
||||
- _Style:_ Match your approach to **naming** and **formatting** with the surrounding code. Basically, the code you submit shouldn't stand out.
|
||||
- "Naming" refers to such constructs as variables, methods, functions, classes, structs, interfaces, packages, modules, directories, files, etc...
|
||||
- "Formatting" refers to such constructs as whitespace, horizontal line length, vertical function length, vertical file length, indentation, curly braces, etc...
|
23
Godeps/_workspace/src/github.com/smartystreets/assertions/LICENSE.md
generated
vendored
23
Godeps/_workspace/src/github.com/smartystreets/assertions/LICENSE.md
generated
vendored
@ -1,23 +0,0 @@
|
||||
Copyright (c) 2016 SmartyStreets, LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
NOTE: Various optional and subordinate components carry their own licensing
|
||||
requirements and restrictions. Use of those components is subject to the terms
|
||||
and conditions outlined the respective license of each component.
|
575
Godeps/_workspace/src/github.com/smartystreets/assertions/README.md
generated
vendored
575
Godeps/_workspace/src/github.com/smartystreets/assertions/README.md
generated
vendored
@ -1,575 +0,0 @@
|
||||
# assertions
|
||||
--
|
||||
import "github.com/smartystreets/assertions"
|
||||
|
||||
Package assertions contains the implementations for all assertions which are
|
||||
referenced in goconvey's `convey` package
|
||||
(github.com/smartystreets/goconvey/convey) and gunit
|
||||
(github.com/smartystreets/gunit) for use with the So(...) method. They can also
|
||||
be used in traditional Go test functions and even in applications.
|
||||
|
||||
Many of the assertions lean heavily on work done by Aaron Jacobs in his
|
||||
excellent oglematchers library. (https://github.com/jacobsa/oglematchers) The
|
||||
ShouldResemble assertion leans heavily on work done by Daniel Jacques in his
|
||||
very helpful go-render library. (https://github.com/luci/go-render)
|
||||
|
||||
## Usage
|
||||
|
||||
#### func GoConveyMode
|
||||
|
||||
```go
|
||||
func GoConveyMode(yes bool)
|
||||
```
|
||||
GoConveyMode provides control over JSON serialization of failures. When using
|
||||
the assertions in this package from the convey package JSON results are very
|
||||
helpful and can be rendered in a DIFF view. In that case, this function will be
|
||||
called with a true value to enable the JSON serialization. By default, the
|
||||
assertions in this package will not serializer a JSON result, making standalone
|
||||
ussage more convenient.
|
||||
|
||||
#### func ShouldAlmostEqual
|
||||
|
||||
```go
|
||||
func ShouldAlmostEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldAlmostEqual makes sure that two parameters are close enough to being
|
||||
equal. The acceptable delta may be specified with a third argument, or a very
|
||||
small default delta will be used.
|
||||
|
||||
#### func ShouldBeBetween
|
||||
|
||||
```go
|
||||
func ShouldBeBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeBetween receives exactly three parameters: an actual value, a lower
|
||||
bound, and an upper bound. It ensures that the actual value is between both
|
||||
bounds (but not equal to either of them).
|
||||
|
||||
#### func ShouldBeBetweenOrEqual
|
||||
|
||||
```go
|
||||
func ShouldBeBetweenOrEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeBetweenOrEqual receives exactly three parameters: an actual value, a
|
||||
lower bound, and an upper bound. It ensures that the actual value is between
|
||||
both bounds or equal to one of them.
|
||||
|
||||
#### func ShouldBeBlank
|
||||
|
||||
```go
|
||||
func ShouldBeBlank(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeBlank receives exactly 1 string parameter and ensures that it is equal
|
||||
to "".
|
||||
|
||||
#### func ShouldBeChronological
|
||||
|
||||
```go
|
||||
func ShouldBeChronological(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeChronological receives a []time.Time slice and asserts that the are in
|
||||
chronological order starting with the first time.Time as the earliest.
|
||||
|
||||
#### func ShouldBeEmpty
|
||||
|
||||
```go
|
||||
func ShouldBeEmpty(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeEmpty receives a single parameter (actual) and determines whether or not
|
||||
calling len(actual) would return `0`. It obeys the rules specified by the len
|
||||
function for determining length: http://golang.org/pkg/builtin/#len
|
||||
|
||||
#### func ShouldBeFalse
|
||||
|
||||
```go
|
||||
func ShouldBeFalse(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeFalse receives a single parameter and ensures that it is false.
|
||||
|
||||
#### func ShouldBeGreaterThan
|
||||
|
||||
```go
|
||||
func ShouldBeGreaterThan(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeGreaterThan receives exactly two parameters and ensures that the first
|
||||
is greater than the second.
|
||||
|
||||
#### func ShouldBeGreaterThanOrEqualTo
|
||||
|
||||
```go
|
||||
func ShouldBeGreaterThanOrEqualTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeGreaterThanOrEqualTo receives exactly two parameters and ensures that
|
||||
the first is greater than or equal to the second.
|
||||
|
||||
#### func ShouldBeIn
|
||||
|
||||
```go
|
||||
func ShouldBeIn(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeIn receives at least 2 parameters. The first is a proposed member of the
|
||||
collection that is passed in either as the second parameter, or of the
|
||||
collection that is comprised of all the remaining parameters. This assertion
|
||||
ensures that the proposed member is in the collection (using ShouldEqual).
|
||||
|
||||
#### func ShouldBeLessThan
|
||||
|
||||
```go
|
||||
func ShouldBeLessThan(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeLessThan receives exactly two parameters and ensures that the first is
|
||||
less than the second.
|
||||
|
||||
#### func ShouldBeLessThanOrEqualTo
|
||||
|
||||
```go
|
||||
func ShouldBeLessThanOrEqualTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeLessThan receives exactly two parameters and ensures that the first is
|
||||
less than or equal to the second.
|
||||
|
||||
#### func ShouldBeNil
|
||||
|
||||
```go
|
||||
func ShouldBeNil(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeNil receives a single parameter and ensures that it is nil.
|
||||
|
||||
#### func ShouldBeTrue
|
||||
|
||||
```go
|
||||
func ShouldBeTrue(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeTrue receives a single parameter and ensures that it is true.
|
||||
|
||||
#### func ShouldBeZeroValue
|
||||
|
||||
```go
|
||||
func ShouldBeZeroValue(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldBeZeroValue receives a single parameter and ensures that it is the Go
|
||||
equivalent of the default value, or "zero" value.
|
||||
|
||||
#### func ShouldContain
|
||||
|
||||
```go
|
||||
func ShouldContain(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldContain receives exactly two parameters. The first is a slice and the
|
||||
second is a proposed member. Membership is determined using ShouldEqual.
|
||||
|
||||
#### func ShouldContainKey
|
||||
|
||||
```go
|
||||
func ShouldContainKey(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldContainKey receives exactly two parameters. The first is a map and the
|
||||
second is a proposed key. Keys are compared with a simple '=='.
|
||||
|
||||
#### func ShouldContainSubstring
|
||||
|
||||
```go
|
||||
func ShouldContainSubstring(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldContainSubstring receives exactly 2 string parameters and ensures that the
|
||||
first contains the second as a substring.
|
||||
|
||||
#### func ShouldEndWith
|
||||
|
||||
```go
|
||||
func ShouldEndWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEndWith receives exactly 2 string parameters and ensures that the first
|
||||
ends with the second.
|
||||
|
||||
#### func ShouldEqual
|
||||
|
||||
```go
|
||||
func ShouldEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqual receives exactly two parameters and does an equality check.
|
||||
|
||||
#### func ShouldEqualTrimSpace
|
||||
|
||||
```go
|
||||
func ShouldEqualTrimSpace(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqualTrimSpace receives exactly 2 string parameters and ensures that the
|
||||
first is equal to the second after removing all leading and trailing whitespace
|
||||
using strings.TrimSpace(first).
|
||||
|
||||
#### func ShouldEqualWithout
|
||||
|
||||
```go
|
||||
func ShouldEqualWithout(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEqualWithout receives exactly 3 string parameters and ensures that the
|
||||
first is equal to the second after removing all instances of the third from the
|
||||
first using strings.Replace(first, third, "", -1).
|
||||
|
||||
#### func ShouldHappenAfter
|
||||
|
||||
```go
|
||||
func ShouldHappenAfter(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenAfter receives exactly 2 time.Time arguments and asserts that the
|
||||
first happens after the second.
|
||||
|
||||
#### func ShouldHappenBefore
|
||||
|
||||
```go
|
||||
func ShouldHappenBefore(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenBefore receives exactly 2 time.Time arguments and asserts that the
|
||||
first happens before the second.
|
||||
|
||||
#### func ShouldHappenBetween
|
||||
|
||||
```go
|
||||
func ShouldHappenBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenBetween receives exactly 3 time.Time arguments and asserts that the
|
||||
first happens between (not on) the second and third.
|
||||
|
||||
#### func ShouldHappenOnOrAfter
|
||||
|
||||
```go
|
||||
func ShouldHappenOnOrAfter(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenOnOrAfter receives exactly 2 time.Time arguments and asserts that
|
||||
the first happens on or after the second.
|
||||
|
||||
#### func ShouldHappenOnOrBefore
|
||||
|
||||
```go
|
||||
func ShouldHappenOnOrBefore(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenOnOrBefore receives exactly 2 time.Time arguments and asserts that
|
||||
the first happens on or before the second.
|
||||
|
||||
#### func ShouldHappenOnOrBetween
|
||||
|
||||
```go
|
||||
func ShouldHappenOnOrBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenOnOrBetween receives exactly 3 time.Time arguments and asserts that
|
||||
the first happens between or on the second and third.
|
||||
|
||||
#### func ShouldHappenWithin
|
||||
|
||||
```go
|
||||
func ShouldHappenWithin(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHappenWithin receives a time.Time, a time.Duration, and a time.Time (3
|
||||
arguments) and asserts that the first time.Time happens within or on the
|
||||
duration specified relative to the other time.Time.
|
||||
|
||||
#### func ShouldHaveLength
|
||||
|
||||
```go
|
||||
func ShouldHaveLength(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHaveLength receives 2 parameters. The first is a collection to check the
|
||||
length of, the second being the expected length. It obeys the rules specified by
|
||||
the len function for determining length: http://golang.org/pkg/builtin/#len
|
||||
|
||||
#### func ShouldHaveSameTypeAs
|
||||
|
||||
```go
|
||||
func ShouldHaveSameTypeAs(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldHaveSameTypeAs receives exactly two parameters and compares their
|
||||
underlying types for equality.
|
||||
|
||||
#### func ShouldImplement
|
||||
|
||||
```go
|
||||
func ShouldImplement(actual interface{}, expectedList ...interface{}) string
|
||||
```
|
||||
ShouldImplement receives exactly two parameters and ensures that the first
|
||||
implements the interface type of the second.
|
||||
|
||||
#### func ShouldNotAlmostEqual
|
||||
|
||||
```go
|
||||
func ShouldNotAlmostEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotAlmostEqual is the inverse of ShouldAlmostEqual
|
||||
|
||||
#### func ShouldNotBeBetween
|
||||
|
||||
```go
|
||||
func ShouldNotBeBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeBetween receives exactly three parameters: an actual value, a lower
|
||||
bound, and an upper bound. It ensures that the actual value is NOT between both
|
||||
bounds.
|
||||
|
||||
#### func ShouldNotBeBetweenOrEqual
|
||||
|
||||
```go
|
||||
func ShouldNotBeBetweenOrEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeBetweenOrEqual receives exactly three parameters: an actual value, a
|
||||
lower bound, and an upper bound. It ensures that the actual value is nopt
|
||||
between the bounds nor equal to either of them.
|
||||
|
||||
#### func ShouldNotBeBlank
|
||||
|
||||
```go
|
||||
func ShouldNotBeBlank(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is
|
||||
equal to "".
|
||||
|
||||
#### func ShouldNotBeEmpty
|
||||
|
||||
```go
|
||||
func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeEmpty receives a single parameter (actual) and determines whether or
|
||||
not calling len(actual) would return a value greater than zero. It obeys the
|
||||
rules specified by the `len` function for determining length:
|
||||
http://golang.org/pkg/builtin/#len
|
||||
|
||||
#### func ShouldNotBeIn
|
||||
|
||||
```go
|
||||
func ShouldNotBeIn(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeIn receives at least 2 parameters. The first is a proposed member of
|
||||
the collection that is passed in either as the second parameter, or of the
|
||||
collection that is comprised of all the remaining parameters. This assertion
|
||||
ensures that the proposed member is NOT in the collection (using ShouldEqual).
|
||||
|
||||
#### func ShouldNotBeNil
|
||||
|
||||
```go
|
||||
func ShouldNotBeNil(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotBeNil receives a single parameter and ensures that it is not nil.
|
||||
|
||||
#### func ShouldNotContain
|
||||
|
||||
```go
|
||||
func ShouldNotContain(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotContain receives exactly two parameters. The first is a slice and the
|
||||
second is a proposed member. Membership is determinied using ShouldEqual.
|
||||
|
||||
#### func ShouldNotContainKey
|
||||
|
||||
```go
|
||||
func ShouldNotContainKey(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotContainKey receives exactly two parameters. The first is a map and the
|
||||
second is a proposed absent key. Keys are compared with a simple '=='.
|
||||
|
||||
#### func ShouldNotContainSubstring
|
||||
|
||||
```go
|
||||
func ShouldNotContainSubstring(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotContainSubstring receives exactly 2 string parameters and ensures that
|
||||
the first does NOT contain the second as a substring.
|
||||
|
||||
#### func ShouldNotEndWith
|
||||
|
||||
```go
|
||||
func ShouldNotEndWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldEndWith receives exactly 2 string parameters and ensures that the first
|
||||
does not end with the second.
|
||||
|
||||
#### func ShouldNotEqual
|
||||
|
||||
```go
|
||||
func ShouldNotEqual(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotEqual receives exactly two parameters and does an inequality check.
|
||||
|
||||
#### func ShouldNotHappenOnOrBetween
|
||||
|
||||
```go
|
||||
func ShouldNotHappenOnOrBetween(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotHappenOnOrBetween receives exactly 3 time.Time arguments and asserts
|
||||
that the first does NOT happen between or on the second or third.
|
||||
|
||||
#### func ShouldNotHappenWithin
|
||||
|
||||
```go
|
||||
func ShouldNotHappenWithin(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotHappenWithin receives a time.Time, a time.Duration, and a time.Time (3
|
||||
arguments) and asserts that the first time.Time does NOT happen within or on the
|
||||
duration specified relative to the other time.Time.
|
||||
|
||||
#### func ShouldNotHaveSameTypeAs
|
||||
|
||||
```go
|
||||
func ShouldNotHaveSameTypeAs(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotHaveSameTypeAs receives exactly two parameters and compares their
|
||||
underlying types for inequality.
|
||||
|
||||
#### func ShouldNotImplement
|
||||
|
||||
```go
|
||||
func ShouldNotImplement(actual interface{}, expectedList ...interface{}) string
|
||||
```
|
||||
ShouldNotImplement receives exactly two parameters and ensures that the first
|
||||
does NOT implement the interface type of the second.
|
||||
|
||||
#### func ShouldNotPanic
|
||||
|
||||
```go
|
||||
func ShouldNotPanic(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldNotPanic receives a void, niladic function and expects to execute the
|
||||
function without any panic.
|
||||
|
||||
#### func ShouldNotPanicWith
|
||||
|
||||
```go
|
||||
func ShouldNotPanicWith(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldNotPanicWith receives a void, niladic function and expects to recover a
|
||||
panic whose content differs from the second argument.
|
||||
|
||||
#### func ShouldNotPointTo
|
||||
|
||||
```go
|
||||
func ShouldNotPointTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotPointTo receives exactly two parameters and checks to see that they
|
||||
point to different addresess.
|
||||
|
||||
#### func ShouldNotResemble
|
||||
|
||||
```go
|
||||
func ShouldNotResemble(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotResemble receives exactly two parameters and does an inverse deep equal
|
||||
check (see reflect.DeepEqual)
|
||||
|
||||
#### func ShouldNotStartWith
|
||||
|
||||
```go
|
||||
func ShouldNotStartWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldNotStartWith receives exactly 2 string parameters and ensures that the
|
||||
first does not start with the second.
|
||||
|
||||
#### func ShouldPanic
|
||||
|
||||
```go
|
||||
func ShouldPanic(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldPanic receives a void, niladic function and expects to recover a panic.
|
||||
|
||||
#### func ShouldPanicWith
|
||||
|
||||
```go
|
||||
func ShouldPanicWith(actual interface{}, expected ...interface{}) (message string)
|
||||
```
|
||||
ShouldPanicWith receives a void, niladic function and expects to recover a panic
|
||||
with the second argument as the content.
|
||||
|
||||
#### func ShouldPointTo
|
||||
|
||||
```go
|
||||
func ShouldPointTo(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldPointTo receives exactly two parameters and checks to see that they point
|
||||
to the same address.
|
||||
|
||||
#### func ShouldResemble
|
||||
|
||||
```go
|
||||
func ShouldResemble(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldResemble receives exactly two parameters and does a deep equal check (see
|
||||
reflect.DeepEqual)
|
||||
|
||||
#### func ShouldStartWith
|
||||
|
||||
```go
|
||||
func ShouldStartWith(actual interface{}, expected ...interface{}) string
|
||||
```
|
||||
ShouldStartWith receives exactly 2 string parameters and ensures that the first
|
||||
starts with the second.
|
||||
|
||||
#### func So
|
||||
|
||||
```go
|
||||
func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string)
|
||||
```
|
||||
So is a convenience function (as opposed to an inconvenience function?) for
|
||||
running assertions on arbitrary arguments in any context, be it for testing or
|
||||
even application logging. It allows you to perform assertion-like behavior (and
|
||||
get nicely formatted messages detailing discrepancies) but without the program
|
||||
blowing up or panicking. All that is required is to import this package and call
|
||||
`So` with one of the assertions exported by this package as the second
|
||||
parameter. The first return parameter is a boolean indicating if the assertion
|
||||
was true. The second return parameter is the well-formatted message showing why
|
||||
an assertion was incorrect, or blank if the assertion was correct.
|
||||
|
||||
Example:
|
||||
|
||||
if ok, message := So(x, ShouldBeGreaterThan, y); !ok {
|
||||
log.Println(message)
|
||||
}
|
||||
|
||||
#### type Assertion
|
||||
|
||||
```go
|
||||
type Assertion struct {
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### func New
|
||||
|
||||
```go
|
||||
func New(t testingT) *Assertion
|
||||
```
|
||||
New swallows the *testing.T struct and prints failed assertions using t.Error.
|
||||
Example: assertions.New(t).So(1, should.Equal, 1)
|
||||
|
||||
#### func (*Assertion) Failed
|
||||
|
||||
```go
|
||||
func (this *Assertion) Failed() bool
|
||||
```
|
||||
Failed reports whether any calls to So (on this Assertion instance) have failed.
|
||||
|
||||
#### func (*Assertion) So
|
||||
|
||||
```go
|
||||
func (this *Assertion) So(actual interface{}, assert assertion, expected ...interface{}) bool
|
||||
```
|
||||
So calls the standalone So function and additionally, calls t.Error in failure
|
||||
scenarios.
|
||||
|
||||
#### type FailureView
|
||||
|
||||
```go
|
||||
type FailureView struct {
|
||||
Message string `json:"Message"`
|
||||
Expected string `json:"Expected"`
|
||||
Actual string `json:"Actual"`
|
||||
}
|
||||
```
|
||||
|
||||
This struct is also declared in
|
||||
github.com/smartystreets/goconvey/convey/reporting. The json struct tags should
|
||||
be equal in both declarations.
|
||||
|
||||
#### type Serializer
|
||||
|
||||
```go
|
||||
type Serializer interface {
|
||||
// contains filtered or unexported methods
|
||||
}
|
||||
```
|
3
Godeps/_workspace/src/github.com/smartystreets/assertions/assertions.goconvey
generated
vendored
3
Godeps/_workspace/src/github.com/smartystreets/assertions/assertions.goconvey
generated
vendored
@ -1,3 +0,0 @@
|
||||
#ignore
|
||||
-timeout=1s
|
||||
-coverpkg=github.com/smartystreets/assertions,github.com/smartystreets/assertions/internal/oglematchers
|
105
Godeps/_workspace/src/github.com/smartystreets/assertions/doc.go
generated
vendored
105
Godeps/_workspace/src/github.com/smartystreets/assertions/doc.go
generated
vendored
@ -1,105 +0,0 @@
|
||||
// Package assertions contains the implementations for all assertions which
|
||||
// are referenced in goconvey's `convey` package
|
||||
// (github.com/smartystreets/goconvey/convey) and gunit (github.com/smartystreets/gunit)
|
||||
// for use with the So(...) method.
|
||||
// They can also be used in traditional Go test functions and even in
|
||||
// applications.
|
||||
//
|
||||
// Many of the assertions lean heavily on work done by Aaron Jacobs in his excellent oglematchers library.
|
||||
// (https://github.com/jacobsa/oglematchers)
|
||||
// The ShouldResemble assertion leans heavily on work done by Daniel Jacques in his very helpful go-render library.
|
||||
// (https://github.com/luci/go-render)
|
||||
package assertions
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// By default we use a no-op serializer. The actual Serializer provides a JSON
|
||||
// representation of failure results on selected assertions so the goconvey
|
||||
// web UI can display a convenient diff.
|
||||
var serializer Serializer = new(noopSerializer)
|
||||
|
||||
// GoConveyMode provides control over JSON serialization of failures. When
|
||||
// using the assertions in this package from the convey package JSON results
|
||||
// are very helpful and can be rendered in a DIFF view. In that case, this function
|
||||
// will be called with a true value to enable the JSON serialization. By default,
|
||||
// the assertions in this package will not serializer a JSON result, making
|
||||
// standalone ussage more convenient.
|
||||
func GoConveyMode(yes bool) {
|
||||
if yes {
|
||||
serializer = newSerializer()
|
||||
} else {
|
||||
serializer = new(noopSerializer)
|
||||
}
|
||||
}
|
||||
|
||||
type testingT interface {
|
||||
Error(args ...interface{})
|
||||
}
|
||||
|
||||
type Assertion struct {
|
||||
t testingT
|
||||
failed bool
|
||||
}
|
||||
|
||||
// New swallows the *testing.T struct and prints failed assertions using t.Error.
|
||||
// Example: assertions.New(t).So(1, should.Equal, 1)
|
||||
func New(t testingT) *Assertion {
|
||||
return &Assertion{t: t}
|
||||
}
|
||||
|
||||
// Failed reports whether any calls to So (on this Assertion instance) have failed.
|
||||
func (this *Assertion) Failed() bool {
|
||||
return this.failed
|
||||
}
|
||||
|
||||
// So calls the standalone So function and additionally, calls t.Error in failure scenarios.
|
||||
func (this *Assertion) So(actual interface{}, assert assertion, expected ...interface{}) bool {
|
||||
ok, result := So(actual, assert, expected...)
|
||||
if !ok {
|
||||
this.failed = true
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
this.t.Error(fmt.Sprintf("\n%s:%d\n%s", file, line, result))
|
||||
}
|
||||
return ok
|
||||
}
|
||||
|
||||
// So is a convenience function (as opposed to an inconvenience function?)
|
||||
// for running assertions on arbitrary arguments in any context, be it for testing or even
|
||||
// application logging. It allows you to perform assertion-like behavior (and get nicely
|
||||
// formatted messages detailing discrepancies) but without the program blowing up or panicking.
|
||||
// All that is required is to import this package and call `So` with one of the assertions
|
||||
// exported by this package as the second parameter.
|
||||
// The first return parameter is a boolean indicating if the assertion was true. The second
|
||||
// return parameter is the well-formatted message showing why an assertion was incorrect, or
|
||||
// blank if the assertion was correct.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// if ok, message := So(x, ShouldBeGreaterThan, y); !ok {
|
||||
// log.Println(message)
|
||||
// }
|
||||
//
|
||||
func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string) {
|
||||
if result := so(actual, assert, expected...); len(result) == 0 {
|
||||
return true, result
|
||||
} else {
|
||||
return false, result
|
||||
}
|
||||
}
|
||||
|
||||
// so is like So, except that it only returns the string message, which is blank if the
|
||||
// assertion passed. Used to facilitate testing.
|
||||
func so(actual interface{}, assert func(interface{}, ...interface{}) string, expected ...interface{}) string {
|
||||
return assert(actual, expected...)
|
||||
}
|
||||
|
||||
// assertion is an alias for a function with a signature that the So()
|
||||
// function can handle. Any future or custom assertions should conform to this
|
||||
// method signature. The return value should be an empty string if the assertion
|
||||
// passes and a well-formed failure message if not.
|
||||
type assertion func(actual interface{}, expected ...interface{}) string
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
@ -1,477 +0,0 @@
|
||||
// Copyright 2015 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
package render
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sort"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var builtinTypeMap = map[reflect.Kind]string{
|
||||
reflect.Bool: "bool",
|
||||
reflect.Complex128: "complex128",
|
||||
reflect.Complex64: "complex64",
|
||||
reflect.Float32: "float32",
|
||||
reflect.Float64: "float64",
|
||||
reflect.Int16: "int16",
|
||||
reflect.Int32: "int32",
|
||||
reflect.Int64: "int64",
|
||||
reflect.Int8: "int8",
|
||||
reflect.Int: "int",
|
||||
reflect.String: "string",
|
||||
reflect.Uint16: "uint16",
|
||||
reflect.Uint32: "uint32",
|
||||
reflect.Uint64: "uint64",
|
||||
reflect.Uint8: "uint8",
|
||||
reflect.Uint: "uint",
|
||||
reflect.Uintptr: "uintptr",
|
||||
}
|
||||
|
||||
var builtinTypeSet = map[string]struct{}{}
|
||||
|
||||
func init() {
|
||||
for _, v := range builtinTypeMap {
|
||||
builtinTypeSet[v] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
var typeOfString = reflect.TypeOf("")
|
||||
var typeOfInt = reflect.TypeOf(int(1))
|
||||
var typeOfUint = reflect.TypeOf(uint(1))
|
||||
var typeOfFloat = reflect.TypeOf(10.1)
|
||||
|
||||
// Render converts a structure to a string representation. Unline the "%#v"
|
||||
// format string, this resolves pointer types' contents in structs, maps, and
|
||||
// slices/arrays and prints their field values.
|
||||
func Render(v interface{}) string {
|
||||
buf := bytes.Buffer{}
|
||||
s := (*traverseState)(nil)
|
||||
s.render(&buf, 0, reflect.ValueOf(v), false)
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
// renderPointer is called to render a pointer value.
|
||||
//
|
||||
// This is overridable so that the test suite can have deterministic pointer
|
||||
// values in its expectations.
|
||||
var renderPointer = func(buf *bytes.Buffer, p uintptr) {
|
||||
fmt.Fprintf(buf, "0x%016x", p)
|
||||
}
|
||||
|
||||
// traverseState is used to note and avoid recursion as struct members are being
|
||||
// traversed.
|
||||
//
|
||||
// traverseState is allowed to be nil. Specifically, the root state is nil.
|
||||
type traverseState struct {
|
||||
parent *traverseState
|
||||
ptr uintptr
|
||||
}
|
||||
|
||||
func (s *traverseState) forkFor(ptr uintptr) *traverseState {
|
||||
for cur := s; cur != nil; cur = cur.parent {
|
||||
if ptr == cur.ptr {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
fs := &traverseState{
|
||||
parent: s,
|
||||
ptr: ptr,
|
||||
}
|
||||
return fs
|
||||
}
|
||||
|
||||
func (s *traverseState) render(buf *bytes.Buffer, ptrs int, v reflect.Value, implicit bool) {
|
||||
if v.Kind() == reflect.Invalid {
|
||||
buf.WriteString("nil")
|
||||
return
|
||||
}
|
||||
vt := v.Type()
|
||||
|
||||
// If the type being rendered is a potentially recursive type (a type that
|
||||
// can contain itself as a member), we need to avoid recursion.
|
||||
//
|
||||
// If we've already seen this type before, mark that this is the case and
|
||||
// write a recursion placeholder instead of actually rendering it.
|
||||
//
|
||||
// If we haven't seen it before, fork our `seen` tracking so any higher-up
|
||||
// renderers will also render it at least once, then mark that we've seen it
|
||||
// to avoid recursing on lower layers.
|
||||
pe := uintptr(0)
|
||||
vk := vt.Kind()
|
||||
switch vk {
|
||||
case reflect.Ptr:
|
||||
// Since structs and arrays aren't pointers, they can't directly be
|
||||
// recursed, but they can contain pointers to themselves. Record their
|
||||
// pointer to avoid this.
|
||||
switch v.Elem().Kind() {
|
||||
case reflect.Struct, reflect.Array:
|
||||
pe = v.Pointer()
|
||||
}
|
||||
|
||||
case reflect.Slice, reflect.Map:
|
||||
pe = v.Pointer()
|
||||
}
|
||||
if pe != 0 {
|
||||
s = s.forkFor(pe)
|
||||
if s == nil {
|
||||
buf.WriteString("<REC(")
|
||||
if !implicit {
|
||||
writeType(buf, ptrs, vt)
|
||||
}
|
||||
buf.WriteString(")>")
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
isAnon := func(t reflect.Type) bool {
|
||||
if t.Name() != "" {
|
||||
if _, ok := builtinTypeSet[t.Name()]; !ok {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return t.Kind() != reflect.Interface
|
||||
}
|
||||
|
||||
switch vk {
|
||||
case reflect.Struct:
|
||||
if !implicit {
|
||||
writeType(buf, ptrs, vt)
|
||||
}
|
||||
structAnon := vt.Name() == ""
|
||||
buf.WriteRune('{')
|
||||
for i := 0; i < vt.NumField(); i++ {
|
||||
if i > 0 {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
anon := structAnon && isAnon(vt.Field(i).Type)
|
||||
|
||||
if !anon {
|
||||
buf.WriteString(vt.Field(i).Name)
|
||||
buf.WriteRune(':')
|
||||
}
|
||||
|
||||
s.render(buf, 0, v.Field(i), anon)
|
||||
}
|
||||
buf.WriteRune('}')
|
||||
|
||||
case reflect.Slice:
|
||||
if v.IsNil() {
|
||||
if !implicit {
|
||||
writeType(buf, ptrs, vt)
|
||||
buf.WriteString("(nil)")
|
||||
} else {
|
||||
buf.WriteString("nil")
|
||||
}
|
||||
return
|
||||
}
|
||||
fallthrough
|
||||
|
||||
case reflect.Array:
|
||||
if !implicit {
|
||||
writeType(buf, ptrs, vt)
|
||||
}
|
||||
anon := vt.Name() == "" && isAnon(vt.Elem())
|
||||
buf.WriteString("{")
|
||||
for i := 0; i < v.Len(); i++ {
|
||||
if i > 0 {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
|
||||
s.render(buf, 0, v.Index(i), anon)
|
||||
}
|
||||
buf.WriteRune('}')
|
||||
|
||||
case reflect.Map:
|
||||
if !implicit {
|
||||
writeType(buf, ptrs, vt)
|
||||
}
|
||||
if v.IsNil() {
|
||||
buf.WriteString("(nil)")
|
||||
} else {
|
||||
buf.WriteString("{")
|
||||
|
||||
mkeys := v.MapKeys()
|
||||
tryAndSortMapKeys(vt, mkeys)
|
||||
|
||||
kt := vt.Key()
|
||||
keyAnon := typeOfString.ConvertibleTo(kt) || typeOfInt.ConvertibleTo(kt) || typeOfUint.ConvertibleTo(kt) || typeOfFloat.ConvertibleTo(kt)
|
||||
valAnon := vt.Name() == "" && isAnon(vt.Elem())
|
||||
for i, mk := range mkeys {
|
||||
if i > 0 {
|
||||
buf.WriteString(", ")
|
||||
}
|
||||
|
||||
s.render(buf, 0, mk, keyAnon)
|
||||
buf.WriteString(":")
|
||||
s.render(buf, 0, v.MapIndex(mk), valAnon)
|
||||
}
|
||||
buf.WriteRune('}')
|
||||
}
|
||||
|
||||
case reflect.Ptr:
|
||||
ptrs++
|
||||
fallthrough
|
||||
case reflect.Interface:
|
||||
if v.IsNil() {
|
||||
writeType(buf, ptrs, v.Type())
|
||||
buf.WriteString("(nil)")
|
||||
} else {
|
||||
s.render(buf, ptrs, v.Elem(), false)
|
||||
}
|
||||
|
||||
case reflect.Chan, reflect.Func, reflect.UnsafePointer:
|
||||
writeType(buf, ptrs, vt)
|
||||
buf.WriteRune('(')
|
||||
renderPointer(buf, v.Pointer())
|
||||
buf.WriteRune(')')
|
||||
|
||||
default:
|
||||
tstr := vt.String()
|
||||
implicit = implicit || (ptrs == 0 && builtinTypeMap[vk] == tstr)
|
||||
if !implicit {
|
||||
writeType(buf, ptrs, vt)
|
||||
buf.WriteRune('(')
|
||||
}
|
||||
|
||||
switch vk {
|
||||
case reflect.String:
|
||||
fmt.Fprintf(buf, "%q", v.String())
|
||||
case reflect.Bool:
|
||||
fmt.Fprintf(buf, "%v", v.Bool())
|
||||
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
fmt.Fprintf(buf, "%d", v.Int())
|
||||
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
|
||||
fmt.Fprintf(buf, "%d", v.Uint())
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
fmt.Fprintf(buf, "%g", v.Float())
|
||||
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
fmt.Fprintf(buf, "%g", v.Complex())
|
||||
}
|
||||
|
||||
if !implicit {
|
||||
buf.WriteRune(')')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func writeType(buf *bytes.Buffer, ptrs int, t reflect.Type) {
|
||||
parens := ptrs > 0
|
||||
switch t.Kind() {
|
||||
case reflect.Chan, reflect.Func, reflect.UnsafePointer:
|
||||
parens = true
|
||||
}
|
||||
|
||||
if parens {
|
||||
buf.WriteRune('(')
|
||||
for i := 0; i < ptrs; i++ {
|
||||
buf.WriteRune('*')
|
||||
}
|
||||
}
|
||||
|
||||
switch t.Kind() {
|
||||
case reflect.Ptr:
|
||||
if ptrs == 0 {
|
||||
// This pointer was referenced from within writeType (e.g., as part of
|
||||
// rendering a list), and so hasn't had its pointer asterisk accounted
|
||||
// for.
|
||||
buf.WriteRune('*')
|
||||
}
|
||||
writeType(buf, 0, t.Elem())
|
||||
|
||||
case reflect.Interface:
|
||||
if n := t.Name(); n != "" {
|
||||
buf.WriteString(t.String())
|
||||
} else {
|
||||
buf.WriteString("interface{}")
|
||||
}
|
||||
|
||||
case reflect.Array:
|
||||
buf.WriteRune('[')
|
||||
buf.WriteString(strconv.FormatInt(int64(t.Len()), 10))
|
||||
buf.WriteRune(']')
|
||||
writeType(buf, 0, t.Elem())
|
||||
|
||||
case reflect.Slice:
|
||||
if t == reflect.SliceOf(t.Elem()) {
|
||||
buf.WriteString("[]")
|
||||
writeType(buf, 0, t.Elem())
|
||||
} else {
|
||||
// Custom slice type, use type name.
|
||||
buf.WriteString(t.String())
|
||||
}
|
||||
|
||||
case reflect.Map:
|
||||
if t == reflect.MapOf(t.Key(), t.Elem()) {
|
||||
buf.WriteString("map[")
|
||||
writeType(buf, 0, t.Key())
|
||||
buf.WriteRune(']')
|
||||
writeType(buf, 0, t.Elem())
|
||||
} else {
|
||||
// Custom map type, use type name.
|
||||
buf.WriteString(t.String())
|
||||
}
|
||||
|
||||
default:
|
||||
buf.WriteString(t.String())
|
||||
}
|
||||
|
||||
if parens {
|
||||
buf.WriteRune(')')
|
||||
}
|
||||
}
|
||||
|
||||
type cmpFn func(a, b reflect.Value) int
|
||||
|
||||
type sortableValueSlice struct {
|
||||
cmp cmpFn
|
||||
elements []reflect.Value
|
||||
}
|
||||
|
||||
func (s sortableValueSlice) Len() int {
|
||||
return len(s.elements)
|
||||
}
|
||||
|
||||
func (s sortableValueSlice) Less(i, j int) bool {
|
||||
return s.cmp(s.elements[i], s.elements[j]) < 0
|
||||
}
|
||||
|
||||
func (s sortableValueSlice) Swap(i, j int) {
|
||||
s.elements[i], s.elements[j] = s.elements[j], s.elements[i]
|
||||
}
|
||||
|
||||
// cmpForType returns a cmpFn which sorts the data for some type t in the same
|
||||
// order that a go-native map key is compared for equality.
|
||||
func cmpForType(t reflect.Type) cmpFn {
|
||||
switch t.Kind() {
|
||||
case reflect.String:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.String(), bv.String()
|
||||
if a < b {
|
||||
return -1
|
||||
} else if a > b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Bool:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.Bool(), bv.Bool()
|
||||
if !a && b {
|
||||
return -1
|
||||
} else if a && !b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.Int(), bv.Int()
|
||||
if a < b {
|
||||
return -1
|
||||
} else if a > b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32,
|
||||
reflect.Uint64, reflect.Uintptr, reflect.UnsafePointer:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.Uint(), bv.Uint()
|
||||
if a < b {
|
||||
return -1
|
||||
} else if a > b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Float32, reflect.Float64:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.Float(), bv.Float()
|
||||
if a < b {
|
||||
return -1
|
||||
} else if a > b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Interface:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.InterfaceData(), bv.InterfaceData()
|
||||
if a[0] < b[0] {
|
||||
return -1
|
||||
} else if a[0] > b[0] {
|
||||
return 1
|
||||
}
|
||||
if a[1] < b[1] {
|
||||
return -1
|
||||
} else if a[1] > b[1] {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Complex64, reflect.Complex128:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.Complex(), bv.Complex()
|
||||
if real(a) < real(b) {
|
||||
return -1
|
||||
} else if real(a) > real(b) {
|
||||
return 1
|
||||
}
|
||||
if imag(a) < imag(b) {
|
||||
return -1
|
||||
} else if imag(a) > imag(b) {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Ptr, reflect.Chan:
|
||||
return func(av, bv reflect.Value) int {
|
||||
a, b := av.Pointer(), bv.Pointer()
|
||||
if a < b {
|
||||
return -1
|
||||
} else if a > b {
|
||||
return 1
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
case reflect.Struct:
|
||||
cmpLst := make([]cmpFn, t.NumField())
|
||||
for i := range cmpLst {
|
||||
cmpLst[i] = cmpForType(t.Field(i).Type)
|
||||
}
|
||||
return func(a, b reflect.Value) int {
|
||||
for i, cmp := range cmpLst {
|
||||
if rslt := cmp(a.Field(i), b.Field(i)); rslt != 0 {
|
||||
return rslt
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func tryAndSortMapKeys(mt reflect.Type, k []reflect.Value) {
|
||||
if cmp := cmpForType(mt.Key()); cmp != nil {
|
||||
sort.Sort(sortableValueSlice{cmp, k})
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
# Cf. http://docs.travis-ci.com/user/getting-started/
|
||||
# Cf. http://docs.travis-ci.com/user/languages/go/
|
||||
|
||||
language: go
|
@ -1,37 +0,0 @@
|
||||
// Copyright 2015 Aaron Jacobs. All Rights Reserved.
|
||||
// Author: aaronjjacobs@gmail.com (Aaron Jacobs)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package oglematchers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// HasSameTypeAs returns a matcher that matches values with exactly the same
|
||||
// type as the supplied prototype.
|
||||
func HasSameTypeAs(p interface{}) Matcher {
|
||||
expected := reflect.TypeOf(p)
|
||||
pred := func(c interface{}) error {
|
||||
actual := reflect.TypeOf(c)
|
||||
if actual != expected {
|
||||
return fmt.Errorf("which has type %v", actual)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
return NewMatcher(pred, fmt.Sprintf("has type %v", expected))
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
// Copyright 2015 Aaron Jacobs. All Rights Reserved.
|
||||
// Author: aaronjjacobs@gmail.com (Aaron Jacobs)
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package oglematchers
|
||||
|
||||
// Create a matcher with the given description and predicate function, which
|
||||
// will be invoked to handle calls to Matchers.
|
||||
//
|
||||
// Using this constructor may be a convenience over defining your own type that
|
||||
// implements Matcher if you do not need any logic in your Description method.
|
||||
func NewMatcher(
|
||||
predicate func(interface{}) error,
|
||||
description string) Matcher {
|
||||
return &predicateMatcher{
|
||||
predicate: predicate,
|
||||
description: description,
|
||||
}
|
||||
}
|
||||
|
||||
type predicateMatcher struct {
|
||||
predicate func(interface{}) error
|
||||
description string
|
||||
}
|
||||
|
||||
func (pm *predicateMatcher) Matches(c interface{}) error {
|
||||
return pm.predicate(c)
|
||||
}
|
||||
|
||||
func (pm *predicateMatcher) Description() string {
|
||||
return pm.description
|
||||
}
|
3
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/assertions.goconvey
generated
vendored
Normal file
3
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/assertions.goconvey
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
#ignore
|
||||
-timeout=1s
|
||||
-coverpkg=github.com/smartystreets/goconvey/convey/assertions,github.com/smartystreets/goconvey/convey/assertions/oglematchers
|
@ -4,7 +4,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
|
||||
"github.com/smartystreets/assertions/internal/oglematchers"
|
||||
"github.com/smartystreets/goconvey/convey/assertions/oglematchers"
|
||||
)
|
||||
|
||||
// ShouldContain receives exactly two parameters. The first is a slice and the
|
||||
@ -42,61 +42,6 @@ func ShouldNotContain(actual interface{}, expected ...interface{}) string {
|
||||
return fmt.Sprintf(shouldNotHaveContained, typeName, expected[0])
|
||||
}
|
||||
|
||||
// ShouldContainKey receives exactly two parameters. The first is a map and the
|
||||
// second is a proposed key. Keys are compared with a simple '=='.
|
||||
func ShouldContainKey(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(1, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
|
||||
keys, isMap := mapKeys(actual)
|
||||
if !isMap {
|
||||
return fmt.Sprintf(shouldHaveBeenAValidMap, reflect.TypeOf(actual))
|
||||
}
|
||||
|
||||
if !keyFound(keys, expected[0]) {
|
||||
return fmt.Sprintf(shouldHaveContainedKey, reflect.TypeOf(actual), expected)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
// ShouldNotContainKey receives exactly two parameters. The first is a map and the
|
||||
// second is a proposed absent key. Keys are compared with a simple '=='.
|
||||
func ShouldNotContainKey(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(1, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
|
||||
keys, isMap := mapKeys(actual)
|
||||
if !isMap {
|
||||
return fmt.Sprintf(shouldHaveBeenAValidMap, reflect.TypeOf(actual))
|
||||
}
|
||||
|
||||
if keyFound(keys, expected[0]) {
|
||||
return fmt.Sprintf(shouldNotHaveContainedKey, reflect.TypeOf(actual), expected)
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func mapKeys(m interface{}) ([]reflect.Value, bool) {
|
||||
value := reflect.ValueOf(m)
|
||||
if value.Kind() != reflect.Map {
|
||||
return nil, false
|
||||
}
|
||||
return value.MapKeys(), true
|
||||
}
|
||||
func keyFound(keys []reflect.Value, expectedKey interface{}) bool {
|
||||
found := false
|
||||
for _, key := range keys {
|
||||
if key.Interface() == expectedKey {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
return found
|
||||
}
|
||||
|
||||
// ShouldBeIn receives at least 2 parameters. The first is a proposed member of the collection
|
||||
// that is passed in either as the second parameter, or of the collection that is comprised
|
||||
// of all the remaining parameters. This assertion ensures that the proposed member is in
|
||||
@ -193,52 +138,3 @@ func ShouldNotBeEmpty(actual interface{}, expected ...interface{}) string {
|
||||
}
|
||||
return fmt.Sprintf(shouldNotHaveBeenEmpty, actual)
|
||||
}
|
||||
|
||||
// ShouldHaveLength receives 2 parameters. The first is a collection to check
|
||||
// the length of, the second being the expected length. It obeys the rules
|
||||
// specified by the len function for determining length:
|
||||
// http://golang.org/pkg/builtin/#len
|
||||
func ShouldHaveLength(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(1, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
|
||||
var expectedLen int64
|
||||
lenValue := reflect.ValueOf(expected[0])
|
||||
switch lenValue.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
expectedLen = lenValue.Int()
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
expectedLen = int64(lenValue.Uint())
|
||||
default:
|
||||
return fmt.Sprintf(shouldHaveBeenAValidInteger, reflect.TypeOf(expected[0]))
|
||||
}
|
||||
|
||||
if expectedLen < 0 {
|
||||
return fmt.Sprintf(shouldHaveBeenAValidLength, expected[0])
|
||||
}
|
||||
|
||||
value := reflect.ValueOf(actual)
|
||||
switch value.Kind() {
|
||||
case reflect.Slice,
|
||||
reflect.Chan,
|
||||
reflect.Map,
|
||||
reflect.String:
|
||||
if int64(value.Len()) == expectedLen {
|
||||
return success
|
||||
} else {
|
||||
return fmt.Sprintf(shouldHaveHadLength, actual, value.Len(), expectedLen)
|
||||
}
|
||||
case reflect.Ptr:
|
||||
elem := value.Elem()
|
||||
kind := elem.Kind()
|
||||
if kind == reflect.Slice || kind == reflect.Array {
|
||||
if int64(elem.Len()) == expectedLen {
|
||||
return success
|
||||
} else {
|
||||
return fmt.Sprintf(shouldHaveHadLength, actual, elem.Len(), expectedLen)
|
||||
}
|
||||
}
|
||||
}
|
||||
return fmt.Sprintf(shouldHaveBeenAValidCollection, reflect.TypeOf(actual))
|
||||
}
|
43
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/doc.go
generated
vendored
Normal file
43
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/doc.go
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
// Package assertions contains the implementations for all assertions which
|
||||
// are referenced in the convey package for use with the So(...) method.
|
||||
package assertions
|
||||
|
||||
// This function is not used by the goconvey library. It's actually a convenience method
|
||||
// for running assertions on arbitrary arguments outside of any testing context, like for
|
||||
// application logging. It allows you to perform assertion-like behavior (and get nicely
|
||||
// formatted messages detailing discrepancies) but without the probram blowing up or panicking.
|
||||
// All that is required is to import this package and call `So` with one of the assertions
|
||||
// exported by this package as the second parameter.
|
||||
// The first return parameter is a boolean indicating if the assertion was true. The second
|
||||
// return parameter is the well-formatted message showing why an assertion was incorrect, or
|
||||
// blank if the assertion was correct.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// if ok, message := So(x, ShouldBeGreaterThan, y); !ok {
|
||||
// log.Println(message)
|
||||
// }
|
||||
//
|
||||
func So(actual interface{}, assert assertion, expected ...interface{}) (bool, string) {
|
||||
serializer = noop
|
||||
|
||||
if result := so(actual, assert, expected...); len(result) == 0 {
|
||||
return true, result
|
||||
} else {
|
||||
return false, result
|
||||
}
|
||||
}
|
||||
|
||||
// so is like So, except that it only returns the string message, which is blank if the
|
||||
// assertion passed. Used to facilitate testing.
|
||||
func so(actual interface{}, assert func(interface{}, ...interface{}) string, expected ...interface{}) string {
|
||||
return assert(actual, expected...)
|
||||
}
|
||||
|
||||
// assertion is an alias for a function with a signature that the So()
|
||||
// function can handle. Any future or custom assertions should conform to this
|
||||
// method signature. The return value should be an empty string if the assertion
|
||||
// passes and a well-formed failure message if not.
|
||||
type assertion func(actual interface{}, expected ...interface{}) string
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
@ -7,8 +7,7 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/smartystreets/assertions/internal/oglematchers"
|
||||
"github.com/smartystreets/assertions/internal/go-render/render"
|
||||
"github.com/smartystreets/goconvey/convey/assertions/oglematchers"
|
||||
)
|
||||
|
||||
// default acceptable delta for ShouldAlmostEqual
|
||||
@ -30,14 +29,7 @@ func shouldEqual(actual, expected interface{}) (message string) {
|
||||
}()
|
||||
|
||||
if matchError := oglematchers.Equals(expected).Matches(actual); matchError != nil {
|
||||
expectedSyntax := fmt.Sprintf("%v", expected)
|
||||
actualSyntax := fmt.Sprintf("%v", actual)
|
||||
if expectedSyntax == actualSyntax && reflect.TypeOf(expected) != reflect.TypeOf(actual) {
|
||||
message = fmt.Sprintf(shouldHaveBeenEqualTypeMismatch, expected, expected, actual, actual)
|
||||
} else {
|
||||
message = fmt.Sprintf(shouldHaveBeenEqual, expected, actual)
|
||||
}
|
||||
message = serializer.serialize(expected, actual, message)
|
||||
message = serializer.serialize(expected, actual, fmt.Sprintf(shouldHaveBeenEqual, expected, actual))
|
||||
return
|
||||
}
|
||||
|
||||
@ -150,8 +142,15 @@ func ShouldResemble(actual interface{}, expected ...interface{}) string {
|
||||
}
|
||||
|
||||
if matchError := oglematchers.DeepEquals(expected[0]).Matches(actual); matchError != nil {
|
||||
return serializer.serializeDetailed(expected[0], actual,
|
||||
fmt.Sprintf(shouldHaveResembled, render.Render(expected[0]), render.Render(actual)))
|
||||
expectedSyntax := fmt.Sprintf("%#v", expected[0])
|
||||
actualSyntax := fmt.Sprintf("%#v", actual)
|
||||
var message string
|
||||
if expectedSyntax == actualSyntax {
|
||||
message = fmt.Sprintf(shouldHaveResembledTypeMismatch, expected[0], actual, expected[0], actual)
|
||||
} else {
|
||||
message = fmt.Sprintf(shouldHaveResembled, expected[0], actual)
|
||||
}
|
||||
return serializer.serializeDetailed(expected[0], actual, message)
|
||||
}
|
||||
|
||||
return success
|
||||
@ -162,7 +161,7 @@ func ShouldNotResemble(actual interface{}, expected ...interface{}) string {
|
||||
if message := need(1, expected); message != success {
|
||||
return message
|
||||
} else if ShouldResemble(actual, expected[0]) == success {
|
||||
return fmt.Sprintf(shouldNotHaveResembled, render.Render(actual), render.Render(expected[0]))
|
||||
return fmt.Sprintf(shouldNotHaveResembled, actual, expected[0])
|
||||
}
|
||||
return success
|
||||
}
|
@ -3,9 +3,8 @@ package assertions
|
||||
import "fmt"
|
||||
|
||||
const (
|
||||
success = ""
|
||||
needExactValues = "This assertion requires exactly %d comparison values (you provided %d)."
|
||||
needNonEmptyCollection = "This assertion requires at least 1 comparison value (you provided 0)."
|
||||
success = ""
|
||||
needExactValues = "This assertion requires exactly %d comparison values (you provided %d)."
|
||||
)
|
||||
|
||||
func need(needed int, expected []interface{}) string {
|
||||
@ -17,7 +16,7 @@ func need(needed int, expected []interface{}) string {
|
||||
|
||||
func atLeast(minimum int, expected []interface{}) string {
|
||||
if len(expected) < 1 {
|
||||
return needNonEmptyCollection
|
||||
return shouldHaveProvidedCollectionMembers
|
||||
}
|
||||
return success
|
||||
}
|
6
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/init.go
generated
vendored
Normal file
6
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/init.go
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
package assertions
|
||||
|
||||
var (
|
||||
serializer Serializer = newSerializer()
|
||||
noop Serializer = new(noopSerializer)
|
||||
)
|
@ -3,10 +3,10 @@ package assertions
|
||||
const ( // equality
|
||||
shouldHaveBeenEqual = "Expected: '%v'\nActual: '%v'\n(Should be equal)"
|
||||
shouldNotHaveBeenEqual = "Expected '%v'\nto NOT equal '%v'\n(but it did)!"
|
||||
shouldHaveBeenEqualTypeMismatch = "Expected: '%v' (%T)\nActual: '%v' (%T)\n(Should be equal, type mismatch)"
|
||||
shouldHaveBeenAlmostEqual = "Expected '%v' to almost equal '%v' (but it didn't)!"
|
||||
shouldHaveNotBeenAlmostEqual = "Expected '%v' to NOT almost equal '%v' (but it did)!"
|
||||
shouldHaveResembled = "Expected: '%s'\nActual: '%s'\n(Should resemble)!"
|
||||
shouldHaveResembled = "Expected: '%#v'\nActual: '%#v'\n(Should resemble)!"
|
||||
shouldHaveResembledTypeMismatch = "Expected: '%#v'\nActual: '%#v'\n(Type mismatch: '%T' vs '%T')!"
|
||||
shouldNotHaveResembled = "Expected '%#v'\nto NOT resemble '%#v'\n(but it did)!"
|
||||
shouldBePointers = "Both arguments should be pointers "
|
||||
shouldHaveBeenNonNilPointer = shouldBePointers + "(the %s was %s)!"
|
||||
@ -32,19 +32,14 @@ const ( // quantity comparisons
|
||||
)
|
||||
|
||||
const ( // collections
|
||||
shouldHaveContained = "Expected the container (%v) to contain: '%v' (but it didn't)!"
|
||||
shouldNotHaveContained = "Expected the container (%v) NOT to contain: '%v' (but it did)!"
|
||||
shouldHaveContainedKey = "Expected the %v to contain the key: %v (but it didn't)!"
|
||||
shouldNotHaveContainedKey = "Expected the %v NOT to contain the key: %v (but it did)!"
|
||||
shouldHaveBeenIn = "Expected '%v' to be in the container (%v), but it wasn't!"
|
||||
shouldNotHaveBeenIn = "Expected '%v' NOT to be in the container (%v), but it was!"
|
||||
shouldHaveBeenAValidCollection = "You must provide a valid container (was %v)!"
|
||||
shouldHaveBeenAValidMap = "You must provide a valid map type (was %v)!"
|
||||
shouldHaveBeenEmpty = "Expected %+v to be empty (but it wasn't)!"
|
||||
shouldNotHaveBeenEmpty = "Expected %+v to NOT be empty (but it was)!"
|
||||
shouldHaveBeenAValidInteger = "You must provide a valid integer (was %v)!"
|
||||
shouldHaveBeenAValidLength = "You must provide a valid positive integer (was %v)!"
|
||||
shouldHaveHadLength = "Expected %+v (length: %v) to have length equal to '%v', but it wasn't!"
|
||||
shouldHaveContained = "Expected the container (%v) to contain: '%v' (but it didn't)!"
|
||||
shouldNotHaveContained = "Expected the container (%v) NOT to contain: '%v' (but it did)!"
|
||||
shouldHaveBeenIn = "Expected '%v' to be in the container (%v, but it wasn't)!"
|
||||
shouldNotHaveBeenIn = "Expected '%v' NOT to be in the container (%v, but it was)!"
|
||||
shouldHaveBeenAValidCollection = "You must provide a valid container (was %v)!"
|
||||
shouldHaveProvidedCollectionMembers = "This assertion requires at least 1 comparison value (you provided 0)."
|
||||
shouldHaveBeenEmpty = "Expected %+v to be empty (but it wasn't)!"
|
||||
shouldNotHaveBeenEmpty = "Expected %+v to NOT be empty (but it was)!"
|
||||
)
|
||||
|
||||
const ( // strings
|
||||
@ -52,11 +47,10 @@ const ( // strings
|
||||
shouldNotHaveStartedWith = "Expected '%v'\nNOT to start with '%v'\n(but it did)!"
|
||||
shouldHaveEndedWith = "Expected '%v'\nto end with '%v'\n(but it didn't)!"
|
||||
shouldNotHaveEndedWith = "Expected '%v'\nNOT to end with '%v'\n(but it did)!"
|
||||
shouldAllBeStrings = "All arguments to this assertion must be strings (you provided: %v)."
|
||||
shouldBothBeStrings = "Both arguments to this assertion must be strings (you provided %v and %v)."
|
||||
shouldBeString = "The argument to this assertion must be a string (you provided %v)."
|
||||
shouldHaveContainedSubstring = "Expected '%s' to contain substring '%s' (but it didn't)!"
|
||||
shouldNotHaveContainedSubstring = "Expected '%s' NOT to contain substring '%s' (but it did)!"
|
||||
shouldNotHaveContainedSubstring = "Expected '%s' NOT to contain substring '%s' (but it didn't)!"
|
||||
shouldHaveBeenBlank = "Expected '%s' to be blank (but it wasn't)!"
|
||||
shouldNotHaveBeenBlank = "Expected value to NOT be blank (but it was)!"
|
||||
)
|
@ -1,5 +1,3 @@
|
||||
[](https://godoc.org/github.com/smartystreets/assertions/internal/oglematchers)
|
||||
|
||||
`oglematchers` is a package for the Go programming language containing a set of
|
||||
matchers, useful in a testing or mocking framework, inspired by and mostly
|
||||
compatible with [Google Test][googletest] for C++ and
|
||||
@ -38,21 +36,21 @@ First, make sure you have installed Go 1.0.2 or newer. See
|
||||
|
||||
Use the following command to install `oglematchers` and keep it up to date:
|
||||
|
||||
go get -u github.com/smartystreets/assertions/internal/oglematchers
|
||||
go get -u github.com/smartystreets/goconvey/convey/assertions/oglematchers
|
||||
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
See [here][reference] for documentation. Alternatively, you can install the
|
||||
package and then use `godoc`:
|
||||
See [here][reference] for documentation hosted on GoPkgDoc. Alternatively, you
|
||||
can install the package and then use `go doc`:
|
||||
|
||||
godoc github.com/smartystreets/assertions/internal/oglematchers
|
||||
go doc github.com/smartystreets/goconvey/convey/assertions/oglematchers
|
||||
|
||||
|
||||
[reference]: http://godoc.org/github.com/smartystreets/assertions/internal/oglematchers
|
||||
[reference]: http://gopkgdoc.appspot.com/pkg/github.com/smartystreets/goconvey/convey/assertions/oglematchers
|
||||
[golang-install]: http://golang.org/doc/install.html
|
||||
[googletest]: http://code.google.com/p/googletest/
|
||||
[google-js-test]: http://code.google.com/p/google-js-test/
|
||||
[ogletest]: http://github.com/smartystreets/assertions/internal/ogletest
|
||||
[oglemock]: http://github.com/smartystreets/assertions/internal/oglemock
|
||||
[ogletest]: http://github.com/smartystreets/goconvey/convey/assertions/ogletest
|
||||
[oglemock]: http://github.com/smartystreets/goconvey/convey/assertions/oglemock
|
@ -47,8 +47,7 @@ func AnyOf(vals ...interface{}) Matcher {
|
||||
// matcher.
|
||||
wrapped := make([]Matcher, len(vals))
|
||||
for i, v := range vals {
|
||||
t := reflect.TypeOf(v)
|
||||
if t != nil && t.Implements(matcherType) {
|
||||
if reflect.TypeOf(v).Implements(matcherType) {
|
||||
wrapped[i] = v.(Matcher)
|
||||
} else {
|
||||
wrapped[i] = Equals(v)
|
@ -28,7 +28,7 @@ func Contains(x interface{}) Matcher {
|
||||
var ok bool
|
||||
|
||||
if result.elementMatcher, ok = x.(Matcher); !ok {
|
||||
result.elementMatcher = DeepEquals(x)
|
||||
result.elementMatcher = Equals(x)
|
||||
}
|
||||
|
||||
return &result
|
@ -24,9 +24,8 @@ import (
|
||||
|
||||
// Equals(x) returns a matcher that matches values v such that v and x are
|
||||
// equivalent. This includes the case when the comparison v == x using Go's
|
||||
// built-in comparison operator is legal (except for structs, which this
|
||||
// matcher does not support), but for convenience the following rules also
|
||||
// apply:
|
||||
// built-in comparison operator is legal, but for convenience the following
|
||||
// rules also apply:
|
||||
//
|
||||
// * Type checking is done based on underlying types rather than actual
|
||||
// types, so that e.g. two aliases for string can be compared:
|
||||
@ -50,16 +49,11 @@ import (
|
||||
//
|
||||
// If you want a stricter matcher that contains no such cleverness, see
|
||||
// IdenticalTo instead.
|
||||
//
|
||||
// Arrays are supported by this matcher, but do not participate in the
|
||||
// exceptions above. Two arrays compared with this matcher must have identical
|
||||
// types, and their element type must itself be comparable according to Go's ==
|
||||
// operator.
|
||||
func Equals(x interface{}) Matcher {
|
||||
v := reflect.ValueOf(x)
|
||||
|
||||
// This matcher doesn't support structs.
|
||||
if v.Kind() == reflect.Struct {
|
||||
// The == operator is not defined for array or struct types.
|
||||
if v.Kind() == reflect.Array || v.Kind() == reflect.Struct {
|
||||
panic(fmt.Sprintf("oglematchers.Equals: unsupported kind %v", v.Kind()))
|
||||
}
|
||||
|
||||
@ -86,7 +80,7 @@ func isSignedInteger(v reflect.Value) bool {
|
||||
|
||||
func isUnsignedInteger(v reflect.Value) bool {
|
||||
k := v.Kind()
|
||||
return k >= reflect.Uint && k <= reflect.Uintptr
|
||||
return k >= reflect.Uint && k <= reflect.Uint64
|
||||
}
|
||||
|
||||
func isInteger(v reflect.Value) bool {
|
||||
@ -313,6 +307,19 @@ func checkAgainstBool(e bool, c reflect.Value) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func checkAgainstUintptr(e uintptr, c reflect.Value) (err error) {
|
||||
if c.Kind() != reflect.Uintptr {
|
||||
err = NewFatalError("which is not a uintptr")
|
||||
return
|
||||
}
|
||||
|
||||
err = errors.New("")
|
||||
if uintptr(c.Uint()) == e {
|
||||
err = nil
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func checkAgainstChan(e reflect.Value, c reflect.Value) (err error) {
|
||||
// Create a description of e's type, e.g. "chan int".
|
||||
typeStr := fmt.Sprintf("%s %s", e.Type().ChanDir(), e.Type().Elem())
|
||||
@ -410,25 +417,6 @@ func checkAgainstString(e reflect.Value, c reflect.Value) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func checkAgainstArray(e reflect.Value, c reflect.Value) (err error) {
|
||||
// Create a description of e's type, e.g. "[2]int".
|
||||
typeStr := fmt.Sprintf("%v", e.Type())
|
||||
|
||||
// Make sure c is the correct type.
|
||||
if c.Type() != e.Type() {
|
||||
err = NewFatalError(fmt.Sprintf("which is not %s", typeStr))
|
||||
return
|
||||
}
|
||||
|
||||
// Check for equality.
|
||||
if e.Interface() != c.Interface() {
|
||||
err = errors.New("")
|
||||
return
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func checkAgainstUnsafePointer(e reflect.Value, c reflect.Value) (err error) {
|
||||
// Make sure c is a pointer.
|
||||
if c.Kind() != reflect.UnsafePointer {
|
||||
@ -488,6 +476,9 @@ func (m *equalsMatcher) Matches(candidate interface{}) error {
|
||||
case isUnsignedInteger(e):
|
||||
return checkAgainstUint64(e.Uint(), c)
|
||||
|
||||
case ek == reflect.Uintptr:
|
||||
return checkAgainstUintptr(uintptr(e.Uint()), c)
|
||||
|
||||
case ek == reflect.Float32:
|
||||
return checkAgainstFloat32(float32(e.Float()), c)
|
||||
|
||||
@ -518,9 +509,6 @@ func (m *equalsMatcher) Matches(candidate interface{}) error {
|
||||
case ek == reflect.String:
|
||||
return checkAgainstString(e, c)
|
||||
|
||||
case ek == reflect.Array:
|
||||
return checkAgainstArray(e, c)
|
||||
|
||||
case ek == reflect.UnsafePointer:
|
||||
return checkAgainstUnsafePointer(e, c)
|
||||
|
@ -25,12 +25,18 @@ import (
|
||||
// HasSubstr returns a matcher that matches strings containing s as a
|
||||
// substring.
|
||||
func HasSubstr(s string) Matcher {
|
||||
return NewMatcher(
|
||||
func(c interface{}) error { return hasSubstr(s, c) },
|
||||
fmt.Sprintf("has substring \"%s\"", s))
|
||||
return &hasSubstrMatcher{s}
|
||||
}
|
||||
|
||||
func hasSubstr(needle string, c interface{}) error {
|
||||
type hasSubstrMatcher struct {
|
||||
needle string
|
||||
}
|
||||
|
||||
func (m *hasSubstrMatcher) Description() string {
|
||||
return fmt.Sprintf("has substring \"%s\"", m.needle)
|
||||
}
|
||||
|
||||
func (m *hasSubstrMatcher) Matches(c interface{}) error {
|
||||
v := reflect.ValueOf(c)
|
||||
if v.Kind() != reflect.String {
|
||||
return NewFatalError("which is not a string")
|
||||
@ -38,7 +44,7 @@ func hasSubstr(needle string, c interface{}) error {
|
||||
|
||||
// Perform the substring search.
|
||||
haystack := v.String()
|
||||
if strings.Contains(haystack, needle) {
|
||||
if strings.Contains(haystack, m.needle) {
|
||||
return nil
|
||||
}
|
||||
|
@ -17,8 +17,8 @@
|
||||
// mocking framework. These matchers are inspired by and mostly compatible with
|
||||
// Google Test for C++ and Google JS Test.
|
||||
//
|
||||
// This package is used by github.com/smartystreets/assertions/internal/ogletest and
|
||||
// github.com/smartystreets/assertions/internal/oglemock, which may be more directly useful if you're not
|
||||
// This package is used by github.com/smartystreets/goconvey/convey/assertions/ogletest and
|
||||
// github.com/smartystreets/goconvey/convey/assertions/oglemock, which may be more directly useful if you're not
|
||||
// writing your own testing package or defining your own matchers.
|
||||
package oglematchers
|
||||
|
||||
@ -26,10 +26,6 @@ package oglematchers
|
||||
// matches. For example, GreaterThan(17) matches all numeric values greater
|
||||
// than 17, and HasSubstr("taco") matches all strings with the substring
|
||||
// "taco".
|
||||
//
|
||||
// Matchers are typically exposed to tests via constructor functions like
|
||||
// HasSubstr. In order to implement such a function you can either define your
|
||||
// own matcher type or use NewMatcher.
|
||||
type Matcher interface {
|
||||
// Check whether the supplied value belongs to the the set defined by the
|
||||
// matcher. Return a non-nil error if and only if it does not.
|
@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
// MatchesRegexp returns a matcher that matches strings and byte slices whose
|
||||
// contents match the supplied regular expression. The semantics are those of
|
||||
// contents match the supplide regular expression. The semantics are those of
|
||||
// regexp.Match. In particular, that means the match is not implicitly anchored
|
||||
// to the ends of the string: MatchesRegexp("bar") will match "foo bar baz".
|
||||
func MatchesRegexp(pattern string) Matcher {
|
2
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/oglematchers/oglematchers.goconvey
generated
vendored
Normal file
2
Godeps/_workspace/src/github.com/smartystreets/goconvey/convey/assertions/oglematchers/oglematchers.goconvey
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
#ignore
|
||||
-timeout=1s
|
@ -3,7 +3,7 @@ package assertions
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/smartystreets/assertions/internal/oglematchers"
|
||||
"github.com/smartystreets/goconvey/convey/assertions/oglematchers"
|
||||
)
|
||||
|
||||
// ShouldBeGreaterThan receives exactly two parameters and ensures that the first is greater than the second.
|
||||
@ -43,7 +43,7 @@ func ShouldBeLessThanOrEqualTo(actual interface{}, expected ...interface{}) stri
|
||||
if fail := need(1, expected); fail != success {
|
||||
return fail
|
||||
} else if matchError := oglematchers.LessOrEqual(expected[0]).Matches(actual); matchError != nil {
|
||||
return fmt.Sprintf(shouldHaveBeenLessOrEqual, actual, expected[0])
|
||||
return fmt.Sprintf(shouldHaveBeenLess, actual, expected[0])
|
||||
}
|
||||
return success
|
||||
}
|
@ -4,7 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/smartystreets/assertions/internal/go-render/render"
|
||||
"github.com/smartystreets/goconvey/convey/reporting"
|
||||
)
|
||||
|
||||
type Serializer interface {
|
||||
@ -15,11 +15,7 @@ type Serializer interface {
|
||||
type failureSerializer struct{}
|
||||
|
||||
func (self *failureSerializer) serializeDetailed(expected, actual interface{}, message string) string {
|
||||
view := FailureView{
|
||||
Message: message,
|
||||
Expected: render.Render(expected),
|
||||
Actual: render.Render(actual),
|
||||
}
|
||||
view := self.format(expected, actual, message, "%#v")
|
||||
serialized, err := json.Marshal(view)
|
||||
if err != nil {
|
||||
return message
|
||||
@ -28,11 +24,7 @@ func (self *failureSerializer) serializeDetailed(expected, actual interface{}, m
|
||||
}
|
||||
|
||||
func (self *failureSerializer) serialize(expected, actual interface{}, message string) string {
|
||||
view := FailureView{
|
||||
Message: message,
|
||||
Expected: fmt.Sprintf("%+v", expected),
|
||||
Actual: fmt.Sprintf("%+v", actual),
|
||||
}
|
||||
view := self.format(expected, actual, message, "%+v")
|
||||
serialized, err := json.Marshal(view)
|
||||
if err != nil {
|
||||
return message
|
||||
@ -40,18 +32,16 @@ func (self *failureSerializer) serialize(expected, actual interface{}, message s
|
||||
return string(serialized)
|
||||
}
|
||||
|
||||
func newSerializer() *failureSerializer {
|
||||
return &failureSerializer{}
|
||||
func (self *failureSerializer) format(expected, actual interface{}, message string, format string) reporting.FailureView {
|
||||
return reporting.FailureView{
|
||||
Message: message,
|
||||
Expected: fmt.Sprintf(format, expected),
|
||||
Actual: fmt.Sprintf(format, actual),
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// This struct is also declared in github.com/smartystreets/goconvey/convey/reporting.
|
||||
// The json struct tags should be equal in both declarations.
|
||||
type FailureView struct {
|
||||
Message string `json:"Message"`
|
||||
Expected string `json:"Expected"`
|
||||
Actual string `json:"Actual"`
|
||||
func newSerializer() *failureSerializer {
|
||||
return &failureSerializer{}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////
|
@ -181,47 +181,3 @@ func ShouldNotBeBlank(actual interface{}, expected ...interface{}) string {
|
||||
}
|
||||
return success
|
||||
}
|
||||
|
||||
// ShouldEqualWithout receives exactly 3 string parameters and ensures that the first is equal to the second
|
||||
// after removing all instances of the third from the first using strings.Replace(first, third, "", -1).
|
||||
func ShouldEqualWithout(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(2, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
actualString, ok1 := actual.(string)
|
||||
expectedString, ok2 := expected[0].(string)
|
||||
replace, ok3 := expected[1].(string)
|
||||
|
||||
if !ok1 || !ok2 || !ok3 {
|
||||
return fmt.Sprintf(shouldAllBeStrings, []reflect.Type{
|
||||
reflect.TypeOf(actual),
|
||||
reflect.TypeOf(expected[0]),
|
||||
reflect.TypeOf(expected[1]),
|
||||
})
|
||||
}
|
||||
|
||||
replaced := strings.Replace(actualString, replace, "", -1)
|
||||
if replaced == expectedString {
|
||||
return ""
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Expected '%s' to equal '%s' but without any '%s' (but it didn't).", actualString, expectedString, replace)
|
||||
}
|
||||
|
||||
// ShouldEqualTrimSpace receives exactly 2 string parameters and ensures that the first is equal to the second
|
||||
// after removing all leading and trailing whitespace using strings.TrimSpace(first).
|
||||
func ShouldEqualTrimSpace(actual interface{}, expected ...interface{}) string {
|
||||
if fail := need(1, expected); fail != success {
|
||||
return fail
|
||||
}
|
||||
|
||||
actualString, valueIsString := actual.(string)
|
||||
_, value2IsString := expected[0].(string)
|
||||
|
||||
if !valueIsString || !value2IsString {
|
||||
return fmt.Sprintf(shouldBothBeStrings, reflect.TypeOf(actual), reflect.TypeOf(expected[0]))
|
||||
}
|
||||
|
||||
actualString = strings.TrimSpace(actualString)
|
||||
return ShouldEqual(actualString, expected[0])
|
||||
}
|
Loading…
Reference in New Issue
Block a user