Giter Site home page Giter Site logo

smarty / assertions Goto Github PK

View Code? Open in Web Editor NEW
97.0 17.0 32.0 3.23 MB

Fluent assertion-style functions used by goconvey and gunit. Can also be used in any test or application.

License: Other

Go 97.98% Makefile 0.51% Python 1.22% Shell 0.29%
testing-tools goconvey gunit assertion-library go equality-check

assertions's People

Contributors

aaasen avatar adrianduke avatar aleksi avatar aybabtme avatar bborbe avatar bt avatar dancannon avatar dgryski avatar dlclark avatar duncanbeutler avatar dwhatcott avatar hatstand avatar james-maloney avatar jaredly avatar jcrob2 avatar jdeveloperw avatar m4rw3r avatar markbates avatar mdwhatcott avatar mholt avatar mtiller avatar mzimmerman avatar nickpresta avatar riannucci avatar source-gisakulabs avatar tchajed avatar vad avatar wallclockbuilder avatar xchrdw avatar yamada-wacul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

assertions's Issues

web/server/watch unit tests are failing (by 1)

golang-github-jtolds-gls-devel.noarch 0-0.10.git9a4a02d.fc27
golang-github-smartystreets-assertions-devel.noarch 1.8.0-1.fc28.llt
golang-golangorg-net-devel.noarch 0-0.40.git1c05540.fc28.llt
golang-golangorg-text-devel.noarch 0-0.21.git3bd178b.fc28

Exécution_de(%check) : /bin/sh -e /var/tmp/rpm-tmp.5OAobM

  • umask 022
  • cd /builddir/build/BUILD
  • cd goconvey-1.6.3
    ++ pwd
  • GO_BUILD_PATH=/builddir/build/BUILD/goconvey-1.6.3/_build
    ++ dirname /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey
  • install -m 0755 -vd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets
    install: creating directory '/builddir/build/BUILD/goconvey-1.6.3/_build'
    install: creating directory '/builddir/build/BUILD/goconvey-1.6.3/_build/src'
    install: creating directory '/builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com'
    install: creating directory '/builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets'
  • ln -fs /builddir/build/BUILD/goconvey-1.6.3 /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey
  • install -m 0755 -vd _bin
    install: creating directory '_bin'
  • export GOPATH=/builddir/build/BUILD/goconvey-1.6.3/_build:/usr/share/gocode
  • GOPATH=/builddir/build/BUILD/goconvey-1.6.3/_build:/usr/share/gocode
    ++ find . -iname '*.go' -exec dirname '{}' ';'
    ++ sort
    ++ sed 's+^./++'
    ++ uniq
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
    Testing .…
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey ~/build/BUILD/goconvey-1.6.3
  • for exclude in "${excludes[@]}"
  • [[ . == examples ]]
  • '[' true = true ']'
  • echo 'Testing .…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/.
  • go test -compiler gc -ldflags ''
    ? github.com/smartystreets/goconvey [no test files]
  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing convey…
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/convey ~/build/BUILD/goconvey-1.6.3
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ convey == examples ]]
  • '[' true = true ']'
  • echo 'Testing convey…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/convey
  • go test -compiler gc -ldflags ''
    PASS
    ok github.com/smartystreets/goconvey/convey 0.027s
  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing convey/gotest…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ convey/gotest == examples ]]
  • '[' true = true ']'
  • echo 'Testing convey/gotest…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/convey/gotest
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/convey/gotest ~/build/BUILD/goconvey-1.6.3
    PASS
    testing: warning: no tests to run
    ok github.com/smartystreets/goconvey/convey/gotest 0.003s
  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing convey/reporting…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ convey/reporting == examples ]]
  • '[' true = true ']'
  • echo 'Testing convey/reporting…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/convey/reporting
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/convey/reporting ~/build/BUILD/goconvey-1.6.3
    PASS
    ok github.com/smartystreets/goconvey/convey/reporting 0.003s
  • popd
    ~/build/BUILD/goconvey-1.6.3
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ examples == examples ]]
  • process=false
  • break
  • '[' false = true ']'
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/api == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/api…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/api
    Testing web/server/api…
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/api ~/build/BUILD/goconvey-1.6.3
  • go test -compiler gc -ldflags ''
    .........S.SSS..S.S
    13 total assertions (one or more sections skipped)

PASS
ok github.com/smartystreets/goconvey/web/server/api 0.211s

  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing web/server/contract…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/contract == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/contract…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/contract
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/contract ~/build/BUILD/goconvey-1.6.3
    PASS
    testing: warning: no tests to run
    ok github.com/smartystreets/goconvey/web/server/contract 0.006s
  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing web/server/executor…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/executor == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/executor…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/executor
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/executor ~/build/BUILD/goconvey-1.6.3
    PASS
    ok github.com/smartystreets/goconvey/web/server/executor 0.006s
  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing web/server/messaging…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/messaging == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/messaging…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/messaging
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/messaging ~/build/BUILD/goconvey-1.6.3
    testing: warning: no tests to run
    PASS
    ok github.com/smartystreets/goconvey/web/server/messaging 0.002s
  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing web/server/parser…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/parser == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/parser…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/parser
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/parser ~/build/BUILD/goconvey-1.6.3
    ...
    3 total assertions

PASS
ok github.com/smartystreets/goconvey/web/server/parser 0.008s

  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing web/server/system…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/system == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/system…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/system
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/system ~/build/BUILD/goconvey-1.6.3
    .......
    7 total assertions

....2017/10/20 01:09:31.515462 shell.go:94: Please run goconvey from within $GOPATH/src (also, symlinks might be problematic). Output and Error: This is a wacky error This happens when running goconvey outside your $GOPATH (symlinked code).
.2017/10/20 01:09:31.515758 shell.go:102: Coverage output: ok
2017/10/20 01:09:31.515770 shell.go:104: Run without coverage
.2017/10/20 01:09:31.515965 shell.go:102: Coverage output: PASS
ok github.com/smartystreets/goconvey/examples 0.012s
2017/10/20 01:09:31.515972 shell.go:104: Run without coverage
..
15 total assertions

2017/10/20 01:09:31.516115 shell.go:102: Coverage output: ok
2017/10/20 01:09:31.516121 shell.go:104: Run without coverage
...
18 total assertions

PASS
ok github.com/smartystreets/goconvey/web/server/system 0.498s

  • popd
    ~/build/BUILD/goconvey-1.6.3
    Testing web/server/watch…
  • for sub in $(find . -iname '*.go' -exec dirname '{}' ;|sort|uniq|sed s'+^./++')
  • process=true
  • declare -a 'excludes=(examples)'
  • for exclude in "${excludes[@]}"
  • [[ web/server/watch == examples ]]
  • '[' true = true ']'
  • echo 'Testing web/server/watch…'
  • pushd /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/watch
  • go test -compiler gc -ldflags ''
    ~/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/watch ~/build/BUILD/goconvey-1.6.3
    ...
    3 total assertions

...
6 total assertions

...
9 total assertions

...
12 total assertions

...
15 total assertions

...
18 total assertions

...
21 total assertions

...
24 total assertions

...
27 total assertions

...
30 total assertions

...
33 total assertions

...
36 total assertions

...
39 total assertions

...
42 total assertions

......
48 total assertions

......
54 total assertions

..
56 total assertions

.
57 total assertions

xxxx....
Failures:

  • /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/watch/integration_test.go
    Line 82:
    Expected: '1'
    Actual: '0'
    (Should be equal)

  • /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/watch/integration_test.go
    Line 96:
    Expected: '2'
    Actual: '1'
    (Should be equal)

  • /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/watch/integration_test.go
    Line 113:
    Expected: '1'
    Actual: '0'
    (Should be equal)

  • /builddir/build/BUILD/goconvey-1.6.3/_build/src/github.com/smartystreets/goconvey/web/server/watch/integration_test.go
    Line 129:
    Expected: '3'
    Actual: '2'
    (Should be equal)

65 total assertions

--- FAIL: TestWatcher (4.52s)
integration_test.go:27: 2017/10/20 01:09:32.342629 integration.go:101: Stopping the watcher...
2017/10/20 01:09:32.343126 integration.go:97: Gathering folders for immediate execution...
2017/10/20 01:09:32.343556 integration.go:101: Stopping the watcher...
2017/10/20 01:09:32.343950 integration.go:75: Ignoring specified folders
2017/10/20 01:09:32.343970 integration.go:163: Currently ignored folders: map[/tmp/goconvey521582753/integration_testing/sub:{}]
2017/10/20 01:09:32.344233 integration.go:82: Reinstating specified folders
2017/10/20 01:09:32.344451 integration.go:101: Stopping the watcher...
2017/10/20 01:09:32.344762 integration.go:70: Adjusting root...
2017/10/20 01:09:32.344971 integration.go:70: Adjusting root...
2017/10/20 01:09:32.345324 integration.go:101: Stopping the watcher...
2017/10/20 01:09:32.345684 integration.go:106: Unrecognized command from server: UNKNOWN INSTRUCTION
2017/10/20 01:09:32.345925 integration.go:122: File system state modified, publishing current folders... 0 3016909361
2017/10/20 01:09:32.596087 integration.go:101: Stopping the watcher...
2017/10/20 01:09:32.596782 integration.go:122: File system state modified, publishing current folders... 0 3016909361
2017/10/20 01:09:33.852234 integration.go:122: File system state modified, publishing current folders... 3016909361 3016909362
2017/10/20 01:09:34.604778 integration.go:101: Stopping the watcher...
2017/10/20 01:09:34.606088 integration.go:122: File system state modified, publishing current folders... 0 3016909362
2017/10/20 01:09:34.856337 integration.go:89: Pausing watcher...
2017/10/20 01:09:35.106618 integration.go:93: Resuming watcher...
2017/10/20 01:09:35.106663 integration.go:101: Stopping the watcher...
2017/10/20 01:09:35.108001 integration.go:122: File system state modified, publishing current folders... 0 3016909362
2017/10/20 01:09:35.358245 integration.go:89: Pausing watcher...
2017/10/20 01:09:36.609668 integration.go:93: Resuming watcher...
2017/10/20 01:09:36.610408 integration.go:122: File system state modified, publishing current folders... 3016909362 3016909365
2017/10/20 01:09:36.860649 integration.go:101: Stopping the watcher...

FAIL
exit status 1
FAIL github.com/smartystreets/goconvey/web/server/watch 4.530s

ShouldEqual does not compare time.Time correctly

It appears that two time.Time objects cannot be compared with ShouldEqual:

base1 := time.Now()
base2 := base1

// Fails
So(base1, ShouldEqual, base2)

// A workaround - this will pass
So(base1, ShouldHappenWithin, time.Duration(0), base2)

Output:

Expected: '2017-02-13 17:21:18.997107497 -0600 CST'
Actual:   '2017-02-13 17:21:18.997107497 -0600 CST'
(Should be equal)

Arguably an upstream issue - jacobsa/oglematchers#25 mentions this.
An easy fix would be to use time.Equal.

ShouldResemble and complex structs (ie. time.Time) don't play nicely

In failure scenarios where complex structs (like time.Time instances) don't match, the resulting output is cumbersome at best to visually parse. The serializer currently makes use of the %+v formatting flag to print stuff. This might sound crazy but we could actually reimplement some of the inner workings of the fmt package to make insert inspections for fmt.GoStringer or fmt.Stringer or any other custom interface defined by the assertions package.

ShouldResemble can fail when there's no visual diff between the inputs

This was initially filed as an issue on goconvey: smartystreets/goconvey#665
But really it's a problem in this assertions code.

Assuming you read that issue first, and especially smartystreets/goconvey#665 (comment) , the right fix would be for the diff to report which types are different. That would be a little involved, especially if anyone has managed to rely on the exact output format that is provided currently.
A lazier fix would be something like the below

func ShouldResemble(actual interface{}, expected ...interface{}) string {
	if message := need(1, expected); message != success {
		return message
	}

	if matchError := oglematchers.DeepEquals(expected[0]).Matches(actual); matchError != nil {
		renderedExpected, renderedActual := render.Render(expected[0]), render.Render(actual)
		message := fmt.Sprintf(shouldHaveResembled, renderedExpected, renderedActual)

		if renderedExpected != renderedActual {
			message += composePrettyDiff(renderedExpected, renderedActual)
		} else {
			message += "No visual diff, but there is a difference in type within expected versus actual"
		}
		return serializer.serializeDetailed(expected[0], actual, message)
	}

	return success
}

FYI @riannucci

https://github.com/luci/go-render has new commits

New features:

  • correct sorting for all map key types
  • abbreviated rendering for explicit types. e.g. map[myString]struct{a, b int}{"hi": {1, 2}} will now render like map[pkg.myString]struct { a int; b int }{"hi": {1, 2}} instead of map[pkg.myString]struct { a int; b int }{pkg.myString("hi"): {a:1, b:2}}

Is there an assertion like So(..) that skips the whole tests without reporting an error if the assertion fails?

I have a method m2 that depend that depends on the output of method m1.

I would like to exit the m1 tests QUIETLY, if m1 assertions fails before m2 tests assertions start executing.

Currently, So(...) reports the m1 assertions failure whereas the main focus should be on the output of m2 assertions if all m1 assertions passed.

If any of the m1 assertions failed, the test should exit quietly skipping all other assertions. Do we have a function that I can use to run m1 assertions while I use So(...) to run m2 assertions?

Problem running test

Hey, I updated to v1.1.0 and got this message error when running a test:

# github.com/vtex/courier/vendor/github.com/smartystreets/assertions
vendor/github.com/smartystreets/assertions/type.go:146:6: undefined: errors.Is

I had to rollback to the previous version.

Just wanted to let you know.

modernise vendoring

It would be great if 3rd party components in assertions/internal could be (re-)bundled using more conventional "Godeps" system. Please remember to stick to tagged releases instead of master's head whenever possible. Thanks.

Versioning scheme changed backwards

Hi!

It looks like the versioning scheme changed from X.Y.Z to vM.N.O, but the versioning got reset backwards from 1.10.1 to 1.0.0. This has the consequence that the package is currently stuck in most distributions on the old 1.10.1 release, as the automatic distribution upstream version checks (or human ones) are not detecting the new version. And for the ones that might have noticed, that would imply adding an epoch, which has its own set of global versioning drawbacks (as the epochs invalidate all current versioned dependencies). See https://repology.org/project/go:github-smartystreets-assertions/versions for current distribution status.

Would it be possible to release a new version and bump it to say v1.11.0? That'd be highly appreciated!

(There's a build failure bug in Debian, which I assume is fixed by latest upstream code, but we cannot update it right away due to this. :/ )

Please tag new release

Since assertions is a dependency of goconvey it would be great if the latter could be built with formally tagged release version. Latest release 1.5.0 of 2014 is too old and affected by circular dependency on goconvey (which is fixed in untagged "master")...

map[int64]bool ShouldContainKey didn't work as expected

func TestContainsKey(t *testing.T) {
	Convey("Test IntersectMapsByKey", t, func() {
		map1 := map[int64]bool{
			1: true,
		}
		So(map1, ShouldContainKey, int64(1))
		So(map1, ShouldContainKey, 1)
	})
}

the first assertion passed, while the second one will fail, error msg:

Expected the map[int64]bool to contain the key: [1] (but it didn't)!

My current temp solution will be:

So(map1[1], ShouldBeTrue)

TestMapSortRendering fails with go1.18

zhsj@debian:~/go/src/github.com/smartystreets/assertions/internal/go-render/render$ go test . -count=1 -run TestMapSortRendering
--- FAIL: TestMapSortRendering (0.00s)
    render_test.go:29: On line #279, [] did not match expectations:
        Expected: map[interface{}]struct {}{1:{}, 2:{}, 3:{}, "foo":{}}
        Actual  : map[interface{}]struct {}{3:{}, 1:{}, 2:{}, "foo":{}}
FAIL
FAIL    github.com/smartystreets/assertions/internal/go-render/render   0.001s
FAIL

Value.InterfaceData seems to return different results with go1.18.

https://github.com/smartystreets/assertions/blob/751d45e3/internal/go-render/render/render.go#L418-L429

[suggestion] loose slice equality

Hello!
First, thanks for this awesome library! :)
Sometimes one needs to test for slice equality disregarding the order of elements. For example, when one wants to check if map contains exactly needed keys/values.
Right now it can be done with multiple assertions (checking for lengths, and some ShouldBeIn checks)

I propose to add something like ShouldLooselyEqual (or ShouldSetEqual) which will behave like this:

So([]int{1,1,2}, ShouldLooselyEqual, []int{1,1,2}) // ok
So([]int{1,2,1}, ShouldLooselyEqual, []int{1,1,2}) // ok
So([]int{1,2,1}, ShouldLooselyEqual, []int{1,2})   // not ok, lengths differ
So([]int{1,2,1}, ShouldLooselyEqual, []int{1,2,3}) // not ok, elements differ

It is also can be parametrised by other assertion (like ShouldLooselyEqual(ShouldAlmostEqual)).
I am willing to make a PR if you are interested.
Please, let me know what do you think.

Major version shall be bumped since v1.51.0

Since v1.51.0, ShouldEqual() has a breaking change and it is no longer compatible with prior 1.x versions. Therefore, the major version shall be bumped to ensure the correctness of semantic versioning.

Should*Contain doesn't handle nested lists

First off, thank you so much for building goconvey. It's truly a pleasure to use, and I find myself thinking much more clearly when I'm writing tests.

One use case I've had is asserting a list of list should contains a list; for example

So([][]int{[]int{1}, []int{2}, []int{3}}, ShouldContain, []int{2})

When I make the assertion, I get a panic:

panic: oglematchers.Equals: non-nil slice [recovered]
        panic: oglematchers.Equals: non-nil slice

goroutine 22 [running]:
testing.tRunner.func1(0xc820098630)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:450 +0x171
github.com/smartystreets/assertions/internal/oglematchers.Equals(0x2e7d80, 0xc820082860, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/internal/oglematchers/equals.go:68 +0x318
github.com/smartystreets/assertions/internal/oglematchers.Contains(0x2e7d80, 0xc820082860, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/internal/oglematchers/contains.go:31 +0xc5
github.com/smartystreets/assertions.ShouldContain(0x2e6d60, 0xc820082880, 0xc820071640, 0x1, 0x1, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/collections.go:17 +0xcc
github.com/smartystreets/assertions.so(0x2e6d60, 0xc820082880, 0x47e940, 0xc820071640, 0x1, 0x1, 0x0, 0x0)
        /Users/jd/go/src/github.com/smartystreets/assertions/doc.go:96 +0x5a
github.com/smartystreets/assertions.TestShouldContain(0xc820098630)
        /Users/jd/go/src/github.com/smartystreets/assertions/collections_test.go:42 +0xd3e
testing.tRunner(0xc820098630, 0x5a29f0)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:456 +0x98
created by testing.RunTests
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:561 +0x86d

goroutine 1 [chan receive]:
testing.RunTests(0x47ee50, 0x5a29c0, 0x3e, 0x3e, 0x1)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:562 +0x8ad
testing.(*M).Run(0xc82004bef8, 0xe3186)
        /usr/local/Cellar/go/1.5.1/libexec/src/testing/testing.go:494 +0x70
main.main()
        github.com/smartystreets/assertions/_test/_testmain.go:176 +0x116

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/local/Cellar/go/1.5.1/libexec/src/runtime/asm_amd64.s:1696 +0x1
exit status 2

I found a pretty simple fix; see PR #12.

Thanks again for building great library!

incompatible with 1.5.1

seeing lots of errors when trying to build with 1.5.1 due toe internal packages not being supported in newest go version

https://groups.google.com/forum/#!topic/golang-nuts/A3KA8SNjcp0
https://docs.google.com/document/d/1e8kOo3r51b2BWtTs_1uADIA5djfXhPT36s6eHVRIvaU/edit

package .
imports github.com/smartystreets/assertions/internal/oglematchers: use of internal package not allowed
package ./internal/oglemock
imports github.com/smartystreets/assertions/internal/oglematchers: use of internal package not allowed
package ./internal/oglemock/createmock
imports github.com/smartystreets/assertions/internal/oglemock/generate: use of internal package not allowed
package ./internal/oglemock/generate/test_cases
imports github.com/smartystreets/assertions/internal/oglemock: use of internal package not allowed
package ./internal/oglemock/generate/test_cases
imports github.com/smartystreets/assertions/internal/oglemock/generate/test_cases/complicated_pkg: use of internal package not allowed
package ./internal/oglemock/generate/test_cases
imports github.com/smartystreets/assertions/internal/oglemock/generate/test_cases/renamed_pkg: use of internal package not allowed
package ./internal/oglemock/generate/test_cases/complicated_pkg
imports github.com/smartystreets/assertions/internal/oglemock/generate/test_cases/renamed_pkg: use of internal package not allowed
package ./internal/oglemock/sample/mock_io
imports github.com/smartystreets/assertions/internal/oglemock: use of internal package not allowed
package ./internal/ogletest
imports github.com/smartystreets/assertions/internal/oglematchers: use of internal package not allowed
package ./internal/ogletest
imports github.com/smartystreets/assertions/internal/oglemock: use of internal package not allowed
package ./internal/ogletest
imports github.com/smartystreets/assertions/internal/ogletest/srcutil: use of internal package not allowed
package ./internal/ogletest
imports github.com/smartystreets/assertions/internal/reqtrace: use of internal package not allowed
package ./internal/ogletest/test_cases
imports github.com/smartystreets/assertions/internal/oglematchers: use of internal package not allowed
package ./internal/ogletest/test_cases
imports github.com/smartystreets/assertions/internal/oglemock: use of internal package not allowed
package ./internal/ogletest/test_cases
imports github.com/smartystreets/assertions/internal/ogletest: use of internal package not allowed
package ./internal/ogletest/test_cases
imports github.com/smartystreets/assertions/internal/ogletest/test_cases/mock_image: use of internal package not allowed
package ./internal/ogletest/test_cases/mock_image
imports github.com/smartystreets/assertions/internal/oglemock: use of internal package not allowed

Drop go1.17 dependency

Seems this module does not require go 1.17. It would be nice to lower the required version. E.g. 1.16 is very popular as it brought embed support. Not sure why 1.17 should be required?

should.ContainKey fails for int32 key

Greetings,
first of all, great library!
It enables me to write more or less fluent assertions, as I'm used to from C#.

However, the test below fails with the int32 key, but works with int key.
This is for version 1.8.3

func Test_Should_ContainKey_With_Integer_Keys_Works(t *testing.T) {
	// Arrange
	assert := assertions.New(t)
	target := map[int32]int{}
	target[3] = 5
	// Assert
	assert.So(target, should.ContainKey, 3)
}

building error

# github.com/smartystreets/assertions
../../smartystreets/assertions/panic.go:81:36: undefined: errors.Is
../../smartystreets/assertions/panic.go:116:36: undefined: errors.Is
../../smartystreets/assertions/type.go:146:6: undefined: errors.Is

The module declares is incorrect

I'm trying go mod tidy on my project, but got this issue

go:
github.com/beego/i18n imports
github.com/Unknwon/goconfig tested by
github.com/Unknwon/goconfig.test imports
github.com/smartystreets/goconvey/convey imports
github.com/smartystreets/assertions: github.com/smartystreets/[email protected]: parsing go.mod:
module declares its path as: github.com/smarty/assertions
but was required as: github.com/smartystreets/assertions

Golang 1.16 beta 1: TestMapSortRendering fails on s390x

On Fedora rawhide, Golang 1.16 beta 1, s390x architecture, the following test fail:

--- FAIL: TestMapSortRendering (0.00s)
    render_test.go:29: On line #279, [] did not match expectations:
        Expected: map[interface{}]struct {}{1:{}, 2:{}, 3:{}, "foo":{}}
        Actual  : map[interface{}]struct {}{3:{}, 1:{}, 2:{}, "foo":{}}
FAIL
exit status 1
FAIL	github.com/smartystreets/assertions/internal/go-render/render	0.004s

README.md should include actual usage examples

func ShouldBeTrue

func ShouldBeTrue(actual interface{}, expected ...interface{}) string

ShouldBeTrue receives a single parameter and ensures that it is true.

The example (which really isn't even an example, but more of a method signature) doesn't match the description.

I think it would be better to provide examples of each method instead of the signature, which looks identical to every other method, and doesn't really provide any value.

ShouldEqual no longer works with functions

Starting in 1.15.0 ShouldEqual no longer functions properly.

func Test(t *testing.T) {
	f := func() {}
	str := assertions.ShouldEqual(f, f)

	if len(str) != 0 {
		panic(str)
	}
}

This panics with:

{"Message":"Expected: (func())(0x0000000104b26d40)
Actual:   (func())(0x0000000104b26d40)
(Should equal, but there is a type difference within the two)!","Expected":"(func())(0x0000000104b26d40)","Actual":"(func())(0x0000000104b26d40)"}

This work in 1.13.1

ShouldEqualJSON does not work with json arrays

Hi, thanks for the awesome lib :)

I just found a small issue with ShouldEqualJSON. The sample test below will fail

func TestSmartyStreetsJsonEqual(t *testing.T) {
	Convey("Test json equal", t, func() {
		actual := `
		{
		  "items": [
			{
			  "id": 1,
			  "sku": "sku-123"
			},
			{
			  "id": 2,
			  "sku": "sku-456"
			}
		  ]
		}
		`
		expected := `
		{
		  "items": [
			{
			  "id": 2,
			  "sku": "sku-456"
			},
			{
			  "id": 1,
			  "sku": "sku-123"
			}
		  ]
		}
		`
		So(actual, assertions.ShouldEqualJSON, expected)
	})
}

It looks like under the hood it's comparing two string [{"id": 1, "sku": "sku-123"}, {"id": 2, "sku": "sku-456"}] and [{"id": 2, "sku": "sku-456"}, {"id": 1, "sku": "sku-123"}], hence the failed test.
Is this the expected behavior of ShouldEqualJSON?
Right now I can bypass this by unmarshalling the json array and compare their elements, but it would be nice if we can have some assertions function to do this. What do you think?

Assertions should allow an optional string with a better message

This is more information that you'd normally get, but it still requires a bit of research to figure out why the assertion failed.

    		(1):      /Users/wes/projects/space-z/maps/spaceship/small_test.go:31
    		(0):      /Users/wes/projects/space-z/maps/spaceship/small_test.go:96
    		Expected: '&{ map[] true}'
    		Actual:   '&{CoEd Showers map[0:0x12838a0 1:0x12838a0 2:0xc42000a160 3:0xc42000a1c0] false}'
    		(Should be equal)

It would be really nice to be able to provide my own why it failed message.

httptest.NewServer starts in background goroutine and causes data race when used with shouldNotBeNil (which depends upon string formatting)

Sample code:

func TestHttpWebServer(t *testing.T) {
	Convey("Scenario: testing WebServer", t, func() {
		dir, err := ioutil.TempDir("", "webserver")
		So(err, ShouldBeNil)
		defer os.RemoveAll(dir)

		err = ioutil.WriteFile(filepath.Join(dir, "file"), make([]byte, 10000), 0755)
		So(err, ShouldBeNil)

		server := httptest.NewServer(http.FileServer(http.Dir(dir)))
                So(server, ShouldNotBeNil)
<snip>

When run with go test -race, this fails because httptest.NewServer has a Goroutine that initializes its connection state, but ShouldNotBeNil calls ShouldBeNil, which returns a string that looks like:

Expected: nil
Actual:   '&{0x1a6fac0 0xc000198000 0xc000214000 0xc000120008 0xc000020080 0 0}'

However, calling fmt.Sprintf(%v, server) isn't really a good idea here because it may not be finished initializing. This seems like a weakness in depending on strings for comparisons.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.