Skip to content

quote string values in empty assertion failures - #1874

Closed
Bojun-Vvibe wants to merge 1 commit into
stretchr:masterfrom
Bojun-Vvibe:agent/stretchr_testify-1776700183
Closed

Bojun-Vvibe wants to merge 1 commit into
stretchr:masterfrom
Bojun-Vvibe:agent/stretchr_testify-1776700183

Conversation

@Bojun-Vvibe

Copy link
Copy Markdown

Repo: stretchr/testify (⭐ 23000)
Type: bugfix
Files changed: 2
Lines: +20/-22

What

This change updates assert.Empty and assert.NotEmpty to quote string values in failure messages, including aliased string types. The related assert package tests were updated so whitespace-only, newline-containing, and empty-string cases now assert against explicit, readable output like "\\n" and "" instead of visually ambiguous raw text.

Why

Current failure output for string values uses %v, which makes empty strings and whitespace-heavy strings hard to distinguish from formatting noise. That weakens assertion diagnostics in exactly the cases where users need clarity. Quoting string values keeps behavior unchanged while making failures immediately understandable and resolves the existing TODO-marked test expectations around these messages.

Testing

Ran GOCACHE=$(pwd)/.gocache go test ./assert -run 'Test(Empty|NotEmpty)$' from the repo root. The targeted tests passed.

Risk

Low / Message formatting only changes for string values in Empty and NotEmpty; assertion semantics are unchanged.

@Bojun-Vvibe Bojun-Vvibe closed this by deleting the head repository Apr 21, 2026
fredbi added a commit to go-openapi/testify that referenced this pull request Aug 23, 2026
Empty rendered the value with %v, so a string of whitespace left nothing on
screen: Empty(t, "  ") reported `Should be empty, but was   `, which reads as a
message that lost its value. NotEmpty had the same problem with the empty
string.

truncatingValue picks %q for anything of string kind, aliased string types
included, and keeps %v for everything else. NotEmpty now goes through it too,
so its value is truncated at maxMessageSize like every other failure message
instead of being printed whole.

reference: github.com/stretchr#1874
reference: github.com/stretchr#1875

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
fredbi added a commit to go-openapi/testify that referenced this pull request Aug 23, 2026
The August sweep of stretchr/testify turned up four reports describing bugs we
had inherited. Each now has a row in the implemented table saying what we
adopted and what we left alone, and stretchr#1942 joins stretchr#1940 as the PR behind
ErrorNotContains.

stretchr#1776 goes in as informational: upstream's generated require documentation
lists a bool return that the functions do not have, the same defect our own API
pages carried until the signature tables were corrected. Nothing to adopt, but
worth recording that both projects found it independently.

Two more bugs surfaced while checking those four, neither of them reported
upstream, so neither gets a row: InDeltaSlice named expected and actual the
wrong way round in its failures, and EqualValues compared a negative signed
integer equal to a large unsigned one.

Also in this file: the review-frequency line was three months stale, [stretchr#1937]
was referenced with no link definition and rendered as literal text, three
definitions were duplicated, and the summary counts are recounted from the
tables.

reference: github.com/stretchr#1776
reference: github.com/stretchr#1874
reference: github.com/stretchr#1875
reference: github.com/stretchr#1898
reference: github.com/stretchr#1899
reference: github.com/stretchr#1908
reference: github.com/stretchr#1931
reference: github.com/stretchr#1940
reference: github.com/stretchr#1942

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
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.

2 participants