Skip to content

Commit 967a7b7

Browse files
committed
fix: update EventuallyWithTf comment examples and codegen
- 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>
1 parent 101072d commit 967a7b7

5 files changed

Lines changed: 16 additions & 11 deletions

File tree

_codegen/main.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,10 +283,15 @@ func (f *testFunc) Comment() string {
283283
}
284284

285285
func (f *testFunc) CommentFormat() string {
286-
search := fmt.Sprintf("%s", f.DocInfo.Name)
286+
search := f.DocInfo.Name
287287
replace := fmt.Sprintf("%sf", f.DocInfo.Name)
288-
comment := strings.Replace(f.Comment(), search, replace, -1)
289-
exp := regexp.MustCompile(replace + `\(((\(\)|[^\n])+)\)`)
288+
comment := strings.ReplaceAll(f.Comment(), search, replace)
289+
290+
// NOTE: Some functions have msgAndArgs at the end. It needs to be omitted. (currently only EventuallyWithT)
291+
// Change here if the original comment changed.
292+
comment = strings.Replace(comment, `, "external state has not changed to 'true'; still false"`, "", 1)
293+
294+
exp := regexp.MustCompile(replace + `\((([^()]*|\([^()]*\))*)\)`)
290295
return exp.ReplaceAllString(comment, replace+`($1, "error message %s", "formatted")`)
291296
}
292297

assert/assertion_format.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ func Eventuallyf(t TestingT, condition func() bool, waitFor time.Duration, tick
190190
// time.Sleep(8*time.Second)
191191
// externalValue = true
192192
// }()
193-
// assert.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") {
193+
// assert.EventuallyWithTf(t, func(c *assert.CollectT) {
194194
// // add assertions as needed; any assertion failure will fail the current tick
195195
// assert.True(c, externalValue, "expected 'externalValue' to be true")
196-
// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
196+
// }, 10*time.Second, 1*time.Second, "error message %s", "formatted")
197197
func EventuallyWithTf(t TestingT, condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
198198
if h, ok := t.(tHelper); ok {
199199
h.Helper()

assert/assertion_forward.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,10 +372,10 @@ func (a *Assertions) EventuallyWithT(condition func(collect *CollectT), waitFor
372372
// time.Sleep(8*time.Second)
373373
// externalValue = true
374374
// }()
375-
// a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") {
375+
// a.EventuallyWithTf(func(c *assert.CollectT) {
376376
// // add assertions as needed; any assertion failure will fail the current tick
377377
// assert.True(c, externalValue, "expected 'externalValue' to be true")
378-
// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
378+
// }, 10*time.Second, 1*time.Second, "error message %s", "formatted")
379379
func (a *Assertions) EventuallyWithTf(condition func(collect *CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) bool {
380380
if h, ok := a.t.(tHelper); ok {
381381
h.Helper()

require/require.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,10 @@ func EventuallyWithT(t TestingT, condition func(collect *assert.CollectT), waitF
457457
// time.Sleep(8*time.Second)
458458
// externalValue = true
459459
// }()
460-
// require.EventuallyWithTf(t, func(c *assert.CollectT, "error message %s", "formatted") {
460+
// require.EventuallyWithTf(t, func(c *assert.CollectT) {
461461
// // add assertions as needed; any assertion failure will fail the current tick
462462
// require.True(c, externalValue, "expected 'externalValue' to be true")
463-
// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
463+
// }, 10*time.Second, 1*time.Second, "error message %s", "formatted")
464464
func EventuallyWithTf(t TestingT, condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
465465
if h, ok := t.(tHelper); ok {
466466
h.Helper()

require/require_forward.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,10 @@ func (a *Assertions) EventuallyWithT(condition func(collect *assert.CollectT), w
373373
// time.Sleep(8*time.Second)
374374
// externalValue = true
375375
// }()
376-
// a.EventuallyWithTf(func(c *assert.CollectT, "error message %s", "formatted") {
376+
// a.EventuallyWithTf(func(c *assert.CollectT) {
377377
// // add assertions as needed; any assertion failure will fail the current tick
378378
// assert.True(c, externalValue, "expected 'externalValue' to be true")
379-
// }, 10*time.Second, 1*time.Second, "external state has not changed to 'true'; still false")
379+
// }, 10*time.Second, 1*time.Second, "error message %s", "formatted")
380380
func (a *Assertions) EventuallyWithTf(condition func(collect *assert.CollectT), waitFor time.Duration, tick time.Duration, msg string, args ...interface{}) {
381381
if h, ok := a.t.(tHelper); ok {
382382
h.Helper()

0 commit comments

Comments
 (0)