Skip to content

Commit

Permalink
Expose constructed void logger to minimize boilerplate for consumers
Browse files Browse the repository at this point in the history
  • Loading branch information
Naatan committed Oct 6, 2023
1 parent 68c9fe7 commit 13d903a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 2 additions & 2 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))...)
Expand Down
4 changes: 3 additions & 1 deletion termtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ 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
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)
},
Expand Down

0 comments on commit 13d903a

Please sign in to comment.