Print the byte unit once in the summary line (closes #17)
check / check (push) Successful in 3m8s
check / check (push) Successful in 3m8s
formatBytes already ends in a unit, so the summary line read "9 B bytes" or "1.0 KiB bytes". The format string in Stats.Print no longer adds the word "bytes". Print now takes the io.Writer to print to; its callers pass os.Stderr, and the new test passes a buffer to read the line for one small and one large byte count. Model: opus-5-5
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -328,3 +329,27 @@ func TestCheckContinuePastUnreadable(t *testing.T) {
|
||||
t.Fatalf("expected verification error from runCheck, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummaryPrintsByteUnitOnce(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
tests := []struct {
|
||||
bytesProcessed int64
|
||||
want string
|
||||
}{
|
||||
{9, ", 9 B in "},
|
||||
{1536, ", 1.5 KiB in "},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
var out bytes.Buffer
|
||||
|
||||
stats := newTestStats()
|
||||
stats.BytesProcessed = tt.bytesProcessed
|
||||
stats.Print(&out, &options{}, "check")
|
||||
|
||||
if !strings.Contains(out.String(), tt.want) {
|
||||
t.Errorf("summary %q does not contain %q", out.String(), tt.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user