Skip to content

Commit

Permalink
Restore old format for dots
Browse files Browse the repository at this point in the history
Attempt to fix dots-v2 by adding empty newlines
  • Loading branch information
dnephin committed Feb 25, 2020
1 parent 9a4b2e3 commit 183b435
Show file tree
Hide file tree
Showing 7 changed files with 333 additions and 116 deletions.
2 changes: 1 addition & 1 deletion internal/dotwriter/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func (w *Writer) Flush() error {
if w.buf.Len() == 0 {
return nil
}
w.clearLines()
w.clearLines(w.lineCount)
w.lineCount = bytes.Count(w.buf.Bytes(), []byte{'\n'})
_, err := w.out.Write(w.buf.Bytes())
w.buf.Reset()
Expand Down
4 changes: 2 additions & 2 deletions internal/dotwriter/writer_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ import (
// clear the line and move the cursor up
var clear = fmt.Sprintf("%c[%dA%c[2K", ESC, 1, ESC)

func (w *Writer) clearLines() {
_, _ = fmt.Fprint(w.out, strings.Repeat(clear, w.lineCount))
func (w *Writer) clearLines(count int) {
_, _ = fmt.Fprint(w.out, strings.Repeat(clear, count))
}
6 changes: 3 additions & 3 deletions internal/dotwriter/writer_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ type fdWriter interface {
Fd() uintptr
}

func (w *Writer) clearLines() {
func (w *Writer) clearLines(count int) {
f, ok := w.out.(fdWriter)
if ok && !isatty.IsTerminal(f.Fd()) {
ok = false
}
if !ok {
_, _ = fmt.Fprint(w.out, strings.Repeat(clear, w.lineCount))
_, _ = fmt.Fprint(w.out, strings.Repeat(clear, count))
return
}
fd := f.Fd()
var csbi consoleScreenBufferInfo
_, _, _ = procGetConsoleScreenBufferInfo.Call(fd, uintptr(unsafe.Pointer(&csbi)))

for i := 0; i < w.lineCount; i++ {
for i := 0; i < count; i++ {
// move the cursor up
csbi.cursorPosition.y--
_, _, _ = procSetConsoleCursorPosition.Call(fd, uintptr(*(*int32)(unsafe.Pointer(&csbi.cursorPosition))))
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Flags:
fmt.Fprint(os.Stderr, `
Formats:
dots print a character for each test
dots-compact dots, without the newlines
dots-v2 experimental dots format, one package per line
pkgname print a line for each package
pkgname-and-test-fails print a line for each package and failed test output
testname print a line for each test and package
Expand Down
3 changes: 3 additions & 0 deletions testjson/dotformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (d *dotFormatter) Format(event TestEvent, exec *Execution) error {
return nil
}

// Add an empty header to work around incorrect line counting
fmt.Fprint(d.writer, "\n\n")

sort.Slice(d.order, d.orderByLastUpdated)
for _, pkg := range d.order {
line := d.pkgs[pkg]
Expand Down
6 changes: 3 additions & 3 deletions testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,10 @@ func NewEventFormatter(out io.Writer, format string) EventFormatter {
return &formatAdapter{out, standardVerboseFormat}
case "standard-quiet":
return &formatAdapter{out, standardQuietFormat}
case "dots":
return newDotFormatter(out)
case "dots-compact":
case "dots", "dots-v1":
return &formatAdapter{out, dotsFormatV1}
case "dots-v2":
return newDotFormatter(out)
case "testname", "short-verbose":
return &formatAdapter{out, shortVerboseFormat}
case "pkgname", "short":
Expand Down
Loading

0 comments on commit 183b435

Please sign in to comment.