2

Example error print of a unit test:

 Expected <string>: "...up - Finish..." to equal | <string>: "...up - Vault ..." 

Is there a way to increase the print limit this is just not practical at all... Like at least to something like 100 signs...

Edit: I might not have given enough information:

Vault ... Finish... 

Are not the only parts that are different in the string and it is very hard to read without more context if an error occurs. There should be a way to allow full comparison prints no? Similar as to how it is in NodeJS Chai.

3
  • I'm not sure what your complaint is. Ginkgo/Gomega are telling you the specific substrings that differ. What value would it provide to output 100+ characters if the values only differ with respect to a small substring? FWIW, I am unaware of any way to change this behavior, but I've honestly never found it limiting, either. Commented Jan 26, 2023 at 12:40
  • 1
    The strings differ from Vault and Finish but completely till the end. It is not just this subsection that is different. I just want to print more of the compared strings. Commented Jan 26, 2023 at 13:06
  • I love Go and its ecosystem. But Ginkgo slows me down. Unfortunately it is the default in some parts of our code base. Commented Apr 16, 2024 at 8:28

3 Answers 3

2

I do not believe this is possible without modifying the underlying Ginkgo code, at least from my reading and experimentation. Ginkgo uses its own reporting framework, and you can leverage that to customize the output...within limits.

One way to see the raw report output is to dump it as json with the --json-report <PATH> flag for ginkgo:

$ ginkgo --json-report=spec-out.json 

I created a simple spec that compared two really long strings (just the English alphabet repeated, separated by spaces, a bunch of times), differing only in the replacement of a single alphabet block with "foobar", and the contents of the report relevant to what you'd see in the normal output were limited to:

"Failure": { "Message": "Expected\n \u003cstring\u003e: \"...wxyz abcdef...\"\nto equal |\n \u003cstring\u003e: \"...wxyz foobar...\"", 

Then I changed the compared string so that it the diff extended for a much longer stretch, and the message was identical - still truncated to the initial point of mismatch.

You can access the underlying reporting framework through Ginkgo itself, for example:

ReportAfterEach(func(report SpecReport) { fmt.Fprintf(os.Stderr, "SPEC REPORT: %s | %s\nFAILURE MESSAGE: %s\n", report.State, report.FullText(), report.FailureMessage()) }) 

This also returned the truncated strings in the message, which would indicate to me that there is no easily accessible mechanism for getting a longer string to output - since this is presumably generated at a lower level (I'm thinking in the code for the Equal() matcher, but I haven't looked yet):

SPEC REPORT: failed | Utils Compares really long strings FAILURE MESSAGE: Expected <string>: "...wxyz abcdef..." to equal | <string>: "...wxyz foobar..." 

For reference see the ginkgo reporting docs and relevant portion of the ginkgo godoc.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for that input seems to be rather tricky! I will also try to take a look into the open source code to find the place where this happens maybe there is a hidden way to configure the size. Would be strange if this value is hard coded somehow.
1

https://github.com/onsi/ginkgo/issues/1166 Have a look at this, onsi answered. Look at the format package.

2 Comments

oh nice crosspost answer :)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-1

At least for me, it is the easiest way to add a temporary print statement before the assertion:

fmt.Printf("=============================>>> Actual: %+v\n", actualResult) 

The "big" marker of equal signs helps to find the output, if there is a lot of output.

The next time I start a project, I won't use Ginkgo/Gomega.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.