Skip to content

Commit 702554f

Browse files
committed
chore: update dependencies and fix new lint rules
1 parent fd7e1f1 commit 702554f

23 files changed

+114
-40
lines changed

assert.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func Assert(t TestingT, result bool, msgAndArgs ...any) bool {
4040
t.Helper()
4141

4242
logResult(t, result, 1, msgAndArgs...)
43+
4344
if !result {
4445
t.Fail()
4546
}
@@ -53,6 +54,7 @@ func Require(t TestingT, result bool, msgAndArgs ...any) {
5354
t.Helper()
5455

5556
logResult(t, result, 1, msgAndArgs...)
57+
5658
if !result {
5759
t.FailNow()
5860
}
@@ -85,6 +87,7 @@ func logResult(t TestingT, result bool, callerStackIndex int, msgAndArgs ...any)
8587

8688
if (result && (SuccessMessageEnabled || *_flagEnableSuccessMessage)) || !result {
8789
var err error
90+
8891
msg, err = message.FromBool(callerStackIndex+1, result)
8992
if err != nil {
9093
t.Logf("krostar/test internal failure: unable to get assertion message: %v", err)

assert_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,22 @@ func Test_Assert(t *testing.T) {
1313
if result := Assert(spiedT, true, "hello from %s", t.Name()); !result {
1414
t.Error("Assert should return true when result is true")
1515
}
16+
1617
spiedT.ExpectTestToPass(t)
1718
spiedT.ExpectNoLogs(t)
1819
})
1920

2021
t.Run("with success message enabled", func(t *testing.T) {
2122
originalSuccessMessageEnabled := SuccessMessageEnabled
2223
t.Cleanup(func() { SuccessMessageEnabled = originalSuccessMessageEnabled })
24+
2325
SuccessMessageEnabled = true
2426

2527
spiedT := double.NewSpy(double.NewFake())
2628
if result := Assert(spiedT, true, "hello from %s", t.Name()); !result {
2729
t.Error("Assert should return true when result is true")
2830
}
31+
2932
spiedT.ExpectTestToPass(t)
3033
spiedT.ExpectLogsToContain(t, "Success:", "[hello from Test_Assert/assertion_true/with_success_message_enabled]")
3134
})
@@ -36,6 +39,7 @@ func Test_Assert(t *testing.T) {
3639
if result := Assert(spiedT, false, "hello from %s", t.Name()); result {
3740
t.Error("Assert should return false when result is false")
3841
}
42+
3943
spiedT.ExpectTestToFail(t)
4044
spiedT.ExpectLogsToContain(t, "Error:", "[hello from Test_Assert/assertion_false]")
4145
})
@@ -53,6 +57,7 @@ func Test_Require(t *testing.T) {
5357
t.Run("with success message enabled", func(t *testing.T) {
5458
originalSuccessMessageEnabled := SuccessMessageEnabled
5559
t.Cleanup(func() { SuccessMessageEnabled = originalSuccessMessageEnabled })
60+
5661
SuccessMessageEnabled = true
5762

5863
spiedT := double.NewSpy(double.NewFake())
@@ -75,6 +80,7 @@ func Test_logResult(t *testing.T) {
7580
t.Run("success without message", func(t *testing.T) {
7681
originalSuccessMessageEnabled := SuccessMessageEnabled
7782
t.Cleanup(func() { SuccessMessageEnabled = originalSuccessMessageEnabled })
83+
7884
SuccessMessageEnabled = false
7985

8086
spiedT := double.NewSpy(double.NewFake())
@@ -85,6 +91,7 @@ func Test_logResult(t *testing.T) {
8591
t.Run("success with message", func(t *testing.T) {
8692
originalSuccessMessageEnabled := SuccessMessageEnabled
8793
t.Cleanup(func() { SuccessMessageEnabled = originalSuccessMessageEnabled })
94+
8895
SuccessMessageEnabled = true
8996

9097
spiedT := double.NewSpy(double.NewFake())

check/check.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func Eventually(ctx context.Context, t test.TestingT, check func(context.Context
5252
} else {
5353
return t, true, fmt.Sprintf("check passed in %s with %d retries", time.Since(startedAt).String(), retries)
5454
}
55+
5556
retries++
57+
5658
ticker.Reset(timeBetweenRetries)
5759

5860
case <-ticker.C:
@@ -102,7 +104,8 @@ func Panics(t test.TestingT, f func(), assertReason func(reason any) error) (tt
102104
return t, false, "function to test for panic must not be nil"
103105
}
104106

105-
tt = t //
107+
tt = t
108+
106109
defer func() {
107110
reason := recover()
108111

check/check_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,22 @@ func Test_Compare(t *testing.T) {
5555
func Test_Eventually(t *testing.T) {
5656
t.Run("success after retries", func(t *testing.T) {
5757
retries := 0
58+
5859
ctx, cancel := context.WithTimeout(t.Context(), 500*time.Millisecond)
5960
defer cancel()
6061

6162
tt, result, msg := Eventually(ctx, t, func(context.Context) error {
6263
defer func() { retries++ }()
64+
6365
if retries < 2 {
6466
return fmt.Errorf("boom %d", retries)
6567
}
68+
6669
return nil
6770
}, time.Millisecond*10)
71+
6872
assertCheck(t, tt, result, true, msg, "check passed")
73+
6974
if retries < 2 {
7075
t.Errorf("expected at least 2 retries, got %d", retries)
7176
}
@@ -132,6 +137,7 @@ func Test_Panics(t *testing.T) {
132137
}
133138
return nil
134139
})
140+
135141
assertCheck(t, tt, result, true, msg, "function panicked like expected")
136142
})
137143

@@ -171,7 +177,7 @@ func assertCheck(t *testing.T, tt test.TestingT, result, expectedResult bool, ms
171177
t.Helper()
172178

173179
if t != tt.(*testing.T) {
174-
t.Errorf("expected check to return the same testingT as provided")
180+
t.Error("expected check to return the same testingT as provided")
175181
}
176182

177183
if result != expectedResult {

context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ func Context(t TestingT) context.Context {
3030
deadline = deadline.Add(-cleanDuration)
3131

3232
var cancel context.CancelFunc
33+
3334
ctx, cancel = context.WithDeadline(ctx, deadline)
3435
t.Cleanup(cancel)
3536
}

double/fake.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func (Fake) Fail() {}
4141
// This is a no-op implementation.
4242
func (Fake) FailNow() {}
4343

44+
// Log implements the TestingT interface.
45+
// This is a no-op implementation.
46+
func (Fake) Log(...any) {}
47+
4448
// Logf implements the TestingT interface.
4549
// This is a no-op implementation.
4650
func (Fake) Logf(string, ...any) {}

double/fake_option_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ func Test_FakeWithRegisterCleanup(t *testing.T) {
3131
called := false
3232
FakeWithRegisterCleanup(func(f func()) {
3333
called = true
34+
3435
f()
3536
})(o)
3637

3738
o.registerCleanup(func() {})
39+
3840
if !called {
3941
t.Error("registerCleanup was not set")
4042
}

double/spy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ func (spy *Spy) FailNow() {
7777
spy.failed = true
7878
}
7979

80+
// Log implements the TestingT interface.
81+
func (spy *Spy) Log(args ...any) {
82+
spy.m.Lock()
83+
defer spy.m.Unlock()
84+
85+
spy.underlyingT.Log(args...)
86+
spy.records = append(spy.records, SpyTestingTRecord{
87+
Method: "Log",
88+
Inputs: args,
89+
Outputs: nil,
90+
})
91+
spy.logs = append(spy.logs, fmt.Sprint(args...))
92+
}
93+
8094
// Logf implements the TestingT interface.
8195
func (spy *Spy) Logf(format string, args ...any) {
8296
spy.m.Lock()

double/spy_expect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (spy *Spy) ExpectTestToFail(t TestingT) {
111111
t.Helper()
112112

113113
if !spy.failed {
114-
t.Logf("Expected test to fail but test succeeded")
114+
t.Log("Expected test to fail but test succeeded")
115115
t.Fail()
116116
}
117117
}
@@ -126,7 +126,7 @@ func (spy *Spy) ExpectTestToPass(t TestingT) {
126126
t.Helper()
127127

128128
if spy.failed {
129-
t.Logf("Expected test to succeed but test failed")
129+
t.Log("Expected test to succeed but test failed")
130130
t.Fail()
131131
}
132132
}

double/spy_expect_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ func Test_SpyTestingT_ExpectRecords(t *testing.T) {
9494
func Test_SpyTestingT_ExpectNoLogs(t *testing.T) {
9595
testedT := NewSpy(NewFake())
9696
testedT.ExpectNoLogs(t)
97-
9897
testedT.Logf("hello world")
9998

10099
spiedT := NewSpy(NewFake())
@@ -106,11 +105,13 @@ func Test_SpyTestingT_ExpectNoLogs(t *testing.T) {
106105
func Test_SpyTestingT_ExpectLogsToContain(t *testing.T) {
107106
testedT := NewSpy(NewFake())
108107
spiedT := NewSpy(NewFake())
108+
109109
testedT.ExpectLogsToContain(spiedT, "foo")
110110
spiedT.ExpectTestToFail(t)
111111
spiedT.ExpectLogsToContain(t, "Expected log to contain message")
112112

113113
spiedT = NewSpy(NewFake())
114+
114115
testedT.Logf("hello world")
115116
testedT.ExpectLogsToContain(t, "hello world")
116117
testedT.ExpectLogsToContain(spiedT, "foo")
@@ -125,21 +126,20 @@ func Test_SpyTestingT_ExpectLogsToContain(t *testing.T) {
125126

126127
func Test_SpyTestingT_ExpectTestToFail(t *testing.T) {
127128
testedT := NewSpy(NewFake())
128-
129129
spiedT := NewSpy(NewFake())
130+
130131
testedT.ExpectTestToFail(spiedT)
131132
spiedT.ExpectTestToFail(t)
132133
spiedT.ExpectLogsToContain(t, "Expected test to fail but test succeeded")
133-
134134
testedT.Fail()
135135
testedT.ExpectTestToFail(t)
136136
}
137137

138138
func Test_SpyTestingT_ExpectTestToPass(t *testing.T) {
139139
testedT := NewSpy(NewFake())
140140
testedT.ExpectTestToPass(t)
141-
142141
testedT.Fail()
142+
143143
spiedT := NewSpy(NewFake())
144144
testedT.ExpectTestToPass(spiedT)
145145
spiedT.ExpectTestToFail(t)

0 commit comments

Comments
 (0)