Skip to content

Commit

Permalink
Fix panic when terminal width is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Dec 24, 2019
1 parent 3233960 commit 66f0a38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 1 addition & 2 deletions testjson/dotformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ func (l *dotLine) checkWidth(prefix, terminal int) {
func newDotFormatter(out io.Writer) EventFormatter {
w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
if err != nil || w == 0 {
logrus.Warn(err.Error())
logrus.Warn("Failed to detect terminal width for dots format.")
logrus.Warnf("Failed to detect terminal width for dots format, error: %v", err)
return &formatAdapter{format: dotsFormatV1, out: out}
}
return &dotFormatter{
Expand Down
13 changes: 11 additions & 2 deletions testjson/dotformat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"time"
"unicode/utf8"

"gotest.tools/gotestsum/internal/dotwriter"

"gotest.tools/assert"
"gotest.tools/assert/cmp"
"gotest.tools/golden"
"gotest.tools/gotestsum/internal/dotwriter"
"gotest.tools/skip"
)

func TestScanTestOutput_WithDotsFormatter(t *testing.T) {
Expand Down Expand Up @@ -152,3 +152,12 @@ func TestFmtDotElapsed_RuneCountProperty(t *testing.T) {
Rand: rand.New(rand.NewSource(seed)),
}))
}

func TestNewDotFormatter(t *testing.T) {
buf := new(bytes.Buffer)
ef := newDotFormatter(buf)

d, ok := ef.(*dotFormatter)
skip.If(t, !ok, "no terminal width")
assert.Assert(t, d.termWidth != 0)
}

0 comments on commit 66f0a38

Please sign in to comment.