mirror of
https://github.com/ceph/go-ceph
synced 2025-02-16 10:37:19 +00:00
implements: add io.Writer argument when creating text report
This io.Writer will be the destination for writes from the report. This better matches with what the JSON report was doing. Signed-off-by: John Mulligan <jmulligan@redhat.com>
This commit is contained in:
parent
217e502afa
commit
3e15044962
@ -2,6 +2,7 @@ package implements
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -25,11 +26,20 @@ type Reporter interface {
|
|||||||
// TextReport implements a streaming plain-text output report.
|
// TextReport implements a streaming plain-text output report.
|
||||||
type TextReport struct {
|
type TextReport struct {
|
||||||
o ReportOptions
|
o ReportOptions
|
||||||
|
// io destination
|
||||||
|
dest io.Writer
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTextReport creates a new TextReport.
|
// NewTextReport creates a new TextReport.
|
||||||
func NewTextReport(o ReportOptions) *TextReport {
|
func NewTextReport(o ReportOptions, dest io.Writer) *TextReport {
|
||||||
return &TextReport{o}
|
return &TextReport{o, dest}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *TextReport) printf(f string, v ...interface{}) {
|
||||||
|
_, err := fmt.Fprintf(r.dest, f, v...)
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report on the given code inspector.
|
// Report on the given code inspector.
|
||||||
@ -41,20 +51,20 @@ func (r *TextReport) Report(name string, ii *Inspector) error {
|
|||||||
|
|
||||||
found := len(ii.found)
|
found := len(ii.found)
|
||||||
total := len(ii.expected)
|
total := len(ii.expected)
|
||||||
fmt.Printf(
|
r.printf(
|
||||||
"%s functions covered: %d/%d : %v%%\n",
|
"%s functions covered: %d/%d : %v%%\n",
|
||||||
packageLabel,
|
packageLabel,
|
||||||
found,
|
found,
|
||||||
total,
|
total,
|
||||||
(100*found)/total)
|
(100*found)/total)
|
||||||
missing := total - found - ii.deprecatedMissing
|
missing := total - found - ii.deprecatedMissing
|
||||||
fmt.Printf(
|
r.printf(
|
||||||
"%s functions missing: %d/%d : %v%%\n",
|
"%s functions missing: %d/%d : %v%%\n",
|
||||||
packageLabel,
|
packageLabel,
|
||||||
missing,
|
missing,
|
||||||
total,
|
total,
|
||||||
(100*missing)/total)
|
(100*missing)/total)
|
||||||
fmt.Printf(
|
r.printf(
|
||||||
" (note missing count does not include deprecated functions in ceph)\n")
|
" (note missing count does not include deprecated functions in ceph)\n")
|
||||||
|
|
||||||
if !o.List {
|
if !o.List {
|
||||||
@ -78,7 +88,7 @@ func (r *TextReport) Report(name string, ii *Inspector) error {
|
|||||||
tags = " (" + strings.TrimSpace(tags) + ")"
|
tags = " (" + strings.TrimSpace(tags) + ")"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf(" Found: %s%s\n", cf.Name, tags)
|
r.printf(" Found: %s%s\n", cf.Name, tags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, cf := range ii.expected {
|
for _, cf := range ii.expected {
|
||||||
@ -89,7 +99,7 @@ func (r *TextReport) Report(name string, ii *Inspector) error {
|
|||||||
if o.Annotate && cf.isDeprecated() {
|
if o.Annotate && cf.isDeprecated() {
|
||||||
d = " (deprecated)"
|
d = " (deprecated)"
|
||||||
}
|
}
|
||||||
fmt.Printf(" Missing: %s%s\n", cf.Name, d)
|
r.printf(" Missing: %s%s\n", cf.Name, d)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user