-
-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Formatting matcher output #37
Comments
Gomega's formatter does not simply print out Stringer/GoStringer because the representations for either of these are often insufficient to correctly diagnose problems. It's actually funny that you picked package bar_test
import (
"encoding/json"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"fmt"
"testing"
"time"
)
func TestBar(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Bar Suite")
}
type Temporal struct {
T time.Time
}
var _ = Describe("JSON", func() {
It("should work", func() {
original := Temporal{T: time.Now()}
encoded, err := json.Marshal(original)
Ω(err).ShouldNot(HaveOccurred())
var hydrated Temporal
err = json.Unmarshal(encoded, &hydrated)
Ω(err).ShouldNot(HaveOccurred())
fmt.Println(original, hydrated)
Ω(hydrated).Should(Equal(original))
})
}) All this is doing is JSON encoding a struct that contains a
At first blush the values appear to be identical. If this is what Gomega showed you there'd be much confusion and no way to understand what was going wrong! Here's Gomega's formatted output:
As you can see the decoded object is missing the complex With all this said, I agree that Gomegas output can be overwhelmingly verbose at times. There isn't currently a way to change this but I would like to add one. I'm envisioning that you can instruct Gomega's format package to enter different verbosity modes. It will default to the current (high-verbosity) mode but you'll be able to do something like: func TestBar(t *testing.T) {
format.SetVerbosityLevel(format.Low)
RegisterFailHandler(Fail)
RunSpecs(t, "Bar Suite")
} which would lead to much terser, but hopefully still useful for most cases, output. Thoughts? |
I've struggle a bit with what to do here. I think what I ended up with on 05c2b32 is a reasonable compromise. You can now modify the (global) maximum recursion depth for the format package by setting You can also opt into displaying These are global and affect all output. I think between the two knobs you can get better control over your output. Thoughts? |
Would it be possible to show the more verbose representation, but only if the less-verbose representations are identical? (vice-versa for inequality matches) |
Sorry to revive such a long dead thread, but I think keeping the conversation in one thread is useful for the future readers. |
I like the idea of a |
Absolutely. |
Thanks! If you could also update the docs on the gh-pages branch that would be great too.
… On Mar 17, 2021, at 8:31 AM, Khosrow Afroozeh ***@***.***> wrote:
Absolutely.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
#427 |
Now that I think of it, maybe it wouldn't be a bad idea to trim a big object's dump if it is bigger than a certain size - say around 2K characters - since it probably will not be useful anyway the way it is. |
Agreed - I was thinking along similar lines. You up for adding a bit more to the PR (I'm currently heads down working on Ginkgo v2 and would appreciate the help making this a more pleasant user experience). How about a new top-level global in
to the end of the representation. (Unless the object has implemented This way the user gets immediate helpful feedback in their test and they can go off and learn more. Thoughts? |
100% agreed, even for the message! (I already even had the message, though yours is better English than mine) |
thanks so much!
… On Mar 17, 2021, at 10:54 AM, Khosrow Afroozeh ***@***.***> wrote:
100% agreed, even for the message! (I already even had the message, though yours is better English than mine)
Will make the PR in a bit.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
PR updated. I went the lazy way in updating the code, trying to change as little as I could. |
thanks @khaf ! |
oh - if you're still up for updating the docs, please do! otherwise let me know and i can take care of it later. |
Here you go #429 |
Originally from onsi/ginkgo#73
This may already be implemented, I just haven't found it.
When I have an expectation like this:
If it fails, it logs a deep inspection of
something
. I find that in many cases this leads to overwhelming output. For example, one of my structures includes atime.Time
. This is (surprisingly) over 250 of output due to a massive DST lookup table that's included in itsloc
field. Some of my data structures include http or file handles that can generate thousands of lines of output (sometimes recursively, leading to hundreds of "too deep for me, man" messages).I had assumed that I could implement Stringer or GoStringer to control the logging output, but Ginkgo doesn't seem to use these. Is there any way to get control over how complex structures are displayed?
The text was updated successfully, but these errors were encountered: