Fix log silencing in tests

Tests were broken in Go 1.14.
pull/1/head
Marc-Antoine Ruel 6 years ago
parent 8284066f76
commit 816785ac40

@ -6,6 +6,7 @@ package bmxx80
import ( import (
"errors" "errors"
"flag"
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
@ -610,10 +611,6 @@ func TestI2CSenseContinuous280_command_fail(t *testing.T) {
} }
func TestI2CSenseContinuous280_sense_fail(t *testing.T) { func TestI2CSenseContinuous280_sense_fail(t *testing.T) {
if !testing.Verbose() {
log.SetOutput(ioutil.Discard)
defer log.SetOutput(os.Stderr)
}
bus := i2ctest.Playback{ bus := i2ctest.Playback{
Ops: []i2ctest.IO{ Ops: []i2ctest.IO{
// Chip ID detection. // Chip ID detection.
@ -1027,3 +1024,11 @@ type spiFail struct {
func (s *spiFail) Connect(f physic.Frequency, mode spi.Mode, bits int) (spi.Conn, error) { func (s *spiFail) Connect(f physic.Frequency, mode spi.Mode, bits int) (spi.Conn, error) {
return nil, errors.New("failing") return nil, errors.New("failing")
} }
func TestMain(m *testing.M) {
flag.Parse()
if !testing.Verbose() {
log.SetOutput(ioutil.Discard)
}
os.Exit(m.Run())
}

@ -8,6 +8,7 @@ import (
"flag" "flag"
"io/ioutil" "io/ioutil"
"log" "log"
"os"
"reflect" "reflect"
"testing" "testing"
"time" "time"
@ -230,8 +231,12 @@ func setupPlaybackIO() []i2ctest.IO {
func init() { func init() {
sleep = func(time.Duration) {} sleep = func(time.Duration) {}
}
func TestMain(m *testing.M) {
flag.Parse() flag.Parse()
if !testing.Verbose() { if !testing.Verbose() {
log.SetOutput(ioutil.Discard) log.SetOutput(ioutil.Discard)
} }
os.Exit(m.Run())
} }

Loading…
Cancel
Save