Can Gomega equal with ginkgo print full strings?

696 views Asked by At

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.

2

There are 2 answers

2
mjnovice On BEST ANSWER

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

1
Sandy Cash On

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.