From 13d903a6f2de5bd9463c81483da34ca1b39e77ff Mon Sep 17 00:00:00 2001 From: Nathan Rijksen Date: Fri, 6 Oct 2023 12:11:11 -0700 Subject: [PATCH] Expose constructed void logger to minimize boilerplate for consumers --- helpers.go | 4 ++-- helpers_test.go | 2 +- termtest.go | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/helpers.go b/helpers.go index 3fab64b..3144ad2 100644 --- a/helpers.go +++ b/helpers.go @@ -9,9 +9,9 @@ import ( "time" ) -type VoidLogger struct{} +type voidLogger struct{} -func (v VoidLogger) Write(p []byte) (n int, err error) { return len(p), nil } +func (v voidLogger) Write(p []byte) (n int, err error) { return len(p), nil } var neverGonnaHappen = time.Hour * 24 * 365 * 100 diff --git a/helpers_test.go b/helpers_test.go index 7eef96f..7dce63c 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -60,7 +60,7 @@ func newTermTest(t *testing.T, cmd *exec.Cmd, logging bool, opts ...SetOpt) *Ter tt, err := New(cmd, append(opts, func(o *Opts) error { o = newTestOpts(o, t) if !logging { - o.Logger = log.New(VoidLogger{}, "TermTest: ", log.LstdFlags) + o.Logger = VoidLogger } return nil }, OptTestErrorHandler(t))...) diff --git a/termtest.go b/termtest.go index 151918c..7677bce 100644 --- a/termtest.go +++ b/termtest.go @@ -43,6 +43,8 @@ var TimeoutError = errors.New("timeout") var VerboseLogger = log.New(os.Stderr, "TermTest: ", log.LstdFlags|log.Lshortfile) +var VoidLogger = log.New(voidLogger{}, "", 0) + type SetOpt func(o *Opts) error const DefaultCols = 140 @@ -50,7 +52,7 @@ const DefaultRows = 10 func NewOpts() *Opts { return &Opts{ - Logger: log.New(VoidLogger{}, "TermTest: ", log.LstdFlags|log.Lshortfile), + Logger: VoidLogger, ExpectErrorHandler: func(_ *TermTest, err error) error { panic(err) },