From 546059ef902931a29100a57832f79b86c8ecb34b Mon Sep 17 00:00:00 2001 From: Adam Luzsi Date: Wed, 12 Jun 2024 20:26:13 +0200 Subject: [PATCH] use testcase.T in T#Eventually's block After extensive testing, we discovered that constantly switching between using `assert.It` and `testcase.T` is risky and prone to errors without adding any benefit. Therefore, our next step is to streamline the API to simplify testing. The core assert.Eventually is unafected by this change and remains the same as before. The biggest added benefit that now accessing testcase varibles from a Eventually block becomes trivial. --- T.go | 12 +++- T_test.go | 120 ++++++++++++++++++++++++++++++++- backward.go | 33 ++------- backward_test.go | 4 -- clock/Clock_test.go | 2 +- examples_test.go | 2 +- let/person_test.go | 3 +- let/std_test.go | 2 +- opts.go | 2 +- random/Factory_test.go | 4 +- random/Make_test.go | 148 ++++++++++++++++++++--------------------- random/Random_test.go | 46 ++++++------- random/pick_test.go | 3 +- 13 files changed, 239 insertions(+), 142 deletions(-) diff --git a/T.go b/T.go index dd6fe9e..be28bb3 100644 --- a/T.go +++ b/T.go @@ -191,13 +191,21 @@ var DefaultEventually = assert.Retry{Strategy: assert.Waiter{Timeout: 3 * time.S // Calling multiple times the assertion function block content should be a safe and repeatable operation. // For more, read the documentation of Eventually and Eventually.Assert. // In case Spec doesn't have a configuration for how to retry Eventually, the DefaultEventually will be used. -func (t *T) Eventually(blk func(t assert.It), retryOpts ...interface{}) { +func (t *T) Eventually(blk func(t *T)) { t.TB.Helper() retry, ok := t.spec.lookupRetryEventually() if !ok { retry = DefaultEventually } - retry.Assert(t, blk) + retry.Assert(t, func(it assert.It) { + // since we use pointers, copy should not cause issue here. + // our only goal here is to avoid that the original T's .It field changed instead of a copy T's + copyT := *t + nT := ©T + nT.It = it + nT.TB = it + blk(nT) + }) } type timerManager interface { diff --git a/T_test.go b/T_test.go index 7cf8393..66f89a2 100644 --- a/T_test.go +++ b/T_test.go @@ -367,13 +367,15 @@ func TestT_Random(t *testing.T) { } func TestT_Eventually(t *testing.T) { + rnd := random.New(random.CryptoSeed{}) + t.Run(`with default eventually retry strategy`, func(t *testing.T) { stub := &doubles.TB{} s := testcase.NewSpec(stub) s.HasSideEffect() var eventuallyRan bool s.Test(``, func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { eventuallyRan = true it.Must.True(t.Random.Bool()) }) // eventually pass @@ -392,10 +394,10 @@ func TestT_Eventually(t *testing.T) { for condition() { } }) - s := testcase.NewSpec(stub, testcase.RetryStrategyForEventually(strategy)) + s := testcase.NewSpec(stub, testcase.WithRetryStrategy(strategy)) s.HasSideEffect() s.Test(``, func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(t.Random.Bool()) }) // eventually pass }) @@ -404,6 +406,118 @@ func TestT_Eventually(t *testing.T) { assert.Must(t).True(!stub.IsFailed, `expected to pass`) assert.Must(t).True(strategyUsed, `retry strategy of the eventually call was used`) }) + + t.Run("Eventually uses a testcase.T that allows its functionalities all from the the eventually block", func(t *testing.T) { + // After extensive testing, we discovered that constantly switching between using `assert.It` and `testcase.T` is risky + // and prone to errors without adding any benefit. + // Therefore, our next step is to streamline the API to simplify testing. + + stub := &doubles.TB{} + s := testcase.NewSpec(stub) + s.HasSideEffect() + + expTag := rnd.StringNC(5, random.CharsetAlpha()) + s.Tag(expTag) + + expVal := rnd.Int() + v := testcase.LetValue(s, expVal) + + var ran bool + s.Test(``, func(tcT *testcase.T) { + tcT.Eventually(func(it *testcase.T) { + ran = true + assert.Equal(t, expVal, v.Get(it)) + assert.Equal(t, tcT.Random, it.Random) + assert.True(t, tcT.HasTag(expTag)) + assert.True(t, tcT.TB != it.TB) + }) + }) + + stub.Finish() + s.Finish() + + assert.Must(t).True(!stub.IsFailed, `expected to pass`) + assert.True(t, ran) + }) + + t.Run("smoke", func(t *testing.T) { + stub := &doubles.TB{} + s := testcase.NewSpec(stub) + s.HasSideEffect() + + var ran bool + s.Test(``, func(tcT *testcase.T) { + var failed bool + tcT.Eventually(func(t *testcase.T) { + if !failed { + failed = true + t.FailNow() + } + // OK + ran = true + }) + assert.False(t, tcT.Failed()) + }) + + stub.Finish() + s.Finish() + + assert.Must(t).True(!stub.IsFailed, `expected to pass`) + assert.True(t, ran) + }) + + t.Run("when failure occurs during the variable initialisation", func(t *testing.T) { + t.Run("permanently", func(t *testing.T) { + stub := &doubles.TB{} + s := testcase.NewSpec(stub, testcase.WithRetryStrategy(assert.RetryCount(3))) + s.HasSideEffect() + + v := testcase.Let[int](s, func(t *testcase.T) int { + t.FailNow() // boom + return 42 + }) + + s.Test(``, func(tcT *testcase.T) { + tcT.Eventually(func(it *testcase.T) { v.Get(it) }) + }) + + stub.Finish() + s.Finish() + + assert.Must(t).True(stub.IsFailed, `expected to fail`) + }) + t.Run("temporarily", func(t *testing.T) { + stub := &doubles.TB{} + s := testcase.NewSpec(stub) + s.HasSideEffect() + + failed := testcase.LetValue[bool](s, false) + counter := testcase.LetValue[int](s, 0) + expVal := rnd.Int() + + v := testcase.Let[int](s, func(t *testcase.T) int { + counter.Set(t, counter.Get(t)+1) + if !failed.Get(t) { + failed.Set(t, true) + t.FailNow() // boom + } + return expVal + }) + + s.Test(``, func(tcT *testcase.T) { + tcT.Eventually(func(it *testcase.T) { + assert.Equal(t, v.Get(it), expVal) + }) + assert.Equal(t, v.Get(tcT), expVal) + assert.Equal(t, counter.Get(tcT), 2, "it was expected that the variable init block only run twice, one for failure and one for success") + }) + + stub.Finish() + s.Finish() + + assert.Must(t).False(stub.IsFailed, `expected to pass`) + }) + }) } func TestNewT(t *testing.T) { diff --git a/backward.go b/backward.go index c9ad454..95f5592 100644 --- a/backward.go +++ b/backward.go @@ -2,32 +2,6 @@ package testcase import "go.llib.dev/testcase/assert" -type ( - // Eventually - // - // DEPRECATED: use assert.Retry instead - Eventually = assert.Retry - // RetryStrategy - // - // DEPRECATED: use assert.RetryStrategy instead - RetryStrategy = assert.RetryStrategy - // RetryStrategyFunc - // - // DEPRECATED: use assert.RetryStrategyFunc instead - RetryStrategyFunc = assert.RetryStrategyFunc - // Waiter - // - // DEPRECATED: use assert.Waiter instead - Waiter = assert.Waiter -) - -// RetryCount is moved from this package. -// -// DEPRECATED: use assert.RetryCount instead -func RetryCount(times int) assert.RetryStrategy { - return assert.RetryCount(times) -} - // Let is a method to provide backward compatibility with the existing testing suite. // Due to how Go type parameters work, methods are not allowed to have type parameters, // thus Let has moved to be a pkg-level function in the package. @@ -50,3 +24,10 @@ func (spec *Spec) LetValue(varName string, value any) Var[any] { // // DEPRECATED: use VarInit type instead. type VarInitFunc[V any] func(*T) V + +// RetryStrategyForEventually +// +// DEPRECATED: use testcase.WithRetryStrategy instead +func RetryStrategyForEventually(strategy assert.RetryStrategy) SpecOption { + return WithRetryStrategy(strategy) +} diff --git a/backward_test.go b/backward_test.go index d4185a3..440a643 100644 --- a/backward_test.go +++ b/backward_test.go @@ -7,10 +7,6 @@ import ( "go.llib.dev/testcase/random" ) -func TestRetryCount(t *testing.T) { - _ = RetryCount(42) -} - func TestSpec_Let_andLetValue_backwardCompatibility(t *testing.T) { s := NewSpec(t) diff --git a/clock/Clock_test.go b/clock/Clock_test.go index 9446f2b..2a92090 100644 --- a/clock/Clock_test.go +++ b/clock/Clock_test.go @@ -48,7 +48,7 @@ func TestNow(t *testing.T) { s.Then("time is still moving forward", func(t *testcase.T) { now := act(t) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { next := act(t) it.Must.False(now.Equal(next)) it.Must.True(next.After(now)) diff --git a/examples_test.go b/examples_test.go index 1d6a6c5..4df1551 100644 --- a/examples_test.go +++ b/examples_test.go @@ -412,7 +412,7 @@ func ExampleT_Eventually() { s := testcase.NewSpec(tb) s.Test(``, func(t *testcase.T) { // Eventually this will pass eventually - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(t.Random.Bool()) }) }) diff --git a/let/person_test.go b/let/person_test.go index d96858a..14e41cf 100644 --- a/let/person_test.go +++ b/let/person_test.go @@ -4,7 +4,6 @@ import ( "testing" "go.llib.dev/testcase" - "go.llib.dev/testcase/assert" "go.llib.dev/testcase/let" "go.llib.dev/testcase/random/sextype" ) @@ -22,7 +21,7 @@ func TestPerson_smoke(t *testing.T) { t.Must.NotEmpty(ln.Get(t)) t.Must.NotEmpty(mfn.Get(t)) t.Must.NotEmpty(em.Get(t)) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(t.Random.Contact(sextype.Male).FirstName, mfn.Get(t)) }) }) diff --git a/let/std_test.go b/let/std_test.go index 5f45f0d..dda9aaa 100644 --- a/let/std_test.go +++ b/let/std_test.go @@ -57,7 +57,7 @@ func TestSTD_smoke(t *testing.T) { t.Must.True(TimeB.Get(t).After(time.Now().AddDate(-1, 0, -1))) t.Must.NotEmpty(UUID.Get(t)) t.Must.NotEmpty(Element.Get(t)) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(Bool.Get(testcase.ToT(&t.TB))) }) }) diff --git a/opts.go b/opts.go index cbd3016..9e7029f 100644 --- a/opts.go +++ b/opts.go @@ -56,7 +56,7 @@ func makeEventually(i any) (assert.Retry, bool) { } } -func RetryStrategyForEventually(strategy assert.RetryStrategy) SpecOption { +func WithRetryStrategy(strategy assert.RetryStrategy) SpecOption { return specOptionFunc(func(s *Spec) { s.eventually = &assert.Retry{Strategy: strategy} }) diff --git a/random/Factory_test.go b/random/Factory_test.go index d5ead18..f58295c 100644 --- a/random/Factory_test.go +++ b/random/Factory_test.go @@ -760,7 +760,7 @@ func TestFactory(t *testing.T) { s.Then("default random will be used to make a random", func(t *testcase.T) { var got = make(map[int]struct{}) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { got[act(t).(int)] = struct{}{} it.Must.True(len(got) > 1) @@ -783,7 +783,7 @@ func TestFactory(t *testing.T) { s.Then("random values are returned", func(t *testcase.T) { var got = make(map[string]struct{}) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { got[act(t).(string)] = struct{}{} it.Must.True(len(got) > 1) diff --git a/random/Make_test.go b/random/Make_test.go index 15ddb5c..f0a0918 100644 --- a/random/Make_test.go +++ b/random/Make_test.go @@ -54,17 +54,17 @@ func TestRandom_Make(t *testing.T) { }) s.Test("bool", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(rnd.Get(t).Make(bool(false)).(bool)) }) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.False(rnd.Get(t).Make(bool(false)).(bool)) }) }) s.Test("string", func(t *testcase.T) { str := rnd.Get(t).Make(string("")) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(str) it.Must.NotEqual( @@ -74,7 +74,7 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("Integer", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(rnd.Get(t).Make(int(0)).(int), int(0)) it.Must.NotEqual(rnd.Get(t).Make(int8(0)).(int8), int8(0)) it.Must.NotEqual(rnd.Get(t).Make(int16(0)).(int16), int16(0)) @@ -83,7 +83,7 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("unsigned Integer", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(rnd.Get(t).Make(uint(0)).(uint), uint(0)) it.Must.NotEqual(rnd.Get(t).Make(uint8(0)).(uint8), uint8(0)) it.Must.NotEqual(rnd.Get(t).Make(uint16(0)).(uint16), uint16(0)) @@ -92,18 +92,18 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("uintptr", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(rnd.Get(t).Make(uintptr(0)), uintptr(0)) }) }) s.Test("floating point number", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(rnd.Get(t).Make(float64(0)).(float64), float64(0)) it.Must.NotEqual(rnd.Get(t).Make(float32(0)).(float32), float32(0)) }) }) s.Test("array", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { var strings [42]string = rnd.Get(t).Make([42]string{}).([42]string) it.Must.NotNil(strings) @@ -116,7 +116,7 @@ func TestRandom_Make(t *testing.T) { }) }) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { var ints [42]int = rnd.Get(t).Make([42]int{}).([42]int) it.Must.NotNil(ints) @@ -130,7 +130,7 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("slice", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { var strings []string = rnd.Get(t).Make([]string{}).([]string) it.Must.NotNil(strings) @@ -143,7 +143,7 @@ func TestRandom_Make(t *testing.T) { }) }) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { var ints []int = rnd.Get(t).Make([]int{}).([]int) it.Must.NotNil(ints) @@ -157,7 +157,7 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("chan", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { ch := rnd.Get(t).Make(make(chan int)).(chan int) it.Must.NotNil(ch) it.Log("should be still empty") @@ -166,7 +166,7 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("map", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { m := rnd.Get(t).Make(map[string]int{}).(map[string]int) it.Must.NotNil(m) it.Must.NotEmpty(m) @@ -178,7 +178,7 @@ func TestRandom_Make(t *testing.T) { }) }) s.Test("pointer", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { m := rnd.Get(t).Make((*int)(nil)).(*int) it.Must.NotNil(m) it.Must.NotEmpty(*m) @@ -191,13 +191,13 @@ func TestRandom_Make(t *testing.T) { }) s.Test(`duration`, func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(rnd.Get(t).Make(time.Duration(0)).(time.Duration)) }) }) s.Test(`time`, func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { tm := rnd.Get(t).Make(time.Time{}).(time.Time) it.Must.False(tm.IsZero()) it.Must.NotEqual( @@ -211,75 +211,75 @@ func TestRandom_Make(t *testing.T) { makeExample := func() Example { return rnd.Get(t).Make(Example{}).(Example) } - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(makeExample().Bool) }) v := makeExample() - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().String) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int8) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int16) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int32) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int64) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UIntPtr) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt8) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt16) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt32) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt64) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Float32) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Float64) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ArrayOfInt) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ArrayOfString) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.SliceOfInt) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.SliceOfString) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ChanOfInt) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ChanOfString) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.Map) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(*v.StringPtr) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(*v.IntPtr) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(v.ExampleStruct.Int) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(v.ExampleStruct.String) }) - t.Eventually(func(it assert.It) { it.Must.Nil(v.Func) }) - t.Eventually(func(it assert.It) { it.Must.NotEqual(time.Duration(0), v.Duration) }) - t.Eventually(func(it assert.It) { it.Must.False(v.Time.IsZero()) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().String) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int8) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int16) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int32) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int64) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UIntPtr) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt8) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt16) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt32) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt64) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Float32) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Float64) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ArrayOfInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ArrayOfString) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.SliceOfInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.SliceOfString) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ChanOfInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ChanOfString) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.Map) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(*v.StringPtr) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(*v.IntPtr) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(v.ExampleStruct.Int) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(v.ExampleStruct.String) }) + t.Eventually(func(it *testcase.T) { it.Must.Nil(v.Func) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(time.Duration(0), v.Duration) }) + t.Eventually(func(it *testcase.T) { it.Must.False(v.Time.IsZero()) }) }) s.Test("*struct", func(t *testcase.T) { makeExample := func() *Example { return rnd.Get(t).Make(new(Example)).(*Example) } - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(makeExample().Bool) }) v := makeExample() - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().String) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int8) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int16) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int32) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Int64) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UIntPtr) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt8) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt16) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt32) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().UInt64) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Float32) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(makeExample().Float64) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ArrayOfInt) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ArrayOfString) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.SliceOfInt) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.SliceOfString) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ChanOfInt) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.ChanOfString) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(v.Map) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(*v.StringPtr) }) - t.Eventually(func(it assert.It) { it.Must.NotNil(*v.IntPtr) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(v.ExampleStruct.Int) }) - t.Eventually(func(it assert.It) { it.Must.NotEmpty(v.ExampleStruct.String) }) - t.Eventually(func(it assert.It) { it.Must.Nil(v.Func) }) - t.Eventually(func(it assert.It) { it.Must.NotEqual(time.Duration(0), v.Duration) }) - t.Eventually(func(it assert.It) { it.Must.False(v.Time.IsZero()) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().String) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int8) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int16) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int32) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Int64) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UIntPtr) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt8) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt16) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt32) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().UInt64) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Float32) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(makeExample().Float64) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ArrayOfInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ArrayOfString) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.SliceOfInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.SliceOfString) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ChanOfInt) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.ChanOfString) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(v.Map) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(*v.StringPtr) }) + t.Eventually(func(it *testcase.T) { it.Must.NotNil(*v.IntPtr) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(v.ExampleStruct.Int) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEmpty(v.ExampleStruct.String) }) + t.Eventually(func(it *testcase.T) { it.Must.Nil(v.Func) }) + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(time.Duration(0), v.Duration) }) + t.Eventually(func(it *testcase.T) { it.Must.False(v.Time.IsZero()) }) }) } diff --git a/random/Random_test.go b/random/Random_test.go index 5439799..2868a4d 100644 --- a/random/Random_test.go +++ b/random/Random_test.go @@ -203,7 +203,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then(`it create random errors on each call`, func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(act(t), act(t), `it was expected to create different error`) }) }) @@ -223,7 +223,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then(`it create random strings on each call`, func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.NotEqual(subject(t), subject(t), `it was expected to create different strings`) }) }) @@ -266,7 +266,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { s.Then("continuous reading yields different results", func(t *testcase.T) { sampling := t.Random.IntB(42, 82) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { var results = make(map[string]struct{}) for i := 0; i < sampling; i++ { n, err := act(t) @@ -403,7 +403,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { s.Then("calling it bulk yields relatively random UUIDs", func(t *testcase.T) { sampling := t.Random.IntB(512, SamplingNumber) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { results := make(map[string]struct{}) for i := 0; i < sampling; i++ { results[act(t)] = struct{}{} @@ -435,13 +435,13 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then("it occasionally returns a valid male name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleMaleName, act(t).FirstName) }) }) s.Then("it occasionally returns a valid female name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleFemaleName, act(t).FirstName) }) }) @@ -452,7 +452,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then("it occasionally returns a valid male name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleMaleName, act(t).FirstName) }) }) @@ -475,7 +475,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then("it occasionally returns a valid female name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleFemaleName, act(t).FirstName) }) }) @@ -498,13 +498,13 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then("it occasionally returns a valid male name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleMaleName, act(t).FirstName) }) }) s.Then("it occasionally returns a valid female name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleFemaleName, act(t).FirstName) }) }) @@ -519,7 +519,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { s.Then("it returns a valid common last name", func(t *testcase.T) { const exampleLastName = "Walker" - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleLastName, act(t).LastName) }) }) @@ -533,7 +533,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { s.Then("it returns a valid common email domain", func(t *testcase.T) { const exampleDomainSuffix = "@gmail.com" - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(strings.HasSuffix(act(t).Email, exampleDomainSuffix)) }) }) @@ -588,9 +588,9 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then("it returns a valid common domain", func(t *testcase.T) { - t.Eventually(func(it assert.It) { it.Must.Equal(act(t), "google.com") }) - t.Eventually(func(it assert.It) { it.Must.Equal(act(t), "amazon.com") }) - t.Eventually(func(it assert.It) { it.Must.Equal(act(t), "youtube.com") }) + t.Eventually(func(it *testcase.T) { it.Must.Equal(act(t), "google.com") }) + t.Eventually(func(it *testcase.T) { it.Must.Equal(act(t), "amazon.com") }) + t.Eventually(func(it *testcase.T) { it.Must.Equal(act(t), "youtube.com") }) }) }) @@ -610,13 +610,13 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { }) s.Then("it occasionally returns a valid male name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleMaleName, act(t)) }) }) s.Then("it occasionally returns a valid female name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleFemaleName, act(t)) }) }) @@ -627,7 +627,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { } s.Then("it occasionally returns a valid male name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleMaleName, act(t)) }) }) @@ -650,7 +650,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { } s.Then("it occasionally returns a valid female name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleFemaleName, act(t)) }) }) @@ -673,13 +673,13 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { } s.Then("it occasionally returns a valid male name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleMaleName, act(t)) }) }) s.Then("it occasionally returns a valid female name", func(t *testcase.T) { - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleFemaleName, act(t)) }) }) @@ -698,7 +698,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { s.Then("it returns a valid common last name", func(t *testcase.T) { const exampleLastName = "Walker" - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.Equal(exampleLastName, act(t)) }) }) @@ -716,7 +716,7 @@ func SpecRandomMethods(s *testcase.Spec, rnd testcase.Var[*random.Random]) { s.Then("it returns a valid common email domain", func(t *testcase.T) { const exampleDomainSuffix = "@gmail.com" - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { it.Must.True(strings.HasSuffix(act(t), exampleDomainSuffix)) }) }) diff --git a/random/pick_test.go b/random/pick_test.go index efaf412..7a98e9c 100644 --- a/random/pick_test.go +++ b/random/pick_test.go @@ -5,7 +5,6 @@ import ( "testing" "go.llib.dev/testcase" - "go.llib.dev/testcase/assert" "go.llib.dev/testcase/let" "go.llib.dev/testcase/random" ) @@ -44,7 +43,7 @@ func TestPick(t *testing.T) { } var got = make(map[int]struct{}) - t.Eventually(func(it assert.It) { + t.Eventually(func(it *testcase.T) { got[act(t)] = struct{}{} it.Must.ContainExactly(exp, got)