Skip to content
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

Truncate very long objects in test failure messages #1646

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

brackendawson
Copy link
Collaborator

Summary

Truncate object representations in test failure output messages that would cause the message to be too long to scan.

This is a different approach than that in #1559. I feel this is more appropriate because is it safer. The other approach has the potential to allocate excessive memory and to print excessive output to the console.

Changes

  • Make the message line indenter show an appropriate error if it fails to scan a line from the message.
  • Use the existing truncatingFormat function to truncate potentially long objects in assertions which format expected/actual values in full.
  • Parameterize the format string used by truncatingFormat.
  • Reduce the limit used by truncatingFormat by almost half to support failure messages showing both long expected and long actual values on the same line.
  • Change the format of NotSubset from %q to %#v to match that of Subset.

Motivation

So that people don't see no output in the failure message when making assertions (such as Len) against very long objects.

Related issues

Closes #1525

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

assert/require.Len doesn't print anything if the slice is too long
1 participant