smarty / assertions Goto Github PK
View Code? Open in Web Editor NEWFluent assertion-style functions used by goconvey and gunit. Can also be used in any test or application.
License: Other
Fluent assertion-style functions used by goconvey and gunit. Can also be used in any test or application.
License: Other
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
PASS
ok github.com/smartystreets/goconvey/web/server/api 0.211s
PASS
ok github.com/smartystreets/goconvey/web/server/parser 0.008s
....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
...
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
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.
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.
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
New features:
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}}
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?
An inverse to the ShouldBeZeroValue assertion would be handy.
foo := ""
So(foo, ShouldNotBeZeroValue) // fails
On this webpage: https://pkg.go.dev/github.com/smartystreets/assertions#section-readme,
There is a typo with the definition of "ShouldNotBeBlank," I believe. The definition says
ShouldNotBeBlank receives exactly 1 string parameter and ensures that it is equal to "".
It should say that it ensures it is not equal to "".
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.
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.
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. :/ )
Would you accept a PR for a "ShouldEqualJSON" assertion? I find myself writing/using this assertion frequently...
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")...
This is the issue: smartystreets/goconvey#348
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)
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.
Title.
Things such as
So("[]\n", assertions.ShouldEqualJSON, "[]")
Return the following error:
Expected value not valid JSON: json: cannot unmarshal array into Go value of type map[string]interface {}
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.
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.
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!
Example: smartystreets/goconvey#492
It panics on https://github.com/smartystreets/assertions/blob/master/equal_method.go#L47 and a shouldHaveBeenEqual message is sent.
Is this the expected behavior? Today, before update this package, this kind of tests worked fine.
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
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?
This should give a better warning: So(1, should.BeEmpty)
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)
}
# 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
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
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
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.
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
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?
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.
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.
Thought: What if ShouldEqual
(and ShouldNotEqual
) worked on struct types that implemented an equality method for their own type:
func (a <struct>) Equal(b <struct>) bool
The time.Time
struct has:
func (t Time) Equal(u Time) bool
Is this pattern common enough that it would be helpful and/or obvious?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.