Skip to content

Commit

Permalink
Fixes #4; capture cached packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mfridman committed Oct 24, 2018
1 parent 5a5fd4e commit 48d8fea
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion parse/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (e *Event) Discard() bool {
}
}

return e.Action == ActionOutput && e.Test == "" && !e.SkipLine()
return e.Action == ActionOutput && e.Test == "" && !e.SkipLine() && !e.IsCached()
}

// Let's try using the Summary method to report the package result.
Expand Down Expand Up @@ -100,6 +100,12 @@ func (e *Event) SkipLine() bool {
return strings.HasPrefix(e.Output, "? \t") && strings.HasSuffix(e.Output, "\t[no test files]\n")
}

// IsCached reports special event case for cached packages:
// ok \tgithub.com/mfridman/tparse/tests\t(cached)\n
func (e *Event) IsCached() bool {
return strings.HasPrefix(e.Output, "ok \t") && strings.HasSuffix(e.Output, "\t(cached)\n")
}

// Action is one of a fixed set of actions describing a single emitted test event.
type Action string

Expand Down
13 changes: 13 additions & 0 deletions parse/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ func (p Packages) Print(skipNoTests bool) {
continue
}

if pkg.Cached {
name += "\n(cached)"
}

tbl.Append([]string{
pkg.Summary.Action.WithColor(),
strconv.FormatFloat(pkg.Summary.Elapsed, 'f', 2, 64) + "s",
Expand All @@ -75,6 +79,9 @@ type Package struct {
// NoTest indicates whether the package contains tests:
// "? \tpackage\t[no test files]\n"
NoTest bool

// Cached indicates whether the test result was obtained from the cache.
Cached bool
}

// AddTestEvent adds the event to a test based on test name.
Expand Down Expand Up @@ -123,6 +130,12 @@ func Start(r io.Reader) (Packages, error) {
pkg.NoTest = true
}

// We don't need this line, simply record the package as cached and move on.
if e.IsCached() {
pkg.Cached = true
continue
}

if e.Summary() {
pkg.Summary = e
continue
Expand Down

0 comments on commit 48d8fea

Please sign in to comment.