Skip to content

Commit

Permalink
Correctly mark methods and test helpers in TestFmt (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
sergekh2 authored Dec 8, 2024
1 parent 6f0298d commit 7558e76
Showing 1 changed file with 41 additions and 17 deletions.
58 changes: 41 additions & 17 deletions core/node/testutils/testfmt/testfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,41 +51,65 @@ func Logf(t TestingLogger, format string, a ...any) {
}
}

func Enabled() bool {
return enabled
}

func Enable(v bool) {
enabled = v
}

type TestFmt struct {
t TestingLogger
t TestingLogger
enabled bool
}

// New returns a new TestFmt that logs to the given testing logger if RIVER_TEST_PRINT is set.
func New(t TestingLogger) TestFmt {
return TestFmt{t}
func New(t TestingLogger) *TestFmt {
return &TestFmt{t, enabled}
}

func (f TestFmt) Print(a ...any) {
Print(f.t, a...)
func (f *TestFmt) Print(a ...any) {
if f.enabled {
f.t.Helper()
f.t.Log(a...)
}
}

func (f TestFmt) Printf(format string, a ...any) {
Printf(f.t, format, a...)
func (f *TestFmt) Printf(format string, a ...any) {
if f.enabled {
f.t.Helper()
f.t.Logf(format, a...)
}
}

func (f TestFmt) Println(a ...any) {
Println(f.t, a...)
func (f *TestFmt) Println(a ...any) {
if f.enabled {
f.t.Helper()
f.t.Log(a...)
}
}

func (f TestFmt) Log(a ...any) {
Log(f.t, a...)
func (f *TestFmt) Log(a ...any) {
if f.enabled {
f.t.Helper()
f.t.Log(a...)
}
}

func (f TestFmt) Logf(format string, a ...any) {
Logf(f.t, format, a...)
func (f *TestFmt) Logf(format string, a ...any) {
if f.enabled {
f.t.Helper()
f.t.Logf(format, a...)
}
}

func Enabled() bool {
return enabled
func (f *TestFmt) Enabled() bool {
return f.enabled
}

func Enable(v bool) {
enabled = v
func (f *TestFmt) Enable(v bool) {
f.enabled = v
}

var enabled bool
Expand Down

0 comments on commit 7558e76

Please sign in to comment.