Commit 46ea3ed9 by Torkel Ödegaard

fix(godep): fixed godep dependency

parent fb7a6c07
......@@ -316,22 +316,17 @@
"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/goconvey/convey",
"Comment": "1.5.0-356-gfbc0a1c",
"Rev": "fbc0a1c888f9f96263f9a559d1769905245f1123"
},
{
"ImportPath": "github.com/smartystreets/assertions/internal/oglematchers",
"Comment": "1.6.0-6-g40711f7",
"Rev": "40711f7748186bbf9c99977cd89f21ce1a229447"
"ImportPath": "github.com/smartystreets/goconvey/convey/assertions",
"Comment": "1.5.0-356-gfbc0a1c",
"Rev": "fbc0a1c888f9f96263f9a559d1769905245f1123"
},
{
"ImportPath": "github.com/smartystreets/goconvey/convey",
"ImportPath": "github.com/smartystreets/goconvey/convey/assertions/oglematchers",
"Comment": "1.5.0-356-gfbc0a1c",
"Rev": "fbc0a1c888f9f96263f9a559d1769905245f1123"
},
......
language: go
go:
- 1.2
- 1.3
- 1.4
- 1.5
install:
- go get -t ./...
script: go test -v
sudo: false
# 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...
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.
# Cf. http://docs.travis-ci.com/user/getting-started/
# Cf. http://docs.travis-ci.com/user/languages/go/
language: go
// 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))
}
// 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
}
#ignore
-timeout=1s
-coverpkg=github.com/smartystreets/goconvey/convey/assertions,github.com/smartystreets/goconvey/convey/assertions/oglematchers
\ No newline at end of file
......@@ -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))
}
// 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)
// are referenced in the convey package for use with the So(...) method.
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
// 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 program blowing up or panicking.
// 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
......@@ -83,6 +19,8 @@ func (this *Assertion) So(actual interface{}, assert assertion, expected ...inte
// }
//
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 {
......
......@@ -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
}
......
......@@ -5,7 +5,6 @@ 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)."
)
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
}
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)!"
......@@ -34,17 +34,12 @@ 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!"
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)!"
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)!"
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!"
)
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)!"
)
......
[![GoDoc](https://godoc.org/github.com/smartystreets/assertions/internal/oglematchers?status.svg)](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 {
......
#ignore
-timeout=1s
-coverpkg=github.com/smartystreets/assertions,github.com/smartystreets/assertions/internal/oglematchers
\ No newline at end of file
......@@ -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])
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment