Skip to content

Commit

Permalink
Remove redundant package methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Oct 19, 2018
1 parent 6bb7988 commit 52090a5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 43 deletions.
6 changes: 2 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {

// Print failed package tests (if any).
for _, p := range pkgs {
failed := p.Failed()
failed := p.TestsByAction(parse.ActionFail)
if len(failed) == 0 {
continue
}
Expand All @@ -66,14 +66,12 @@ func main() {

var i int
for _, p := range pkgs {
passed := p.Passed()
passed := p.TestsByAction(parse.ActionPass)
if len(passed) == 0 {
continue
}

// Sort tests within a package by elapsed time in descending order, longest on top.
// TODO: I don't like how this works. Ideally all "pass" tests of all packages will be grouped
// and sorted by elapsed time.
sort.Slice(passed, func(i, j int) bool {
return passed[i].Elapsed() > passed[j].Elapsed()
})
Expand Down
57 changes: 18 additions & 39 deletions parse/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"os"
"sort"
"strconv"

"github.com/olekukonko/tablewriter"
Expand Down Expand Up @@ -39,9 +38,9 @@ func (p Packages) Print() {
pkg.Summary.Action.WithColor(),
strconv.FormatFloat(pkg.Summary.Elapsed, 'f', 2, 64),
name,
strconv.Itoa(len(pkg.Passed())),
strconv.Itoa(len(pkg.Failed())),
strconv.Itoa(len(pkg.Skipped())),
strconv.Itoa(len(pkg.TestsByAction(ActionPass))),
strconv.Itoa(len(pkg.TestsByAction(ActionFail))),
strconv.Itoa(len(pkg.TestsByAction(ActionSkip))),
})
}

Expand Down Expand Up @@ -106,7 +105,7 @@ func Do(r io.Reader) (Packages, error) {
}

if err := sc.Err(); err != nil {
// something went wrong scanning. We may want to fail? and dump
// TODO: FIXME: something went wrong scanning. We may want to fail? and dump
// what we were able to read.
// E.g., store events in strings.Builder and dump the output lines,
// or return a structured error with context and events we were able to read.
Expand All @@ -116,46 +115,26 @@ func Do(r io.Reader) (Packages, error) {
return pkgs, nil
}

// Passed returns a slice of tests, sorted by time.
func (p *Package) Passed() []*Test {
passed := []*Test{}
// TestsByAction returns all tests that identify as one of the following
// actions: pass, skip or fail.
//
// If there are no tests an empty slice is returned.
func (p *Package) TestsByAction(action Action) []*Test {
tests := []*Test{}

for _, t := range p.Tests {
if t.Status() == ActionPass {
passed = append(passed, t)
if t.Status() == action {
tests = append(tests, t)
}
}
if len(passed) == 0 {
return passed
}

sort.Slice(passed, func(i, j int) bool {
return passed[i].Elapsed() > passed[i].Elapsed()
})

return passed
return tests
}

func (p *Package) Failed() []*Test {
failed := []*Test{}
/*
for _, t := range p.Tests {
if t.Status() == ActionFail {
failed = append(failed, t)
}
}

return failed
}

func (p *Package) Skipped() []*Test {
skipped := []*Test{}

for _, t := range p.Tests {
if t.Status() == ActionSkip {
skipped = append(skipped, t)
}
}
sort.Slice(passed, func(i, j int) bool {
return passed[i].Elapsed() > passed[i].Elapsed()
})
return skipped
}
*/

0 comments on commit 52090a5

Please sign in to comment.