2024-01-20 17:40:22 +00:00
|
|
|
package progress
|
|
|
|
|
2024-04-14 09:44:13 +00:00
|
|
|
import "testing"
|
|
|
|
|
2024-01-20 17:40:22 +00:00
|
|
|
// A Printer can can return a new counter or print messages
|
|
|
|
// at different log levels.
|
|
|
|
// It must be safe to call its methods from concurrent goroutines.
|
|
|
|
type Printer interface {
|
|
|
|
NewCounter(description string) *Counter
|
|
|
|
|
|
|
|
E(msg string, args ...interface{})
|
|
|
|
P(msg string, args ...interface{})
|
|
|
|
V(msg string, args ...interface{})
|
|
|
|
VV(msg string, args ...interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// NoopPrinter discards all messages
|
|
|
|
type NoopPrinter struct{}
|
|
|
|
|
|
|
|
var _ Printer = (*NoopPrinter)(nil)
|
|
|
|
|
2024-01-20 20:58:28 +00:00
|
|
|
func (*NoopPrinter) NewCounter(_ string) *Counter {
|
2024-01-20 17:40:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-20 20:58:28 +00:00
|
|
|
func (*NoopPrinter) E(_ string, _ ...interface{}) {}
|
2024-01-20 17:40:22 +00:00
|
|
|
|
2024-01-20 20:58:28 +00:00
|
|
|
func (*NoopPrinter) P(_ string, _ ...interface{}) {}
|
2024-01-20 17:40:22 +00:00
|
|
|
|
2024-01-20 20:58:28 +00:00
|
|
|
func (*NoopPrinter) V(_ string, _ ...interface{}) {}
|
2024-01-20 17:40:22 +00:00
|
|
|
|
2024-01-20 20:58:28 +00:00
|
|
|
func (*NoopPrinter) VV(_ string, _ ...interface{}) {}
|
2024-04-14 09:44:13 +00:00
|
|
|
|
|
|
|
// TestPrinter prints messages during testing
|
|
|
|
type TestPrinter struct {
|
|
|
|
t testing.TB
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewTestPrinter(t testing.TB) *TestPrinter {
|
|
|
|
return &TestPrinter{
|
|
|
|
t: t,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ Printer = (*TestPrinter)(nil)
|
|
|
|
|
|
|
|
func (p *TestPrinter) NewCounter(_ string) *Counter {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TestPrinter) E(msg string, args ...interface{}) {
|
|
|
|
p.t.Logf("error: "+msg, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TestPrinter) P(msg string, args ...interface{}) {
|
|
|
|
p.t.Logf("print: "+msg, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TestPrinter) V(msg string, args ...interface{}) {
|
|
|
|
p.t.Logf("verbose: "+msg, args...)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *TestPrinter) VV(msg string, args ...interface{}) {
|
|
|
|
p.t.Logf("verbose2: "+msg, args...)
|
|
|
|
}
|