Skip to content

docs: Fix EventuallyWithTf documentation with proper placement of formatting arguments#1842

Merged
dolmen merged 1 commit intostretchr:masterfrom
a2not:fix-EventuallyWithTf-doc-callback-signature
Feb 23, 2026
Merged

docs: Fix EventuallyWithTf documentation with proper placement of formatting arguments#1842
dolmen merged 1 commit intostretchr:masterfrom
a2not:fix-EventuallyWithTf-doc-callback-signature

Conversation

@a2not
Copy link
Contributor

@a2not a2not commented Jan 8, 2026

Summary

Fixed the regexp for CommentFormat() code-generation function such that it properly captures the outer most closing parenthesis of a function call in code comment.

exp := regexp.MustCompile(replace + `\(((\(\)|[^\n])+)\)`)

Changes

  • Changed regexp. It got much more of complexity but regexp is hard so what can I say...
  • Minor refactoring such as removing a formating of a string which in reality does nothing.
  • The original EventuallyWithT has msgAndArgs as the last argument, which needs to be replaced by two separate msg and args in EventuallyWithTf. I've implemented with very naive approach which might need to be improved.

Motivation

Misleading documentation

Related issues

Closes #1833

@dolmen dolmen added documentation pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require internal/codegen Change related to internal code generation labels Feb 17, 2026
_codegen/main.go Outdated
comment := strings.Replace(f.Comment(), search, replace, -1)
exp := regexp.MustCompile(replace + `\(((\(\)|[^\n])+)\)`)
comment := strings.ReplaceAll(f.Comment(), search, replace)
if strings.Contains(search, "EventuallyWithT") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about looking for the ..."external state... string instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This suggestion simplified the implementation. Thanks!

@a2not a2not force-pushed the fix-EventuallyWithTf-doc-callback-signature branch 2 times, most recently from df7336c to a270037 Compare February 18, 2026 00:39
- Updated code generation logic to handle msgAndArgs in EventuallyWithTf
  comments, ensuring correct formatting and removal of obsolete messages.
- Revised example comments in assertion_format.go, assertion_forward.go,
  require.go, and require_forward.go to use the new signature and message
  format for EventuallyWithTf.

Signed-off-by: a2not <31874975+a2not@users.noreply.github.com>
@dolmen dolmen merged commit cddda8c into stretchr:master Feb 23, 2026
9 checks passed
@a2not a2not deleted the fix-EventuallyWithTf-doc-callback-signature branch February 24, 2026 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation internal/codegen Change related to internal code generation pkg-assert Change related to package testify/assert pkg-require Change related to package testify/require

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EventuallyWithTf function help is incorrect, misleading callback signature

2 participants