Skip to content

Commit

Permalink
Display n slowest tests within a pkg with -slow
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Feb 19, 2019
1 parent eea49c7 commit 4658b67
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ var (
smallScreenPtr = flag.Bool("smallscreen", false, "")
topPtr = flag.Bool("top", false, "") // TODO(mf): rename this to -reverse with v1
noColorPtr = flag.Bool("nocolor", false, "")
slowPtr = flag.Int("slow", 0, "")
)

var usage = `Usage:
Expand All @@ -48,6 +49,7 @@ Options:
-dump Enables recovering go test output in non-JSON format.
-smallscreen Split subtest names vertically to fit on smaller screens.
-top Display summary table towards top.
-slow Number of slowest tests to display. Default is 0, display all.
-nocolor Disable all colors.
`

Expand Down Expand Up @@ -109,6 +111,7 @@ func main() {

opts := testsTableOptions{
trim: *smallScreenPtr,
slow: *slowPtr,
}
if *allPtr {
opts.pass, opts.skip = true, true
Expand Down Expand Up @@ -298,11 +301,11 @@ func (w *consoleWriter) SummaryTable(pkgs parse.Packages, showNoTests bool) {

type testsTableOptions struct {
pass, skip, trim bool
slow int
}

func (w *consoleWriter) TestsTable(pkgs parse.Packages, options testsTableOptions) {
// Print passed tests, sorted by elapsed. Unlike failed tests, passed tests
// are not grouped. Maybe bad design?
// Print passed tests, sorted by elapsed. Grouped by alphabetically sorted pkgs.
tbl := tablewriter.NewWriter(w.Output)

tbl.SetHeader([]string{
Expand Down Expand Up @@ -356,6 +359,10 @@ func (w *consoleWriter) TestsTable(pkgs parse.Packages, options testsTableOption
continue
}

if options.slow > 0 && len(all) > options.slow {
all = all[:options.slow]
}

for _, t := range all {
t.SortEvents()

Expand Down

0 comments on commit 4658b67

Please sign in to comment.